Let's understand Mainframe
Home Tutorials Interview Q&A Quiz Mainframe Memes Contact us About us

Module 8: JCL Sort & Merge


OUTFIL statement

OUTFIL statement is used to create multiple output files based on condition specified. It will be easier to understand it with help of example

Note: - Maximum 32 files can be created

Example 1:-

Input file:-

----+----1----+----2----+----3----+----4----+----5 88888JOHN PURCHASING 08000 11111AKSHAY HR 10000 55555SMITH R&D 25000 99999JOHN ADMIN 28000 44444STEVE ADMIN 20000 33333VIJAY FINANCE DEPT 24000 77777VIJAY FINANCE DEPT 30000 44444STEVE HR 20000

Requirement: Split input file into three files based on the condition specified. Condition is three separate file should be created for employee having name John, Steve, Vijay

JCL Code:

//SORTSTEP EXEC PGM=SORT //SORTIN DD DSN=DEPT.EMPL.DATA.INPUT,DISP=SHR //SORTOF01 DD DSN=DEPT.EMPL.DATA.JOHN, // DISP=(,CATLG,DELETE), // DCB=(RECFM=FB,LRECL=50,BLKSIZE=0), // UNIT=TEST,SPACE=(CYL,(50,10),RLSE) //SORTOF02 DD DSN=DEPT.EMPL.DATA.STEVE, // DISP=(,CATLG,DELETE), // DCB=(RECFM=FB,LRECL=50,BLKSIZE=0), // UNIT=TEST,SPACE=(CYL,(50,10),RLSE) //SORTOF03 DD DSN=DEPT.EMPL.DATA.VIJAY, // DISP=(,CATLG,DELETE), // DCB=(RECFM=FB,LRECL=50,BLKSIZE=0), // UNIT=TEST,SPACE=(CYL,(50,10),RLSE) //SYSOUT DD SYSOUT=* //SYSPRINT DD SYSOUT=* //SYSIN DD * SORT FIELDS=COPY OUTFIL FILES=01,INCLUDE=(6,5,CH,EQ,C'JOHN ') OUTFIL FILES=02,INCLUDE=(6,5,CH,EQ,C'STEVE') OUTFIL FILES=03,INCLUDE=(6,5,CH,EQ,C'VIJAY') /*

Output file SORTOF01:-

----+----1----+----2----+----3----+----4----+----5 88888JOHN PURCHASING 08000 99999JOHN ADMIN 28000

Output file SORTOF02:-

----+----1----+----2----+----3----+----4----+----5 44444STEVE ADMIN 20000 44444STEVE HR 20000

Output file SORTOF03:-

----+----1----+----2----+----3----+----4----+----5 33333VIJAY FINANCE DEPT 24000 77777VIJAY FINANCE DEPT 30000

Explanation:

  • SORT FIELDS=COPY, is used to specify that all records will be copied without any sort
  • OUTFIL FILES=01,INCLUDE=(6,5,CH,EQ,C'JOHN ') is used here to specify that if field in file at position 6-10 (length 5) is having ‘JOHN ‘ then it will be copied to DSN specified as SORTOF01 as FILES=01 refers to that DSN. Similar condition is specified for STEVE and VIJAY which will be copied to SORTOF02 and SORTOF03 respectively

Example 2:-

Input file:-

----+----1----+----2----+----3----+----4----+----5 88888JOHN PURCHASING 08000 11111AKSHAY HR 10000 55555SMITH R&D 25000 99999JOHN ADMIN 28000 44444STEVE ADMIN 20000 33333VIJAY FINANCE DEPT 24000 77777VIJAY FINANCE DEPT 30000 44444STEVE HR 20000 22222LOKESH ADMIN 20000 12345JIMROBY HR 30000

Requirement: Input file contains 10 records, we need to split this file into 3 files, first 3 records should be moved to DSN SORTOF01, 4th to 8th records should be moved to DSN SORTOF02 and remaining records should go to DSN SORTOF03

SYSIN Control card:

//SORTSTEP EXEC PGM=SORT //SORTIN DD DSN=DEPT.EMPL.DATA.INPUT,DISP=SHR //SORTOF01 DD DSN=DEPT.EMPL.DATA.JOHN, // DISP=(,CATLG,DELETE), // DCB=(RECFM=FB,LRECL=50,BLKSIZE=0), // UNIT=TEST,SPACE=(CYL,(50,10),RLSE) //SORTOF02 DD DSN=DEPT.EMPL.DATA.STEVE, // DISP=(,CATLG,DELETE), // DCB=(RECFM=FB,LRECL=50,BLKSIZE=0), // UNIT=TEST,SPACE=(CYL,(50,10),RLSE) //SORTOF03 DD DSN=DEPT.EMPL.DATA.VIJAY, // DISP=(,CATLG,DELETE), // DCB=(RECFM=FB,LRECL=50,BLKSIZE=0), // UNIT=TEST,SPACE=(CYL,(50,10),RLSE) //SYSOUT DD SYSOUT=* //SYSPRINT DD SYSOUT=* //SYSIN DD * SORT FIELDS=COPY OUTFIL FILES=01,ENDREC=3 OUTFIL FILES=02,STARTREC=4,ENDREC=8 OUTFIL FILES=03,STARTREC=9 /*

Output file SORTOF01:-

88888JOHN PURCHASING 08000 11111AKSHAY HR 10000 55555SMITH R&D 25000

Output file SORTOF02:-

99999JOHN ADMIN 28000 44444STEVE ADMIN 20000 33333VIJAY FINANCE DEPT 24000 77777VIJAY FINANCE DEPT 30000 44444STEVE HR 20000

Output file SORTOF03:-

22222LOKESH ADMIN 20000 12345JIMROBY HR 30000



Advertisements






© copyright mainframebug.com
Privacy Policy