Merges multiple input files (MERGE Operator)


Merges one or more input files, processes them, and splits them into one or more output files. It allows upto 10 input files. It merges the indd files to the outdd files using the DFSORT control statements in xxxxCNTL.

DFSORT MERGE statement should supply in xxxxCNTL to indicate the control fields for the MERGE. The records in each input file should already be sorted as specified by the control field in the DFSORT MERGE statement.

Syntax -

Merging three input files to output file -

//TOOLIN DD *
  MERGE FROM(INDD01,INDD02,INDD03) TO(OUTPUT) USING(MERG)
/*
//MERGCNTL DD *
  MERGE FIELDS=(starting-position,length,type,ascending/descending)
/*

Merging three input files to two output files -

//TOOLIN DD *
  MERGE FROM(INDD01,INDD02,INDD03) USING(MERG)
/*
//MERGCNTL DD *
  MERGE FIELDS=(starting-position,length,type,ascending/descending)
  OUTFIL FNAMES=OUTDD01,INCLUDE=(starting-position,length,type,EQ,matching-value)
  OUTFIL FNAMES=OUTDD02,SAVE
/*

Required Operands


  • FROM - specifies ddname of the input file. It is mandatory when FROM operand is coded.
  • USING - specifies the first 4-characters of the ddname (xxxxCNTL) for the DFSORT control statement. XXXX name is the user-defined name. Either TO, USING, or both operands can code at the same time.

Optional Operands


  • TO - specifies 1 to 10 ddnames of output files. TO and USING operands can code at the same time.
  • VSAMTYPE - specifies the record format for a VSAM input file. It should be either F (fixed-length) or V (variable-length) record processing.

Example -


Scenario - Merges the employee details and separates employee details based on the country code "IN", "US".

INPUT1 - MATEPK.INPUT.PSFILE

----+----1----+----2----+----3----+----4----+----5----+----6----+----7----+----8
001  PAWAN         MAINFRAME           JPM       AP        IN
002  SRINIVAS      TESTING             ORACLE    TG        IN
003  SRIDHAR       SAS                 CG        OR        US
004  VENKATESH     ABAP                CSC       CA        US
005  RAVI          HADOOP              CTS       FL        US
006  PRASAD        HR                  INFOSYS   MI        US
007  RAJA          TESTING             IBM       CA        US

INPUT2 - MATEPK.INPUT.PSFILE4

----+----1----+----2----+----3----+----4----+----5----+----6----+----7----+----8
008  KUMAR         SAP BASIS           TCS       TN        IN
009  RAMESH        SAP SD              ORACLE    MN        US
010  RAVINDER      SAP ABAP            INFOTECH  AK        US

JCL -

----+----1----+----2----+----3----+----4----+----5----+
...
//STEP01   EXEC PGM=ICETOOL
//INDD01   DD DSN=MATEPK.INPUT.PSFILE,DISP=SHR
//INDD02   DD DSN=MATEPK.INPUT.PSFILE4,DISP=SHR 
//OUTDD1   DD DSN=MATEPK.OUTPUT.PSFILE3, 
//            DISP=(NEW,CATLG,DELETE),VOLUME=SER=DEVHD4,
//            SPACE=(TRK,(1,1),RLSE),UNIT=SYSDA,
//            DCB=(DSORG=PS,RECFM=FB,LRECL=80,BLKSIZE=800)
//OUTDD2   DD DSN=MATEPK.OUTPUT.PSFILE4,
//            DISP=(NEW,CATLG,DELETE),VOLUME=SER=DEVHD4,
//            SPACE=(TRK,(1,1),RLSE),UNIT=SYSDA,
//            DCB=(DSORG=PS,RECFM=FB,LRECL=80,BLKSIZE=800)
//TOOLIN   DD *
  MERGE FROM(INDD01,INDD02) USING(CTL1)
/*
//CTL1CNTL DD *
  MERGE FIELDS=(1,3,ZD,A)
  OUTFIL FNAMES=OUTDD1,INCLUDE(60,2,CH,EQ,C'IN')
  OUTFIL FNAMES=OUTDD2,INCLUDE(60,2,CH,EQ,C'US')
/*
...

OUTPUT1 - MATEPK.OUTPUT.PSFILE3

----+----1----+----2----+----3----+----4----+----5----+----6----+----7----+----8
001  PAWAN         MAINFRAME           JPM       AP        IN
002  SRINIVAS      TESTING             ORACLE    TG        IN
008  KUMAR         SAP BASIS           TCS       TN        IN

OUTPUT2 - MATEPK.OUTPUT.PSFILE4

----+----1----+----2----+----3----+----4----+----5----+----6----+----7----+----8
003  SRIDHAR       SAS                 CG        OR        US
004  VENKATESH     ABAP                CSC       CA        US
005  RAVI          HADOOP              CTS       FL        US
006  PRASAD        HR                  INFOSYS   MI        US
007  RAJA          TESTING             IBM       CA        US
009  RAMESH        SAP SD              ORACLE    MN        US
010  RAVINDER      SAP ABAP            INFOTECH  AK        US