OUTFIL control statements allow you to create one or more output data sets for a sort, copy, or merge application from a single pass over one or more input data sets. You can use multiple OUTFIL statements, with each statement specifying the OUTFIL processing to be performed for one or more output data sets. OUTFIL processing begins after all other processing ends (that is, after processing for exits, options, and other control statements).
OUTFILE can be used as an alias for OUTFIL.
OUTFIL Files statements can be used for data set tasks:
Creation of multiple output data sets.
Conversion of variable-length record data sets to fixed-length record data sets.
Conversion of fixed-length record data sets to variable-length record data sets.
Splitting of data records in rotation among a set of output data sets.
Updating counts and totals in an existing trailer (last) record based on the current data records.
Repetition and sampling of data records.
A wide variety of parsing, editing, and reformatting tasks.
and many more...Let's see an example for OUTFIL FILES sort statemens,
INPUT FILE:
1234567890123456789012345678901234567890 ---> Column KALAIA 12345678901234567 RASAN SRINIV 19876543210987654 ASAN KALAIA 02345678901234567 RASAN REVATH 11111111111111111 ISAMBATH SRINIV 09876543210987654 ASAN SANKAR 22222222222222222 ICHELLA GUNASE 33333333333333333 ELAN |
SORT JCL:
//STEP01 EXEC PGM=SORT //SYSOUT DD SYSOUT=* //SORTIN DD DSN=userid.SORT.INPUT.FILE,DISP=SHR ---> Input file //SORTOF01 DD DSN=dataset1, ---> Output file1 // DISP=(NEW,CATLG,DELETE),UNIT=SYSDA, // SPACE=(CYL,(1,4),RLSE), // DCB=(RECFM=FB,LRECL=80,BLKSIZE=0) //SORTOF02 DD DSN=dataset2, ---> Output file2 // DISP=(NEW,CATLG,DELETE),UNIT=SYSDA, // SPACE=(CYL,(1,4),RLSE), // DCB=(RECFM=FB,LRECL=80,BLKSIZE=0) //SORTOF03 DD DSN=dataset3, ---> Output file3 // DISP=(NEW,CATLG,DELETE),UNIT=SYSDA, // SPACE=(CYL,(1,4),RLSE), // DCB=(RECFM=FB,LRECL=80,BLKSIZE=0) //SYSIN DD * SORT FIELDS=COPY OUTFIL FILES=01,INCLUDE=(1,6,CH,EQ,C'SRINIV') OUTFIL FILES=02,INCLUDE=(1,6,CH,EQ,C'KALAIA') OUTFIL FILES=03,INCLUDE=(1,6,CH,EQ,C'GUNASE') /* |
OUTPUT FILE 1:
SRINIV 19876543210987654 ASAN SRINIV 09876543210987654 ASAN |
OUTPUT FILE 2:
KALAIA 12345678901234567 RASAN KALAIA 02345678901234567 RASAN |
OUTPUT FILE 2:
GUNASE 33333333333333333 ELAN |
Explanation:
SORT FIELDS=COPY - indicate , it for copy of records, not for sort, we can also mention "OPTION COPY" instead of "SORT FIELDS=COPY".OUTFIL FILES=01,INCLUDE=(1,6,CH,EQ,C'SRINIV') OUTFIL FILES=02,INCLUDE=(1,6,CH,EQ,C'KALAIA') OUTFIL FILES=03,INCLUDE=(1,6,CH,EQ,C'GUNASE') |
the above sort statements will take data from 1st positioon to 6th position of input file and it will compare that data with 'SRINIV' or 'KALAIA' or 'GUNASE'
If data equals to 'SRINIV' then that record will copies to dataset defined in SORTOF01 step. ( because we defined FILES=01)
If data equals to 'KALAIA' then that record will pass to dataset defined in SORTOF02 step. ( because we defined FILES=02)
If data equals to 'GUNASE' then that recorrd will copied to dataset defined in SORTOF03 step. ( because we defined FILES=03)
Example 2: SORT JCL TO SPLIT DATA USING OUTFILE
We are going to split a file contaning 700 records into 3 files where 1st file has 200, 2nd has 200 and 3rd has 300.
This also can be achived by using JCL sort OUTFIL FILES WITH STARTREC & ENDREC OPTION.
SORT JCL:
//STEP01 EXEC PGM=SORT //SYSOUT DD SYSOUT=* //SYSPRINT DD SYSOUT=* //SYSUDUMP DD SYSOUT=* //SORTIN DD DSN=userid.SORT.INPUT.FILE,DISP=SHR ---> Input file //OUTPUT1 DD DSN=OUTPUTFILE1......., // DISP=(NEW,CATLG,DELETE),UNIT=SYSDA, // SPACE=(CYL,(1,1),RLSE), // RECFM=FB,LRECL=20 //OUTPUT2 DD DSN=OUTPUTFILE2.............., // DISP=(NEW,CATLG,DELETE),UNIT=SYSDA, // SPACE=(CYL,(1,1),RLSE), // RECFM=FB,LRECL=20 //OUTPUT3 DD DSN=OUTPUTFILE3.............., // DISP=(NEW,CATLG,DELETE),UNIT=SYSDA, // SPACE=(CYL,(1,1),RLSE), // RECFM=FB,LRECL=20 //SYSIN DD * SORT FIELDS=COPY OUTFIL FNAMES=OUTPUT1,ENDREC=200 OUTFIL FNAMES=OUTPUT2,STARTREC=201,ENDREC=400 OUTFIL FNAMES=OUTPUT3,STARTREC=401,ENDREC=700 /* |
Explanation:
Name | Description |
---|---|
FNAMES=ddname | ddname is eight character’s name that representing the actual dataset in JCL. |
STARTREC=number | Specifies the starting record number from where the copy starts |
ENDREC=number | Specifies the ending record number where the copy ends |
OUTFIL FNAMES=OUTPUT1,ENDREC=200 - Copies 1st record and picked upto 200th record.
OUTFIL FNAMES=OUTPUT2,STARTREC=201,ENDREC=400 - Copy starts from 201 record and picked upto 400th record.
OUTFIL FNAMES=OUTPUT3,STARTREC=401,ENDREC=700 - Copy starts from 401 record and picked upto 700th record.
If you have any doubts or queries related to this chapter, get them clarified from our Mainframe experts on ibmmainframer Community!