OUTFIL Splitting Records
The OUTFIL statement can be used to split an input dataset into multiple output datasets based on coded criteria, such as splitting by the number of records or conditions. The SPLIT keyword is used to split the file.
If SPLIT is used and there are two OUTFIL datasets, the SORT will distribute the first record to OUTFIL file1, the second record to OUTFIL file2, the third to OUTFIL file1, and so on until the end of the records.
If SPLIT=n is used and two OUTFIL files are, then n records will be distributed from the first OUTFIL file, the next n records to OUTFIL file2, the next n records to OUTFIL file1, and so on until the end of the records.
Syntax -
//SYSIN DD *
OPTION COPY
OUTFIL FNAMES=(DDname-1,DDname-2,…,DDname-n),SPLIT=n
/*
DDname-1,DDname-2,..,DDname-n | Specifies the DDnames of the output files. |
SPLIT=n | Splits the input dataset into multiple output datasets, each containing n records. |
Examples -
Scenario1 - Splitting by Number of Records.
//SYSIN DD *
SORT FIELDS=COPY
OUTFIL FNAMES=OUT1,SPLIT=500
OUTFIL FNAMES=OUT2,SPLIT=500
/*
Writes the first 500 records to OUT1 file and writes the next 500 records to OUT2 file.
Scenario2 - Splitting by Groups of Records.
//SYSIN DD *
SORT FIELDS=COPY
OUTFIL FNAMES=OUT1,SPLITBY=500
OUTFIL FNAMES=OUT2
/*
Splits the file by writing the first 500 records to OUT1 file and the remaining records to OUT2 file.
Scenario3 - Splitting the Records by 500 each.
//SYSIN DD *
SORT FIELDS=COPY
OUTFIL FNAMES=(OUT1,OUT2),SPLITBY=500
/*
Splits the file by writing the first 500 records to OUT1 file, the next 500 records to OUT2 file, next 500 records to OUT1 file and so on until the end of the file.