REXX code used in SORT parm of JCL

797 views Asked by At

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.

1

There are 1 answers

1
NealB On

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')