TSO-ISPF JCL COBOL VSAM DB2 CICS Tools Articles Job Portal Forum Quiz Interview Q&A

COBOL - Merge Statement


Merge performs the following operations,

  1. Opens the work-file in I-O mode, input-files in the INPUT mode and output-file in the OUTPUT mode.

  2. Transfers the records present in the input-files to the work-file.

  3. Sorts the SORT-FILE in ascending/descending sequence by rec-key.

  4. Transfers the sorted records from the work-file to the output-file.

  5. Closes the input-file and the output-file and deletes the work-file.
Syntax:

Following is the syntax to merge two or more files

MERGE work-file ON ASCENDING KEY rec-key1
   [ON DESCENDING KEY rec-key2]
USING input-1, input-2 GIVING output-file.

Three files are required in the sort process,

Input file - Input-1, Input-2 is the files which we have to sort either in ascending or descending order.

Work file is used to hold records while the sort process is in progress. Input file records from both input files are transferred to the work file for the sorting process. This file should be defined in the File-Section under SD entry.

Output file is the file which we get after the sorting process. It is the final output of the Sort verb.


If you have any doubts or queries related to this chapter, get them clarified from our Mainframe experts on ibmmainframer Community!

Are you looking for Job Change? Job Portal