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

Module 8: JCL Sort & Merge


MERGE FIELDS

It is used to combine one or more sorted input files into a single, ordered, sequential file.

Syntax of MERGE command:

MERGE FIELDS= (sort-key1, sort-key2,…., sort-keyN)

Where, each sort-key consist of below four paramaters:-

Important note: MERGE command will fail if any of the input file is not sorted for the condition you specify on MERGE FILEDS control statement
For example, if you are going to merge files using controls card “MERGE FIELDS=(1,5,CH,A)”, then all input files must be in ascending order for column 1 to 5. If input files are not already in sorted based on these conditions, job will fail.

Example:-

Requirement:-Need to MERGE two sorted files into one sorted file in ascending order of column 1 to 5

Input file SORTIN01 :-

----+----1----+----2----+----3----+----4----+----5 11111AKSHAY HR 10000 33333VIJAY FINANCE DEPT 24000 44444STEVE HR 20000

Input file SORTIN02 :-

----+----1----+----2----+----3----+----4----+----5 77777VIJAY FINANCE DEPT 30000 88888JOHN PURCHASING 08000

JCL CODE:-

//SORTSTEP EXEC PGM=SORT //SORTIN01 DD DSN=DEPT.EMPL.DATA.INPUT1,DISP=SHR //SORTIN02 DD DSN=DEPT.EMPL.DATA.INPUT2,DISP=SHR //SORTOUT DD DSN=DEPT.EMPL.DATA.OUTPUT, // 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 * MERGE FIELDS=(1,5,CH,A) /*

Output file SORTOUT:-

----+----1----+----2----+----3----+----4----+----5 11111AKSHAY HR 10000 33333VIJAY FINANCE DEPT 24000 44444STEVE HR 20000 77777VIJAY FINANCE DEPT 30000 88888JOHN PURCHASING 08000






© copyright mainframebug.com
Privacy Policy