GIVING Phrase

file-name-4, ...
Specifies input files.
When the GIVING phrase is specified, all the merged records in file-name-1 are automatically transferred to the output file (file-name-4). At the start of execution of the MERGE statement, the file referenced by file-name-4 must not be open. For each of the files referenced by file-name-4, the execution of the MERGE statement causes the following actions to be taken:
  1. The processing of the file is initiated. The initiation is performed as if an OPEN statement with the OUTPUT phrase had been executed.
  2. The merged logical records are returned and written onto the file. Each record is written as if a WRITE statement without any optional phrases had been executed. The records overwrite the previous contents, if any, of the file.
    IBM Extension

    If file-name-1 is a logical database file, the records are added to the end of the file.

    End of IBM Extension

    If the file referenced by file-name-4 is an INDEXED file then the associated key data-name for that file must have an ASCENDING KEY phrase in the merge statement. This same data-name must occupy the identical character positions in its record as the data item associated with the prime record key for the file.

    For a relative file, the relative key data item for the first record returned contains the value '1'; for the second record returned, the value '2', and so on. After execution of the MERGE statement, the content of the relative key data item indicates the last record returned to the file.

  3. The processing of the file is terminated, as if a CLOSE statement without optional phrases had been executed.
Note: When duplicate keys are found when writing to an indexed file, the MERGE will terminate and the merged data in all GIVING files will be incomplete.

These implicit functions are performed such that any associated USE AFTER EXCEPTION/ERROR procedures are executed; however, the execution of such a USE procedure must not cause the execution of any statement manipulating the file referenced by, or accessing the record area associated with, file-name-4. On the first attempt to write beyond the externally defined boundaries of the file, any USE AFTER STANDARD EXCEPTION/ERROR procedure specified for the file is executed. If control is returned from that USE procedure or if no such USE procedure is specified, the processing of the file is terminated.

The output file must be described in an FD entry in the Data Division, and its record description(s) must describe records of the same size as the record described for the merge file. If the elementary items that make up these records are not identical, the output record must have an equal number of character positions as the merge record.

The output file must have a sequential, relative or indexed organization.

The output file should be created without a keyed sequence access path. Otherwise, the MERGE statement cannot override the collating sequence defined in the data description specifications (DDS).

If the output files (file-name-4) contain variable-length records, the size of the records contained in file-name-1 must be no less than the largest record described in the output files. If the output files contain fixed-length records, the size of the records contained in file-name-1 must be no greater than the largest record described for the output files.