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

Module 8: JCL Sort & Merge


OUTREC OVERLAY

It is used to reformat each record by specifying just the items that overlay specific columns.

Overlay lets you change specific existing columns without affecting the entire record.

As compared with FIELD or BUILD statement, in OVERLAY we don’t have to specify information regarding the fields which has to be copied as it is, in OVERLAY we just have to specify information and specification for those field which need to be changed or to be overwritten.

Example 1:-

Input file:-

----+----1----+----2----+----3 JOHN MON 08000 AKSHAY TUE 10000 SMITH WED 25000 JOHN THU 28000 STEVE MON 20000 VIJAY XXX 24000 VIJAY SUN 30000

Requirement: Need to copy all records from input file to output file, however while writing output records, field at position 11 to 20 needs to be converted to lower case letters

JCL Code - Solution:-

//SORTSTEP EXEC PGM=SORT //SORTIN DD DSN=DEPT.EMPL.DATA.OUTPUT1,DISP=SHR //SORTOUT DD DSN=DEPT.EMPL.DATA.OUTPUT2, // DISP=(,CATLG,DELETE), // DCB=(RECFM=FB,LRECL=30,BLKSIZE=0), // UNIT=TEST,SPACE=(CYL,(50,10),RLSE) //SYSOUT DD SYSOUT=* //SYSPRINT DD SYSOUT=* //SYSIN DD * SORT FIELDS=COPY OUTREC OVERLAY=(11:11,10,TRAN=UTOL) /*

Output file:

----+----1----+----2----+----3 JOHN mon 08000 AKSHAY tue 10000 SMITH wed 25000 JOHN thu 28000 STEVE mon 20000 VIJAY xxx 24000 VIJAY sun 30000

Explanation:

  • Statement ‘SORT FIELDS=COPY’ is used here to indicate that all records will be copied from input file to output file.
  • Statement ‘OUTREC OVERLAY=(11:11,10,TRAN=UTOL), is used here to specify that the field at position (11-20 i.e. length=10) of input file should be converted to lowercase and then it should be written to 11th position of output file.

IMP Note: In above example, while coding OUTREC OVERLAY statement we do not have to worry about field at positions (1-10 and 21-30) as they will be copied and written as it is. If we have used OUTREC FIELDS statement then it would have look like OUTREC FIELDS=( 1,10,11:11,10,TRAN=UTOL,21,10).

Example 2:-

Input file:-

----+----1----+----2----+----3 JOHN MON 08000 AKSHAY TUE 10000 SMITH WED 25000 JOHN THU 28000 STEVE MON 20000 VIJAY XXX 24000 VIJAY SUN 30000

Requirement: Need to calculate yearly salary from field at position (26-30 i.e. length=5) of input file and should be written at 41th position of output file

JCL Code Soution:

//SORTSTEP EXEC PGM=SORT //SORTIN DD DSN=DEPT.EMPL.DATA.OUTPUT1,DISP=SHR //SORTOUT DD DSN=DEPT.EMPL.DATA.OUTPUT2, // 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 OUTREC FIELDS=(1,30,41:26,5,ZD,MUL,+12,TO=FS,LENGTH=10) /*

Output file:

----+----1----+----2----+----3----+----4----+----5 JOHN MON 08000 +96000 AKSHAY TUE 10000 +120000 SMITH WED 25000 +300000 JOHN THU 28000 +336000 STEVE MON 20000 +240000 VIJAY XXX 24000 +288000 VIJAY SUN 30000 +360000

Explanation:

  • Statement 'SORT FIELDS=COPY' is used here to indicate that all records will be copied from input file to output file.
  • Statement 'OUTREC FIELDS=(1,30,41:26,5,ZD,MUL,+12,TO=FS,LENGTH=10) ', is used here to specify that the field at position (1-30 i.e. length=30) of input file will be written as it is followed by the value at position (26-30 i.e. length=5 ) of input file will be multiplied by 12 and resultant value will be converted to FS value with length 10. The resultant value will be written to 41 position in output file






© copyright mainframebug.com
Privacy Policy