msa4004
New User
Joined: 25 Feb 2022 Posts: 6 Location: Malaysia
|
|
|
|
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 |
|
Willy Jensen
Active Member
Joined: 01 Sep 2015 Posts: 734 Location: Denmark
|
|
|
|
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. |
|