IBM Mainframe Forum Index
 
Log In
 
IBM Mainframe Forum Index Mainframe: Search IBM Mainframe Forum: FAQ Register
 

Rexx Logic error while adding seperator at end of record


IBM Mainframe Forums -> CLIST & REXX
Post new topic   Reply to topic
View previous topic :: View next topic  
Author Message
msa4004

New User


Joined: 25 Feb 2022
Posts: 4
Location: Malaysia

PostPosted: Mon Feb 28, 2022 6:58 pm
Reply with quote

Hi Rexx Gurus,

I am really a beginner on ReXx coding.First background of what I am doing , I am creating a Rexx to out read DSN sysin and output as SQL statements. My code is almost done. However I am having some logic bug/issue. I want to add a separator at end of final record as per code below. When code read final record it will change LAST_SEP= ',' to LAST_SEP=')'

Code:

CONN = SUBSTR(CUSTMR,4,3)               
DBNAME = DWR||CONN||E                   
                                       
SQLREC.1       =" SELECT * "           
SQLREC.2       =" FROM "DBNAME".TEST"
SQLREC.3       =" WHERE CONN="CONN     
SQLREC.4       =" AND SSNN IN ( "       
/* READ SYSIN FOR SSNN */                                           
"EXECIO * DISKR SYSIN(FINIS STEM XACT."                             
LINE_CNT = 5                                                       
LAST_SEP = ','                                                     
DO REC_CNT = 1 TO XACT.0                                           
   OLD_SSNN.REC_CNT = SUBSTR(XACT.REC_CNT,6,9)                     
   NEW_SSNN.REC_CNT = SUBSTR(XACT.REC_CNT,45,9)                     
   SQLREC.LINE_CNT= " " OLD_SSNN.REC_CNT","NEW_SSNN.REC_CNT LAST_SEP
   LINE_CNT = LINE_CNT + 1                                         
   IF REC_CNT = XACT.0 THEN                                         
      LAST_SEP = ')'                                                 
   END                                                                                             
SQLREC.0=LINE_CNT                                                   
                                                                   
"EXECIO * DISKW SQLOUT ( FINIS STEM SQLREC."                       


however it seem code below that I added not working

Code:

IF REC_CNT = XACT.0 THEN                                         
      LAST_SEP = ')'                                               
END   


My program incorrect output
Code:

<--- SQL GENERATED --->
 SELECT *             
 FROM DWR157E.TEST 
 WHERE CONN=157       
 AND SSNN IN (         
  111111111,222222222 ,
  333333333,444444444 ,
  555555555,666666666 ,   
READY                 


I would like it to be like below if possible

Code:

<--- SQL GENERATED --->
 SELECT *             
 FROM DWR157E.TEST 
 WHERE CONN=157       
 AND SSNN IN (         
  111111111,222222222 ,
  333333333,444444444 ,
  555555555,666666666 )  <-   into  ')'
 


Can someone kindly point me the way to achieve this using my current code or probably point out where my faulty logic is for me to fix. Thanks
Back to top
View user's profile Send private message
Willy Jensen

Active Member


Joined: 01 Sep 2015
Posts: 712
Location: Denmark

PostPosted: Mon Feb 28, 2022 7:10 pm
Reply with quote

I think I would drop the
IF REC_CNT = XACT.0 THEN
LAST_SEP = ')'
and do something like the following after the END:
rec=strip(strip(rec,'t'),'t',';')')'

The inner strip is to make sure that there are no trailing blanks.
Back to top
View user's profile Send private message
sergeyken

Senior Member


Joined: 29 Apr 2008
Posts: 2022
Location: USA

PostPosted: Mon Feb 28, 2022 7:15 pm
Reply with quote

You need to place this code
Code:
IF REC_CNT = XACT.0 THEN                                         
      LAST_SEP = ')' 

before this statement
Code:
   SQLREC.LINE_CNT= " " OLD_SSNN.REC_CNT","NEW_SSNN.REC_CNT LAST_SEP


Besides of this the following doesn't make any sense
Code:
SQLREC.0=LINE_CNT                                                   
                                                                   
"EXECIO * DISKW SQLOUT ( FINIS STEM SQLREC." 

Needs to be changed to
Code:
"EXECIO" LINE_CNT "DISKW SQLOUT ( FINIS STEM SQLREC." 

because DISKW (unlike DISKR) ignores the value of SQLREC.0
Back to top
View user's profile Send private message
msa4004

New User


Joined: 25 Feb 2022
Posts: 4
Location: Malaysia

PostPosted: Wed Mar 02, 2022 7:56 am
Reply with quote

Thank you all for response
Back to top
View user's profile Send private message
View previous topic :: :: View next topic  
Post new topic   Reply to topic View Bookmarks
All times are GMT + 6 Hours
Forum Index -> CLIST & REXX

 


Similar Topics
Topic Forum Replies
No new posts Compile Several JCL JOB Through one r... CLIST & REXX 4
No new posts How to split large record length file... DFSORT/ICETOOL 10
No new posts Running REXX through JOB CLIST & REXX 13
No new posts Error to read log with rexx CLIST & REXX 11
No new posts Error when install DB2 DB2 2
Search our Forums:

Back to Top