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

COBOL - Merge Statement Examples


In the following example, INPUT1 and INPUT2 are the input files which are to be merged in ascending order −

IDENTIFICATION DIVISION.
PROGRAM-ID. CBLMERGE.

ENVIRONMENT DIVISION.
   INPUT-OUTPUT SECTION.
   FILE-CONTROL.
      SELECT INPUT1 ASSIGN TO IN1.
      SELECT INPUT2 ASSIGN TO IN2.
      SELECT OUTPUT ASSIGN TO OUT.
      SELECT WORK ASSIGN TO WRK.

DATA DIVISION.
   FILE SECTION.
   FD INPUT1.
      01 INPUT1-STUDENT.
         05 STUDENT-ID-I1 PIC 9(5).
         05 STUDENT-NAME-I1 PIC A(25).
   FD INPUT2.
      01 INPUT2-STUDENT.
         05 STUDENT-ID-I2 PIC 9(5).
         05 STUDENT-NAME-I2 PIC A(25).
   FD OUTPUT.
      01 OUTPUT-STUDENT.
         05 STUDENT-ID-O PIC 9(5).
         05 STUDENT-NAME-O PIC A(25).
   SD WORK.
      01 WORK-STUDENT.
         05 STUDENT-ID-W PIC 9(5).
         05 STUDENT-NAME-W PIC A(25).

PROCEDURE DIVISION.
   MERGE WORK ON ASCENDING KEY STUDENT-ID-O
   USING INPUT1, INPUT2 GIVING OUTPUT.
   DISPLAY 'Merge Successful'.
STOP RUN.

When you compile and execute the above program, it produces the following result −

Merge Successful

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