Sample MERGE program using COBOL


       IDENTIFICATION DIVISION.
       PROGRAM-ID. MERGING-OF-SEQUENTIAL-FILES.
       ENVIRONMENT DIVISION.
       CONFIGURATION SECTION.
       SOURCE-COMPUTER.
       OBJECT-COMPUTER.
       INPUT-OUTPUT SECTION.
       FILE-CONTROL.
           SELECT STU1-FILE ASSIGN TO DISK
           ORGANIZATION IS LINE SEQUENTIAL.
           SELECT STU2-FILE ASSIGN TO DISK
           ORGANIZATION IS LINE SEQUENTIAL.
           SELECT OUT-FILE ASSIGN TO DISK
           ORGANIZATION IS LINE SEQUENTIAL.
           SELECT WORK-FILE ASSIGN TO DISK.
       DATA DIVISION.
       FILE SECTION.
       FD  STU1-FILE
           LABEL RECORDS ARE STANDARD
           VALUE OF FILE-ID IS "LIST1.DAT"
           DATA RECORD IS STU1-REC.
       01  STU1-REC.
           02 REGNO1   PIC 999.
           02 NAME1    PIC X(10).
           02 YOA1     PIC 9999.
       FD  STU2-FILE
           LABEL RECORDS ARE STANDARD
           VALUE OF FILE-ID IS "LIST2.DAT"
           DATA RECORD IS STU2-REC.
       01  STU2-REC.
           02 REGNO2   PIC 999.
           02 NAME2    PIC X(10).
           02 YOA2     PIC 9999.
       FD  OUT-FILE
           LABEL RECORDS ARE STANDARD
           VALUE OF FILE-ID IS "MLIST.DAT"
           DATA RECORD IS OUT-REC.
       01  OUT-REC.
           02 OREGNO   PIC 999.
           02 ONAME    PIC X(10).
           02 OYOA     PIC 9999.
       SD  WORK-FILE
           DATA RECORD IS WORK-REC.
       01  WORK-REC.
           02 WREGNO   PIC 999.
           02 WNAME    PIC X(10).
           02 WYOA     PIC 9999.
       PROCEDURE DIVISION.
       MAIN-PARA.
           MERGE WORK-FILE
                ON DESCENDING KEY WYOA
                ON ASCENDING KEY WNAME
                USING STU1-FILE STU2-FILE
                GIVING OUT-FILE.
       OPEN-PARA.
           OPEN INPUT OUT-FILE.
           DISPLAY "------------------------------------".
           DISPLAY "   MERGED RECORDS".
           DISPLAY "------------------------------------".
       READ-PARA.
           READ OUT-FILE RECORD AT END GO TO CLOSE-PARA.
           DISPLAY OUT-REC.
           GO TO READ-PARA.
       CLOSE-PARA.
           DISPLAY "------------------------------------".
           DISPLAY " ".
           CLOSE OUT-FILE.
           STOP RUN.

No comments:

Post a comment