How to write Master file popular program in COBOL

This is sample COBOL program for reading Master file and Transaction file, and writes modified records into output file. This is most powerful logic across all financial projects using same Technics.

IDENTIFICATION DIVISION.
       PROGRAM-ID.  STRUCT.
      *****************************************************************
      * PROGRAM TO READ INPUT FILE, UPDATE IT FROM A TRANSACTIONS     *
      * FILE, AND WRITE AN OUTPUT FILE.                               *
      * IN:  In-File CONTAINS INPUT FILE.                             *
      *      Trans-File CONTAINS THE TRANSACTIONS FILE.               *
      * OUT: Out-File CONTAINS THE UPDATED OUTPUT FILE.               *
      *****************************************************************
       ENVIRONMENT DIVISION.
       INPUT-OUTPUT SECTION.
       FILE-CONTROL.
           SELECT In-File ASSIGN TO "NONSTIN.TXT"
                  ORGANIZATION IS LINE SEQUENTIAL.
           SELECT Out-File ASSIGN TO "NONSTOUT.TXT"
                  ORGANIZATION IS LINE SEQUENTIAL.
           SELECT Trans-File ASSIGN TO "NONSTTR.TXT"
                  ORGANIZATION IS LINE SEQUENTIAL.
       DATA DIVISION.
       FILE SECTION.
       FD  In-File
              BLOCK CONTAINS 0 RECORDS.
       01  In-Record.
           05  K                         PIC X(15).
           05  L.
               10  M                     PIC S9.
               10  N                     PIC X(4).
       FD  Out-File BLOCK CONTAINS 0 RECORDS.
       01  Out-Rec.
           05  K                         PIC X(15).
           05  L.
               10  M                     PIC S9.
               10  N                     PIC X(4).
       FD  Trans-File BLOCK CONTAINS 0 RECORDS.
       01  Trans-Record.
           05  K                         PIC X(15).
           05  L.
               10  M                     PIC S9.
               10  N                     PIC X(4).
       WORKING-STORAGE SECTION.
       01  In-Rec.
           05  K                         PIC X(15).
           05  L.
               10  M                     PIC S9.
               10  N                     PIC X(4).
       01  Trans-Rec.
           05  K                         PIC X(15).
           05  L.
               10  M                     PIC S9.
               10  N                     PIC X(4).
       01  Out-Record.
           05  K                         PIC X(15).
           05  L.
               10  M                     PIC S9.
               10  N                     PIC X(4).
       01  In-EOF                        PIC X.
      *            Flag for end of file.  "Y", EOF.  "N", no EOF.
       01  Record-Count                  PIC S9(8).
      *          Record-Count counts the records read and written.
       PROCEDURE DIVISION.
       A00-Begin.
           DISPLAY "BEGINNING STRUCT PROGRAM."
           OPEN INPUT In-File, Trans-File, OUTPUT Out-File
           MOVE LOW-VALUES TO In-Rec, Trans-Rec
           PERFORM A10-READ-In-File WITH TEST AFTER
                   UNTIL In-Rec = HIGH-VALUES
           DISPLAY "END OF PROGRAM"
           CLOSE In-File, Trans-File, Out-File
           GOBACK
           .
      **** Exit
       A10-Read-In-File.
           READ In-File INTO In-Rec
             AT END MOVE HIGH-VALUES TO In-Rec
           END-READ
           PERFORM WITH TEST BEFORE UNTIL Trans-Rec >= In-Rec
              IF Trans-Rec - LOW-VALUES
                 THEN READ Trans-File INTO Trans-Rec
                           AT END MOVE HIGH-VALUES TO Trans-Rec
                      END-READ
              END-IF
              IF Trans-Rec < In-Rec
                 THEN DISPLAY "TRANSACTION IGNORED:", Trans-Rec
                      MOVE LOW-VALU"ES TO Trans-Rec
              END-IF
           END-PERFORM
           EVALUATE TRUE
             WHEN In-Rec = HIGH-VALUES CONTINUE
             WHEN Trans-Rec = In-Rec DISPLAY "DELETING:", In-Rec
             WHEN OTHER
                  DISPLAY "WRITING: ", In-Rec
                  WRITE Out-Rec FROM In-Rec
           END-EVALUATE
           .
      **** Exit
       END PROGRAM STRUCT.
NONSTIN.TXT:
111111111111111AAAA
222222222222221AAAA
222222222222222AAAA
222222222222222DDDD
444444444444441BBBB
555555555555552CCCC
NONSTTR.TXT:
111111111111111BBBB
222222222222221AAAA
222222222222222AAAA
222222222222222EEEE
444444444444441BBBB
555555555555553CCCC
Advertisements

Author: Srini

Experienced software developer. Skills in Development, Coding, Testing and Debugging. Good Data analytic skills (Data Warehousing and BI). Also skills in Mainframe.