ILE COBOL Language Reference


MERGE Statement

The MERGE statement combines two or more identically sequenced files (that is, files that have already been sorted according to an identical set of ascending/descending keys) on one or more keys and makes records available in merged order to an output procedure or output file.

A MERGE statement may appear anywhere in the Procedure Division except in a Declarative Section. The maximum number of USING or GIVING files is 32.

+-------------------------------IBM Extension--------------------------------+

It is not necessary to sequence input files prior to a merge operation.

+----------------------------End of IBM Extension----------------------------+

MERGE Statement -- Format
 
>>-MERGE--file-name-1------------------------------------------->
 
   .--------------------------------------------------.
   |                                  .-------------. |
   V                                  V             | |
>----+----+--+-ASCENDING--+--+-----+----data-name-1-+-+--------->
     '-ON-'  '-DESCENDING-'  '-KEY-'
 
>--+------------------------------------------------+----------->
   '-+-----------+--SEQUENCE--+----+--alphabet-name-'
     '-COLLATING-'            '-IS-'
 
                       .-------------.
                       V             |
>--USING--file-name-2----file-name-3-+-------------------------->
 
>--+-| OUTPUT PROCEDURE Phrase |-+-----------------------------><
   |         .-------------.     |
   |         V             |     |
   '-GIVING----file-name-4-+-----'
 
OUTPUT PROCEDURE Phrase:
 
|--OUTPUT PROCEDURE--+----+--procedure-name-1------------------->
                     '-IS-'
 
>--+-------------------------------+----------------------------|
   '-+-THROUGH-+--procedure-name-2-'
     '-THRU----'
 
 
file-name-1
The name given in the SD entry that describes the record.

No file-name may be repeated in the MERGE statement.

Do not specify a pair of file names in the MERGE statement that already share storage through a SAME AREA, SAME SORT AREA, or SAME SORT-MERGE AREA clause. However, you may specify file names in the MERGE statement that share the SAME RECORD AREA clause if they are also associated with the GIVING clause (file-name-4).

When the MERGE statement is executed, all records contained in file-name-2, file-name-3,... are accepted by the merge program and then merged according to the key(s) specified.

Null-capable fields are supported,

but null values are only supported for DATABASE files that have ALWNULL specified on their ASSIGN clause.

Related Information:


[ Top of Page | Previous Page | Next Page | Table of Contents | Index ]