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: 6
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: 734
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: 2143
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: 6
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 IEW2315E 1369 Link error All Other Mainframe Topics 3
No new posts Run rexx with JCL Job CLIST & REXX 1
No new posts Run rexx in batch job CLIST & REXX 7
No new posts Does anyone know rexx for VSE CLIST & REXX 3
No new posts TSO ALLOC In REXX Needs Improvement JCL & VSAM 3
Search our Forums:

Back to Top