Thursday 20 August 2015

Splitting files using SORT utility

Using SORT, we can split a file into multiple files based on

1. Record Count
2. Conditions.

Splitting file into multiple files based on record count:

Suppose, i have a file with 100 records and i need to split this file into 3 files where first file should have 30 records, second and third one should have 35 each.

Here is how to do it.

//A171501C JOB (Accounting-Information),CLASS=T, 
//              MSGCLASS=H,NOTIFY=&SYSUID                    
//*THIS JCL SPLITS FILE BY NUMBER OF RECORDS                    
//STEP01   EXEC PGM=SORT                                        
//SORTIN   DD DSN=input-file-name,DISP=SHR                        
//SYSIN    DD *                                                 
  SORT FIELDS=COPY                                              
  OUTFIL FILES=01,ENDREC=30                                    
  OUTFIL FILES=02,STARTREC=31,ENDREC=65                       
  OUTFIL FILES=03,STARTREC=66,ENDREC=100                      
/*                                                              
//SORTOF01 DD DSN=output-file1,DISP=(NEW,CATLG,DELETE),
//            LRECL=57,DSORG=PS,RECFM=FB,AVGREC=K               
//SORTOF02 DD DSN=Output-file2,DISP=(NEW,CATLG,DELETE),
//            LRECL=57,DSORG=PS,RECFM=FB,AVGREC=K               
//SORTOF03 DD DSN=Output-file3,DISP=(NEW,CATLG,DELETE),
//            LRECL=57,DSORG=PS,RECFM=FB,AVGREC=K               
//SYSOUT   DD SYSOUT=*                           
//*     

                                         

No comments:

Post a Comment