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

SORT using REXX


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

New User


Joined: 26 Nov 2013
Posts: 3
Location: USA

PostPosted: Thu Dec 12, 2013 10:20 pm
Reply with quote

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

Code:
/* 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. I know the code to be added is
OUTVAR1=" OMIT FORMAT=CH,COND=(33,16,EQ,C'"||ACCTNBR||"')"
but the IF condition is not working for me. Could anyone suggest any ideas.
Back to top
View user's profile Send private message
Akatsukami

Global Moderator


Joined: 03 Oct 2009
Posts: 1788
Location: Bloomington, IL

PostPosted: Thu Dec 12, 2013 10:51 pm
Reply with quote

Use:
Code:
/* 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                                                     
    if (i¬=zgd.0) then                                             
      OUTVAR1=" OMIT FORMAT=CH,COND=(33,16,EQ,C'"||ACCTNBR||"',OR,"
    else nop                                                       
  ELSE DO                                                         
    if i=zgd.0 then                                               
      if (i=1) then                                               
        outvar1=" OMIT FORMAT=CH,COND=(33,16,EQ,C'"||acctnbr||"')"
      else 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'                                   
Back to top
View user's profile Send private message
spoorni80

New User


Joined: 26 Nov 2013
Posts: 3
Location: USA

PostPosted: Thu Dec 12, 2013 11:18 pm
Reply with quote

I tried doing this. The output created is
SORT FIELDS=COPY
SORT FIELDS=COPY
Back to top
View user's profile Send private message
spoorni80

New User


Joined: 26 Nov 2013
Posts: 3
Location: USA

PostPosted: Fri Dec 13, 2013 1:41 am
Reply with quote

I dont think the initial code would work very well with one record in the input. So, i changed the entire code as follows and it worked well:

Code:
/* REXX */                                                             
'EXECIO * DISKR ZEROGDT (STEM ZGD.'                                     
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                                                       
     OUTVAR1=" OMIT FORMAT=CH,COND=(33,16,EQ,C'"||SUBSTR(ZGD.I,33,16)   
   ELSE                                                                 
     OUTVAR1=COPIES(' ',21)||"33,16,EQ,C'"||SUBSTR(ZGD.I,33,16)         
   IF I=ZGD.0 THEN                                                     
     OUTVAR1=OUTVAR1||"')"                                             
   ELSE                                                                 
     OUTVAR1=OUTVAR1||"',OR,"                                           
   'EXECIO 1 DISKW ACCOUNT (STEM OUTVAR'                               
END                                                                     
'EXECIO 0 DISKW ACCOUNT (FINIS'             


Thanks!
Back to top
View user's profile Send private message
expat

Global Moderator


Joined: 14 Mar 2007
Posts: 8797
Location: Welsh Wales

PostPosted: Fri Dec 13, 2013 1:19 pm
Reply with quote

I usually handle that by setting the end of statement as a variable which changes values at the last record. You can also do the same for the start variable too.
Code:
"EXECIO * DISKR FILEIN (STEM FI. FINIS"                       
                                                             
START   = "  OMIT  COND=("                                   
ENDOF   = "',OR,"                                             
                                                             
MAKEBUF                                                       
QUEUE  " SORT   FIELDS=COPY"                                 
                                                             
DO AA = 1 TO FI.0                                             
  IF AA = FI.0 THEN ENDOF = "')   "                           
  WRK = START||"1,10,CH,EQ,C'"||SUBSTR(FI.AA,11,10)||ENDOF   
  QUEUE WRK                                                   
  IF AA = 1 THEN START = "              "                     
END                                                           
                                                             
"EXECIO "QUEUED()" DISKW FILEOUT ( FINIS"                     
DROPBUF                                                                         
 
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 Need to set RC4 through JCL SORT DFSORT/ICETOOL 5
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
Search our Forums:

Back to Top