3

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?

Manasi
  • 717
  • 8
  • 18
  • 30

4 Answers4

4

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

Deuian
  • 831
  • 1
  • 6
  • 12
  • I tried to run this job. It is spliting the records in 3 files. But in this case 1st rec is written in 1 st file..2nd in 2nd file and so on. Could u pls explain me the significance of SORT FIELDS=(21,5,FS,A) ? I tried to open the link provided by you. But the PDF in that link is not opening ...Could you pls help? – Manasi Mar 04 '11 at 08:58
  • I have added in what the FIELDS statement signifies. What way do you want the records split on? – Deuian Mar 07 '11 at 14:44
  • My input file is already sorted, i just wanted to split that in several files. I used option, SORT FIELDS=COPY, and it is working perfectly fine for me. Thanks a lot for your solution. It saved my time of using SKIPREC and STOPAFTER... :) Thanks a lot :) – Manasi Mar 10 '11 at 07:26
2

SPLIT is just SPLIT, you can't associate it with a number.

SPLITBY=n will "rotate" n records between each OUTFIL dataset specified. SPLIT is the same as SPLITBY=1.

SPLIT1R=n will only carry out one "rotation" (n records will be written to first OUTFIL dataset, then n to second OUTFIL and continuing like that until the final OUTFIL dataset is used, which will contain any remaining records for the input, no matter how many.

OUTFIL FILES=OUT1 is not permissible.It should be OUTFIL FNAMES=(OUT1,OUT2,OUT3),SPLIT.

IF using STATREC/ENDREC or INCLUDE/OMIT, OUTFIL SAVE can be used to establish a file for records that are not written to any of the other OUTFIL datasets.

Community
  • 1
  • 1
Bill Woodger
  • 12,968
  • 4
  • 38
  • 47
1
  • Deuian's SORT CARD splits the input file into output file equally. If we have 3 output files for instance, the total input records divided by 3 will be record count of each input file.
  • Of cos we can specify the count based on which split should happen, as below. Its implicitly splits the input file into output files 10000 records each. Say for eg, we have 40000 records in input file and we are dividing them into 3 output files, then we will be getting 10000+10000/3 records in the output file.

OUTFIL FNAMES=(OUT1,OUT2,OUT3),SPLIT=10000

  • In nutshell, we can make use of it, when we do not have any constraints on output record count. When we have any such criteria while splitting then below piece of code helps...

SORT FIELDS=COPY
OUTFIL FILES=OUT1,ENDREC=10000
OUTFIL FILES=02,STARTREC=10001,ENDREC=20000 OUTFIL FILES=03,STARTREC=20001,ENDREC=30000

  • Lastly, If we have more than 30000 records in input file and we didnt specify what to do for those records, so SORT will not bother about them. Meaning only 10000 records will be held by last output file.

Hope I made you clear. Do get back incase of question further.

Raja Reddy
  • 772
  • 8
  • 19
  • 37
0

Suppose you don't know how many records are in a data set, but you want to divide the records as equally as possible between two output data sets. You can use OUTFIL's SPLIT parameter to put the first record into OUTPUT1, the second record into OUTPUT2, the third record into OUTPUT1, the fourth record into OUTPUT2, and so on until you run out of records. SPLIT splits the records one at a time among the data sets specified by FNAMES. The following statements split the records between two OUTFIL data sets: OPTION COPY OUTFIL FNAMES=(OUTPUT1,OUTPUT2),SPLIT With 17 input records, the results produced for OUTPUT1 are: Record 01 Record 03 Record 05 Record 07 Record 09 Record 11 Record 13 Record 15 Record 17

Similarly, OUTFIL's SPLITBY=n parameter splits the records n at a time among the data sets specified by FNAMES. The following statements split the records four at a time between three OUTFIL data sets: OPTION COPY OUTFIL FNAMES=(OUT1,OUT2,OUT3),SPLITBY=4