Monday, September 26, 2011

SORT - Extract records 1,5,9,13,...

I have got a sequential file in which every set of 4 records forms one unit of data - say, the first line contains student name and Date of birth, second line contains address, third line contains percentage of marks scored in 10 subjects and fourth line contains extra-curricular activities. 
  
  Student Id will be available on all four records, to help in identification. Each and every student WILL have the four records mentioned - you won't have a student with (say) the first three records alone.

  Now I need to extract ONLY the first record for each student. That will be the records 1,5,9,13,17, etc till the end of the file. 


Solution


//STEP010  EXEC PGM=SORT                    
//SYSOUT   DD SYSOUT=*                      
//SYSPRINT DD SYSOUT=*                      
//SORTIN   DD  DSN=USERID.TSTS.INPUT,
//             DISP=SHR                    
//SORTOUT  DD  DSN=USERID.TSTS.OUTPUT,
//             DISP=(NEW,CATLG,DELETE),    
//             SPACE=(CYL,(1,1),RLSE)
//SYSIN    DD *                                
 INREC FIELDS=(SEQNUM,6,ZD,START=25,INCR=25,1,80)
 SORT FIELDS=COPY                              
 OUTFIL FNAMES=SORTOUT,INCLUDE=(5,2,CH,EQ,C'25'),
        OUTREC=(7,80)                          
/*                                               

Or a slightly simpler approach using SPLIT:

//STEP010  EXEC PGM=SORT                    
//SYSOUT   DD SYSOUT=*                      
//SYSPRINT DD SYSOUT=*                      
//SORTIN   DD  DSN=USERID.TSTS.INPUT,
//             DISP=SHR                    
//SORTOF1  DD  DSN=USERID.TSTS.OUTPUT,
//             DISP=(NEW,CATLG,DELETE),    
//             SPACE=(CYL,(1,1),RLSE)
//SORTOF2  DD  DUMMY
//SORTOF3  DD  DUMMY
//SORTOF4  DD  DUMMY
//SYSIN    DD  *                            
 SORT FIELDS=COPY                          
 OUTFIL FILES=(1,2,3,4),SPLIT                  
//*         

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.