The MERGE statement takes two or more identically sequenced files and combines them according to the key values you specify. During the process, it makes records available, in merged order, to routines in OUTPUT PROCEDURE or to an output file. Format - MERGE mergefile { ON { ASCENDING } KEY { mergekey } ... } ... { { DESCENDING } } [ COLLATING SEQUENCE IS alpha ] USING infile { infile } ... { OUTPUT PROCEDURE IS first-proc [ { THRU } end-proc ] } { [ { THROUGH } ] } { GIVING { outfile } ... }
1 – mergefile
is a file-name described in a sort-merge file description (SD) entry in the Data Division.
2 – mergekey
is the data-name of a data item in a record associated with mergefile.
3 – alpha
is an alphabet-name defined in the SPECIAL-NAMES paragraph of the Environment Division.
4 – infile
is the file-name of an input file. It must be described in a file description (FD) entry in the Data Division.
5 – first-proc
is the section-name or paragraph-name of the output procedure's first (or only) section or paragraph.
6 – end-proc
is the section-name or paragraph-name of the output procedure's last section or paragraph.
7 – outfile
is the file-name of an output file. It must be described in a file description (FD) entry in the Data Division.