jcl sort to divide Mainframe Dataset

Manasi picture Manasi · Mar 3, 2011 · Viewed 30.4k times · Source

I am trying to divide MF PS into several datasets. e.g. If I have a Dataset containg 600 recs, I want to divide this into 6 files with 100 records each. Is it possible to do this using JCL sort?

Answer

Deuian picture Deuian · Mar 3, 2011

The below JCL uses DFSORT to split DD SOTRIN evenly across 3 output DATASETS (OUT1,OUT2 and OUT3), to do it across 6 add in 3 more output DD statements and add them in to the FNAMES statement.

//SPLIT EXEC PGM=ICEMAN  
//SYSOUT DD SYSOUT=*  
//SORTIN DD DSN=Y897797.INPUT1,DISP=OLD  
//OUT1 DD DSN=Y897797.SPLIT1,DISP=(NEW,CATLG),  
// SPACE=(CYL,(5,5)),UNIT=SYSDA  
//OUT2 DD DSN=Y897797.SPLIT2,DISP=(NEW,CATLG),  
// SPACE=(CYL,(5,5)),UNIT=SYSDA  
//OUT3 DD DSN=Y897797.SPLIT3,DISP=(NEW,CATLG),  
// SPACE=(CYL,(5,5)),UNIT=SYSDA  
//SYSIN DD *  
SORT FIELDS=(21,5,FS,A)  
OUTFIL FNAMES=(OUT1,OUT2,OUT3),SPLIT  
/*  

SORT FIELDS=(21,5,FS,A) is how you want the sortint dataset sorted, below is what this fields statement means

21 beginning of field to be sorted
5 Length of field to be sorted
FS Floating Sign (Signed Numeric)
A Ascending order

DFSORT Getting Started Manual
Smart DFSORT Tricks has lots of useful examples and a couple of other ways to split the records out of a dataset