0

I have a sort parm in a JCL that is created using some REXX code as follows:

/* REXX */                                                           
'EXECIO * DISKR ZEROGDT (STEM ZGD.'                                  
S21='                     '                                          
OUTVAR1=' SORT FIELDS=COPY'                                          
'EXECIO 1 DISKW ACCOUNT (STEM OUTVAR'                                
DO I=1 TO ZGD.0                                                      
   ACCTNBR=SUBSTR(ZGD.I,33,16)                                       
   IF I=1 THEN DO                                                    
     OUTVAR1=" OMIT FORMAT=CH,COND=(33,16,EQ,C'"||ACCTNBR||"',OR,"   
   END                                                               
   ELSE DO                                                           
      IF I=ZGD.0 THEN OUTVAR1=S21||" 33,16,EQ,C'"||ACCTNBR||"')"     
      ELSE OUTVAR1=S21||" 33,16,EQ,C'"||ACCTNBR||"',OR,"              
   END                                                               
   'EXECIO 1 DISKW ACCOUNT (STEM OUTVAR'                             
END                                                                  
'EXECIO 0 DISKW ACCOUNT (FINIS'                                      

I know that the above REXX code creates a sort parm as follows:

SORT FIELDS=COPY                                     
OMIT FORMAT=CH,COND=(33,16,EQ,C'8257310018808572',OR,
                     33,16,EQ,C'8257310018076428',OR,
                     33,16,EQ,C'8257310017959681',OR,
                     33,16,EQ,C'8257310016504835',OR,
                     33,16,EQ,C'8257310016059467',OR)

But, it is not able to handle a single record in the input file. I am trying to modify the REXX code to handle a single record but have not been able to. Any help is appreciated.

PSA
  • 53
  • 1
  • 3
  • 13
  • What do you mean by "Not able to handle"? – NoChance Dec 09 '13 at 22:13
  • Well, the code itself is clear that if there it is the first record, start the omit cond. If it is not the first record just append to the omit cond and if it is the last record, close the bracket for the omit cond. In case there is a single record, it is supposed to open the bracket for the omit cond and end it too. That condition doesnt seem to be present in this code. And when i try to add it in different ways i get errors. – PSA Dec 09 '13 at 22:39
  • Would this work? OUTVAR1=" OMIT FORMAT=CH,COND=(33,16,EQ,C'"||ACCTNBR||"')" – NoChance Dec 09 '13 at 22:51
  • yes, it should. But unfortunately i cannot get the right condition to work. I have tried a lot of permutations and combinations but havent got it to work. – PSA Dec 09 '13 at 23:12

1 Answers1

0

The code below allows the first line to also be the last, the original code could not account for this because of the way the IF statements nested.

/* REXX */                                                           
'EXECIO * DISKR ZEROGDT (STEM ZGD.'                                  
OUTVAR=' SORT FIELDS=COPY'                                          
'EXECIO 1 DISKW ACCOUNT (STEM OUTVAR'                                
DO I=1 TO ZGD.0                                                      

   IF I = 1 THEN  
      OUTVAR = " OMIT FORMAT=CH,COND=(33,16,EQ,C'" || SUBSTR(ZGD.I,33,16)
   ELSE
      OUTVAR = COPIES(' ', 21) || " 33,16,EQ,C'" || SUBSTR(ZGD.I,33,16)

   IF I = ZGD.0 THEN
      OUTVAR = OUTVAR || ")" /* This is the last line, close paren. */
   ELSE
      OUTVAR = OUTVAR || ",OR," /* Another line to follow, continue */

   'EXECIO 1 DISKW ACCOUNT (STEM OUTVAR'                             
END                                                                  
'EXECIO 0 DISKW ACCOUNT (FINIS'                                      

For a single line of input this should produce:

SORT FIELDS=COPY                                     
OMIT FORMAT=CH,COND=(33,16,EQ,C'8257310018808572')

For multiple lines it should produce:

SORT FIELDS=COPY                                     
OMIT FORMAT=CH,COND=(33,16,EQ,C'8257310018808572',OR,
                     33,16,EQ,C'8257310018076428',OR,
                     33,16,EQ,C'8257310017959681')
NealB
  • 16,670
  • 2
  • 39
  • 60
  • Thank you NealB! This worked well for me and was easily understandable when compared to the initial code I had! – PSA Dec 12 '13 at 19:37