Google
 

Trailing-Edge - PDP-10 Archives - decuslib20-05 - decus/20-0137/mthmrg/mthmrg.cbl
There are 2 other files named mthmrg.cbl in the archive. Click here to see a list.
       IDENTIFICATION DIVISION.
       PROGRAM-ID.  MTHMRG.
       AUTHOR.  BERENICE GAN HOUCHARD.
       REMARKS.  WESTERN MICHIGAN UNIVERSITY
           MTHMRG.CBL (FILE NAME ON LIBRARY DECTAPE)
           MTHMRG, 3.4.1 (CALLING NAME, SUBLST NO.)
           MATCH, MERGE, AND UPDATING FILES.
           THIS PROGRAM WAS WRITTEN BY BERENICE GAN HOUCHARD AND 
           LATER MODIFIED BY M. LIBERACKI
           ABOVE REMARKS AND RIGHT ADJUSTED REMARKS PUT IN BY WG.
       DATE-WRITTEN.  OCTOBER, 1972.
       ENVIRONMENT DIVISION.
       INPUT-OUTPUT SECTION.
       FILE-CONTROL.
           SELECT INITIAL-FILE ASSIGN TO DSK.
           SELECT UPDATE-FILE ASSIGN TO DSK.
           SELECT FILE-1 ASSIGN TO DSK.
           SELECT FILE-2 ASSIGN TO DSK.
           SELECT FILE-3 ASSIGN TO DSK.
           SELECT TEMP-IN-FILE ASSIGN TO DSK.
           SELECT TEMP-UP-FILE ASSIGN TO DSK.
           SELECT SORTING ASSIGN TO DSKC,DSKC,DSKC,DSKC,DSKC,DSKC.
       DATA DIVISION.
       FILE SECTION.
       FD  INITIAL-FILE VALUE OF IDENTIFICATION IS IN-DAT.
       01  INITIAL-RECORD DISPLAY-7.
           02  IN-REC PICTURE X OCCURS 80 TIMES.
       FD  UPDATE-FILE VALUE OF IDENTIFICATION IS UP-DAT.
       01  UPDATE-RECORD DISPLAY-7.
           02  UP-REC PICTURE X OCCURS 80 TIMES.
       FD  FILE-1 VALUE OF IDENTIFICATION IS RPT-1.
       01  FILE1-RECORD DISPLAY-7.
           02  FILE1-REC PICTURE X OCCURS 80 TIMES.
       FD  FILE-2 VALUE OF IDENTIFICATION IS RPT-2.
       01  FILE2-RECORD DISPLAY-7.
           02  FILE2-REC PICTURE X OCCURS 80 TIMES.
       FD  FILE-3 VALUE OF IDENTIFICATION IS RPT-3.
       01  FILE3-RECORD DISPLAY-7.
           02  FILE3-REC PICTURE X OCCURS 80 TIMES.
       FD  TEMP-IN-FILE VALUE OF IDENTIFICATION IS "TEMP1 FIL".
       01  TEMP-IN-RECORD DISPLAY-7.
           02  TEMP-IN-REC PICTURE X OCCURS 80 TIMES.
       FD  TEMP-UP-FILE VALUE OF IDENTIFICATION IS "TEMP2 FIL".
       01  TEMP-UP-RECORD DISPLAY-7.
           02  TEMP-UP-REC PICTURE X OCCURS 80 TIMES.
       SD  SORTING.
       01  SORT-REC DISPLAY-7 PICTURE X(80).
       WORKING-STORAGE SECTION.
      * 01  I-NAME VALUE 'MTHMRG' PIC X(6) DISPLAY-7.
      * 01  IX REDEFINES I-NAME COMP PIC S9(18).
       01  IN-DAT DISPLAY-7.
           02  IN-NAME PICTURE X OCCURS 9 TIMES.
       01  UP-DAT DISPLAY-7.
           02  UP-NAME PICTURE X OCCURS 9 TIMES.
       01  NAME-RECORD DISPLAY-7.
           02  NAME-REC PICTURE X OCCURS 10 TIMES.
       01  NAME-OUT-1 PICTURE X(10).
       01  RPT-1 DISPLAY-7.
            02  RPT1-NAME.
               03  RPT1-REC PICTURE X.
               03  RPT1-REC-1 PICTURE X(5) VALUE "1    ".
           02  RPT1-EXT PICTURE X(3) VALUE "DAT".
       01  RPT-2 DISPLAY-7.
           02  RPT2-NAME.
               03  RPT2-REC PICTURE X.
               03  RPT2-REC-1 PICTURE X(5) VALUE "2    ".
           02  RPT2-EXT PICTURE X(3) VALUE "DAT".
       01  RPT-3 DISPLAY-7.
           02  RPT3-NAME.
               03  RPT3-REC PICTURE X.
               03  RPT3-REC-1 PICTURE X(5) VALUE "3    ".
           02  RPT3-EXT PICTURE X(3) VALUE "DAT".
       01  ALPHA-RECORD PICTURE X(26) VALUE "ABCDEFGHIJKLMNOPQRST
      -    "UVWXYZ".
       01  ALP-RECORD REDEFINES ALPHA-RECORD.
           02  ALPHA-REC PIC X OCCURS 26 TIMES.
       01  PARAMETER DISPLAY-7.
           02  WHAT-TYPE PICTURE X(5).
       01  KEY-LOC DISPLAY-7.
           02  FROM-KEY PICTURE 99.
           02  TO-KEY PICTURE 99.
       01  TEMP-RECORD DISPLAY-7.
           02  TEMP-REC PICTURE X OCCURS 80 TIMES.
       01  TEMP-1 DISPLAY-7.
           02 TEMP1-REC PICTURE X OCCURS 80 TIMES.
       01  RECORD-1 DISPLAY-7.
           02  REC-1 PICTURE X OCCURS 80 TIMES.
       01  RECORD-2 DISPLAY-7.
           02  REC-2 PICTURE X OCCURS 80 TIMES.
       77  PERIOD PICTURE X VALUE ".".
       77  FLAG PICTURE 9 USAGE IS COMP.
       77  CARD-IN PICTURE 9(7) USAGE IS COMP.
       77  CARD-UP PICTURE 9(7) USAGE IS COMP.
       77  COUNTER-1 PICTURE 9(7) USAGE IS COMP.
       77  COUNTER-2 PICTURE 9(7) USAGE IS COMP.
       77  COUNTER-3 PICTURE 9(7) USAGE IS COMP.
       77  COUNTER-4 PICTURE 9(7) USAGE IS COMP.
       77  COUNTER-5 PICTURE 9(7) USAGE IS COMP.
       77  TYPE-1 PICTURE X(5) VALUE "REPLA".
       77  TYPE-2 PICTURE X(5) VALUE "INSER".
       77  TYPE-3 PICTURE X(5) VALUE "DELET".
       77  TYPE-4 PICTURE X(5) VALUE "MISMA".
       77  TYPE-5 PICTURE X(5) VALUE "MATCH".
       77  RANGE-1 PICTURE 99 USAGE IS COMP.
       77  RANGE-2 PICTURE 99 USAGE IS COMP.
       77  KK PICTURE 9(7) USAGE IS COMP.
       77  K PICTURE 99 USAGE IS COMP.
       77  I PICTURE 99 USAGE IS COMP.
       77  J PICTURE 99 USAGE IS COMP.
       77  POINT-ER PICTURE 99 USAGE IS COMP.
       77  LAST-JOB PICTURE 9 USAGE IS COMP.
       01  OUT-MESSAGE.
           02  FILLER PICTURE X(10) VALUE SPACES.
           02  FILLER PICTURE X(24) VALUE "*****SUMMARY REPORT*****".
       01  OUT-MESSAGE-1.
           02  FILLER PICTURE X(44) VALUE "TOTAL NUMBER OF RECORDS IN
      -        " INPUT DATA FILES:".
       01  OUT-MESSAGE-2.
           02  FILLER PICTURE X(10) VALUE SPACES.
           02  NAME-MES PICTURE X(10).
           02  FILLER PICTURE X(2) VALUE " =".
           02  VALUE-1 PICTURE ZZZZZZ9.
       01  OUT-MESSAGE-3.
           02  FILLER PICTURE X(41) VALUE "NUMBER OF RECORDS IN FINAL
      -        " UPDATED FILE =".
           02  VALUE-3 PICTURE ZZZZZZ9.
       01  OUT-MESSAGE-4.
           02  FILLER PIC X(28) VALUE "THIS FILE IS UNDER FILENAME ".
           02  NAME-1 PICTURE X OCCURS 2 TIMES.
           02  FILLER PICTURE X(4) VALUE ".DAT".
       01  OUT-MESSAGE-7.
           02  FILLER PICTURE X(21) VALUE "NUMBER OF RECORDS IN ".
           02  NAME-NOT PICTURE X(10).
           02  FILLER PICTURE X(13) VALUE " NOT USED =  ".
       PROCEDURE DIVISION.
       BEGIN.
      *     ENTER FORTRAN USAGE USING IX.
           MOVE SPACES TO IN-DAT, UP-DAT.
           SET POINT-ER TO 0.
       START-1.
           ADD 1 TO POINT-ER.
           IF POINT-ER IS GREATER THAN 26,
               DISPLAY "TOO MANY FILES, JOB ABANDON.",
               GO TO FINAL-EXIT.
      *---------------CONSTRUCT OUTPUT FILE NAMES;  SEE SECTION 4.2
      *--------------- OF WRITE UP
           MOVE ALPHA-REC (POINT-ER) TO RPT1-REC.
           MOVE ALPHA-REC (POINT-ER) TO RPT2-REC.
           MOVE ALPHA-REC (POINT-ER) TO NAME-1 (1).
           DISPLAY "ENTER INPUT DATA FILENAME--" WITH NO ADVANCING.
      *---------------THIS IS 5TH 01 IN WS SECTION.
           ACCEPT NAME-RECORD.
           SET FLAG TO 1.
      *---------------NAME-OUT-1 IS 6TH 01 IN WS SECTION.
           MOVE NAME-RECORD TO NAME-OUT-1.
       START-1A.
           SET K TO 10.
       CHECK-PERIOD.
      *---------------PERIOD HAS LEVEL NO. 77
           IF NAME-REC (K) IS = PERIOD,
               GO TO FOUND-PERIOD;
           ELSE COMPUTE K = K - 1,
               IF K = 1, GO TO NO-EXT;
               ELSE GO TO CHECK-PERIOD.
       FOUND-PERIOD.
           COMPUTE I = K + 1.
           MOVE 6 TO KK.
           PERFORM ADJUST-NAME-1 VARYING J FROM I BY 1 UNTIL J > K + 3.
           MOVE ZERO TO KK.
           PERFORM ADJUST-NAME-1 VARYING J FROM 1 BY 1 UNTIL J > K - 1.
           GO TO WHERE-TO.
       ADJUST-NAME-1.
           ADD 1 TO KK.
      *---------------FLAG=1 MEANS INPUT DATA FILE NAME WAS READ, 
      *--------------- FLAG=2 UPDATE FILE NAME WAS READ.
           IF FLAG = 1,
               MOVE NAME-REC (J) TO IN-NAME (KK);
           ELSE MOVE NAME-REC (J) TO UP-NAME (KK).
       NO-EXT.
           MOVE ZERO TO KK.
           PERFORM ADJUST-NAME-1 VARYING J FROM 1 BY 1 UNTIL
               J > 6.
       WHERE-TO.
           IF FLAG = 1, GO TO READ-UP-NAME;
           ELSE IF NAME-OUT-1 IS NOT = NAME-RECORD, GO TO READ-OPTION;
               ELSE DISPLAY " ",
               DISPLAY " ",
               DISPLAY "CANNOT HAVE IDENTICAL INPUT FILES, JOB
      -        " TERMINATES.",
      *---------------STOP RUN IS IN FINAL-EXIT
               GO TO FINAL-EXIT.
       READ-UP-NAME.
           DISPLAY "          UPDATE FILENAME--" WITH NO ADVANCING.
           ACCEPT NAME-RECORD.
      *---------------NAME-NOT IS IN LAST REC. OF WS SECTION.
           MOVE NAME-RECORD TO NAME-NOT.
           SET FLAG TO 0.
           GO TO START-1A.
       READ-OPTION.
           DISPLAY " ".
           DISPLAY "ENTER OPTION (REPLACE,INSERT,DELETE,MISMATCH,
      -        "MATCH)--" WITH NO ADVANCING.
      *---------------PARAMETER IS 12TH 01 IN WS SECTION.
           ACCEPT PARAMETER.
      *---------------TYPE-1,...,TYPE-5 HAVE LEVEL NOS. 77 IN WS
      *--------------- SECTION.
           IF WHAT-TYPE IS = TYPE-1 OR TYPE-2 OR TYPE-3 OR TYPE-4
               OR TYPE-5, GO TO READ-KEY-WORD.
           DISPLAY " ".
           DISPLAY " ".
           DISPLAY "ERROR IN OPTION, JOB TERMINATES.".
           GO TO FINAL-EXIT.
      *---------------ALL 5 OPTIONS HERE.
       READ-KEY-WORD.
      *---------------SEE WRITE UP SECTION 5.1.1
           DISPLAY "KEY WORD LOCATED IN COLUMNS--FROM,TO--" WITH NO
               ADVANCING.
           MOVE ZEROS TO KEY-LOC.
           ACCEPT FROM-KEY, TO-KEY.
           IF FROM-KEY > TO-KEY, GO TO DISPLAY-2.
           IF FROM-KEY IS < 0 OR > 80, GO TO DISPLAY-2.
           IF TO-KEY IS < 81 AND > 0, GO TO COMPUTE-1.
       DISPLAY-2.
           DISPLAY " ".
           DISPLAY " ".
           DISPLAY " ".
           DISPLAY "ERROR IN KEYWORD, JOB TERMINATES.".
           GO TO FINAL-EXIT.
       COMPUTE-1.
           MOVE ZEROS TO CARD-IN, CARD-UP.
           COMPUTE RANGE-1 = TO-KEY - FROM-KEY + 1.
           COMPUTE RANGE-2 = RANGE-1 + 1.
           COMPUTE J = FROM-KEY - 1.
       SORT-1.
      *---------------SEE 6TH FD IN FILE SECTION FOR TEMP-IN-FILE.
           SORT SORTING ON ASCENDING KEY SORT-REC INPUT PROCEDURE
               SORT-READ-1 GIVING TEMP-IN-FILE.
       SORT-2.
           SORT SORTING ON ASCENDING KEY SORT-REC INPUT PROCEDURE
               SORT-READ-UPDATE GIVING TEMP-UP-FILE.
       START-2.
           OPEN INPUT TEMP-IN-FILE TEMP-UP-FILE.
      *---------------SEE WRITE UP SECTION 4.2 ABOUT OUTPUT FILES.
           OPEN OUTPUT FILE-1 FILE-2.
           MOVE SPACES TO TEMP-RECORD, TEMP-1, RECORD-1, RECORD-2.
       START-3.
      ***AM	(MTHMRG #3.4.1 - CHANGE #1) MSL 6-FEB-78
           IF WHAT-TYPE IS = TYPE-1
                ALTER EQUAL-ALL TO PROCEED TO REP-EQUAL
                ALTER LESS-ALL TO PROCEED TO REP-LESS
                ALTER GREATER-ALL TO PROCEED TO REP-GREATER
                ALTER ADJUST-1 TO PROCEED TO REP-ADJUST-1
                ALTER ADJUST-2 TO PROCEED TO REP-ADJUST-2
                GO TO START-4.
      ***END	(MAIN SECTION) (START-3 + 8)
           IF WHAT-TYPE IS = TYPE-2,
               ALTER EQUAL-ALL TO PROCEED TO INS-EQUAL,
               ALTER LESS-ALL TO PROCEED TO INS-LESS,
               ALTER GREATER-ALL TO PROCEED TO INS-GREATER,
               ALTER ADJUST-1 TO PROCEED TO INS-ADJUST-1,
               ALTER ADJUST-2 TO PROCEED TO INS-ADJUST-2,
               GO TO START-4.
           IF WHAT-TYPE IS = TYPE-3,
               ALTER EQUAL-ALL TO PROCEED TO DEL-EQUAL,
               ALTER LESS-ALL TO PROCEED TO REP-LESS,
               ALTER GREATER-ALL TO PROCEED TO REP-GREATER,
               GO TO START-4.
           MOVE ALPHA-REC (POINT-ER) TO RPT3-REC.
           OPEN OUTPUT FILE-3.
           MOVE ZEROS TO COUNTER-5.
           MOVE ZEROS TO FLAG.
           ALTER EQUAL-ALL TO PROCEED TO MAT-EQUAL.
           ALTER LESS-ALL TO PROCEED TO MIS-LESS.
           ALTER GREATER-ALL TO PROCEED TO MIS-GREATER.
           ALTER ADJUST-1 TO PROCEED TO MIS-ADJUST-1.
           ALTER ADJUST-2 TO PROCEED TO MIS-ADJUST-2.
           IF WHAT-TYPE = TYPE-4,
               MOVE 1 TO FLAG,
               ALTER EQUAL-ALL TO PROCEED TO CHECK-END.
      *---------------HERE FOR ALL 5 OPTIONS.
       START-4.
           MOVE ZEROS TO COUNTER-1, COUNTER-2, COUNTER-3, COUNTER-4.
           MOVE SPACES TO TEMP-RECORD, TEMP-1, RECORD-1, RECORD-2.
      *---------------MOVE KEY WORD FOR COMPARISON.
       ALL-READ-1.
           READ TEMP-IN-FILE AT END GO TO END-ALL.
           ADD 1 TO COUNTER-1.
           PERFORM MOVE-1 VARYING K FROM 1 BY 1 UNTIL K > RANGE-1.
       ALL-READ-2.
           READ TEMP-UP-FILE AT END GO TO END-ALL.
           ADD 1 TO COUNTER-2.
           PERFORM MOVE-2 VARYING K FROM 1 BY 1 UNTIL K > RANGE-1.
       CHECK-ALL.
           IF RECORD-1 IS = RECORD-2, GO TO EQUAL-ALL.
           IF RECORD-1 IS < RECORD-2, GO TO LESS-ALL;
               ELSE GO TO GREATER-ALL.
      *---------------HERE WHEN THERE ARE NO MORE RECORDS IN THE
      *--------------- UPDATE FILE.
       END-ALL.
           CLOSE FILE-1 FILE-2 TEMP-IN-FILE TEMP-UP-FILE.
           DISPLAY " ".
           DISPLAY " ".
           DISPLAY OUT-MESSAGE.
           DISPLAY " ".
           DISPLAY OUT-MESSAGE-1.
           MOVE CARD-IN TO VALUE-1.
           MOVE NAME-OUT-1 TO NAME-MES.
           DISPLAY OUT-MESSAGE-2.
           MOVE NAME-RECORD TO NAME-MES.
           MOVE CARD-UP TO VALUE-1.
           DISPLAY OUT-MESSAGE-2.
           DISPLAY " ".
           IF WHAT-TYPE = TYPE-1,
               DISPLAY OUT-MESSAGE-3, CARD-IN,
               MOVE 1 TO NAME-1 (2),
               DISPLAY OUT-MESSAGE-4,
               DISPLAY "NUMBER OF RECORDS REPLACED =  ", COUNTER-3,
               PERFORM CHECK-MESSAGE,
               GO TO TTY-2.
           IF WHAT-TYPE = TYPE-2,
               COMPUTE KK = CARD-IN + COUNTER-3,
               MOVE KK TO VALUE-3,
               DISPLAY OUT-MESSAGE-3,
               MOVE 1 TO NAME-1 (2),
               DISPLAY OUT-MESSAGE-4,
               DISPLAY "NUMBER OF RECORDS INSERTED =  ", COUNTER-3,
               PERFORM CHECK-MESSAGE,
               GO TO TTY-2.
           IF WHAT-TYPE = TYPE-3,
               COMPUTE KK = CARD-IN - COUNTER-3,
               MOVE KK TO VALUE-3,
               DISPLAY OUT-MESSAGE-3,
               MOVE 1 TO NAME-1 (2),
               DISPLAY OUT-MESSAGE-4,
               DISPLAY "NUMBER OF RECORDS DELETED =  ", COUNTER-3,
               PERFORM CHECK-MESSAGE,
               GO TO TTY-2.
           CLOSE FILE-3.
           PERFORM MIS-MAT-MESSAGE.
           IF FLAG = 1,
               DISPLAY "TOTAL NUMBER OF RECORDS MISMATCHED FROM BOTH
      -            " FILES =  ", COUNTER-5;
           ELSE DISPLAY "TOTAL NUMBER OF RECORDS MATCHED =  ",
               COUNTER-5.
           IF COUNTER-5 IS NOT EQUAL TO 0,
               MOVE 3 TO NAME-1 (2),
               DISPLAY OUT-MESSAGE-4.
           GO TO TTY-2.
       MIS-MAT-MESSAGE.
           DISPLAY "NUMBER OF RECORDS MISMATCHED IN ", NAME-OUT-1,
      -        " =  ", COUNTER-3.
           IF COUNTER-3 IS NOT = 0,
               MOVE 1 TO NAME-1 (2),
               DISPLAY OUT-MESSAGE-4.
           DISPLAY " ".
           DISPLAY "NUMBER OF RECORDS MISMATCHED IN ", NAME-RECORD,
      -        " =  ", COUNTER-4.
           IF COUNTER-4 IS NOT = 0,
               MOVE 2 TO NAME-1 (2),
               DISPLAY OUT-MESSAGE-4.
           DISPLAY " ".
      *---------------ALL 5 OPTIONS.
       TTY-2.
           DISPLAY " ".
           DISPLAY " ".
           DISPLAY "               **************".
           DISPLAY " ".
           GO TO EXIT-1.
      *---------------DELETE, REPLACE, INSERT OPTIONS
       CHECK-MESSAGE.
           DISPLAY " ".
           DISPLAY OUT-MESSAGE-7, COUNTER-4.
           IF COUNTER-4 IS NOT = 0,
           MOVE 2 TO NAME-1 (2),
           DISPLAY OUT-MESSAGE-4.
      *---------------REPLACE OPTION.
       REP-EQUAL.
           ADD 1 TO COUNTER-3.
           PERFORM UP-FILE1.
      *---------------MATCH OPTION
       CHECK-END.
           IF COUNTER-1 IS NOT EQUAL TO CARD-IN AND COUNTER-2
               IS NOT EQUAL TO CARD-UP, GO TO ALL-READ-1.
           IF COUNTER-1 = CARD-IN AND COUNTER-2 = CARD-UP, GO TO
               END-ALL.
           IF COUNTER-1 = CARD-IN, GO TO ADJUST-1;
           ELSE GO TO ADJUST-2.
       REP-ADJUST-1.
           READ TEMP-UP-FILE AT END GO TO END-ALL.
           PERFORM UP-FILE2.
           ADD 1 TO COUNTER-4.
           GO TO REP-ADJUST-1.
       REP-ADJUST-2.
           READ TEMP-IN-FILE AT END GO TO END-ALL.
           PERFORM IN-FILE1.
           GO TO REP-ADJUST-2.
      *---------------REPLACE, DELETE OPTIONS
       REP-LESS.
           PERFORM IN-FILE1.
           IF COUNTER-1 IS NOT = TO CARD-IN, 
               PERFORM ALL-READ-1,
               GO TO CHECK-ALL;
           ELSE PERFORM UP-FILE2.
           ADD 1 TO COUNTER-4,
           GO TO REP-ADJUST-1.
      *---------------REPLACE, DELETE OPTIONS
       REP-GREATER.
           PERFORM UP-FILE2.
           ADD 1 TO COUNTER-4.
           IF COUNTER-2 IS NOT = CARD-UP,
               GO TO ALL-READ-2.
           PERFORM IN-FILE1.
           GO TO REP-ADJUST-2.
      *---------------INSERT OPTION
       INS-EQUAL.
           ADD 1 TO COUNTER-4.
           PERFORM IN-FILE1.
           PERFORM UP-FILE2.
           GO TO CHECK-END.
      *---------------INSERT OPTION
       INS-ADJUST-1.
           READ TEMP-UP-FILE AT END GO TO END-ALL.
           ADD 1 TO COUNTER-3.
           PERFORM UP-FILE1.
           GO TO INS-ADJUST-1.
      *---------------INSERT OPTION
       INS-ADJUST-2.
           READ TEMP-IN-FILE AT END GO TO END-ALL.
           PERFORM IN-FILE1.
           GO TO INS-ADJUST-2.
      *---------------INSERT OPTION
       INS-LESS.
           PERFORM IN-FILE1.
           IF COUNTER-1 = CARD-IN,
               PERFORM UP-FILE1,
               ADD 1 TO COUNTER-3,
               GO TO INS-ADJUST-1;
           ELSE PERFORM ALL-READ-1,
               GO TO CHECK-ALL.
      *---------------INSERT OPTION
       INS-GREATER.
           ADD 1 TO COUNTER-3.
           PERFORM UP-FILE1.
           IF COUNTER-2 IS NOT = CARD-UP, GO TO ALL-READ-2;
           ELSE PERFORM IN-FILE1,
               GO TO INS-ADJUST-2.
      *---------------DELETE OPTION
       DEL-EQUAL.
           ADD 1 TO COUNTER-3.
           GO TO CHECK-END.
      *---------------MATCH, MISMATCH OPTIONS
       MIS-LESS.
           PERFORM IN-FILE1.
           ADD 1 TO COUNTER-3.
           IF FLAG = 1,
               WRITE FILE3-RECORD FROM FILE1-RECORD,
               ADD 1 TO COUNTER-5.
           IF COUNTER-1 IS NOT = CARD-IN,
               PERFORM ALL-READ-1,
               GO TO CHECK-ALL.
           PERFORM UP-FILE2.
           ADD 1 TO COUNTER-4.
           IF FLAG = 1,
               WRITE FILE3-RECORD FROM FILE2-RECORD,
               ADD 1 TO COUNTER-5.
           GO TO MIS-ADJUST-1.
      *---------------MATCH, MISMATCH OPTIONS
       MIS-GREATER.
           PERFORM UP-FILE2.
           ADD 1 TO COUNTER-4.
           IF FLAG = 1,
               WRITE FILE3-RECORD FROM FILE2-RECORD,
               ADD 1 TO COUNTER-5.
           IF COUNTER-2 IS NOT = CARD-UP,
               GO TO ALL-READ-2.
           PERFORM IN-FILE1.
           ADD 1 TO COUNTER-3.
           IF FLAG = 1,
               WRITE FILE3-RECORD FROM FILE1-RECORD,
               ADD 1 TO COUNTER-5.
           GO TO MIS-ADJUST-2.
      *---------------MATCH, MISMATCH OPTIONS
       MIS-ADJUST-1.
           READ TEMP-UP-FILE AT END GO TO END-ALL.
           PERFORM UP-FILE2.
           ADD 1 TO COUNTER-4.
           IF FLAG = 1,
               WRITE FILE3-RECORD FROM FILE2-RECORD,
               ADD 1 TO COUNTER-5.
           GO TO MIS-ADJUST-1.
      *---------------MATCH, MISMATCH OPTIONS
       MIS-ADJUST-2.
           READ TEMP-IN-FILE AT END GO TO END-ALL.
           PERFORM IN-FILE1.
           ADD 1 TO COUNTER-3.
           IF FLAG = 1,
               WRITE FILE3-RECORD FROM FILE1-RECORD,
               ADD 1 TO COUNTER-5.
           GO TO MIS-ADJUST-2.
      *---------------MATCH, MISMATCH OPTIONS
       MAT-EQUAL.
           PERFORM MOVE-TEMP-IN.
           WRITE FILE3-RECORD FROM TEMP-RECORD.
           ADD 1 TO COUNTER-5.
           GO TO CHECK-END.
      *---------------INSERT, REPLACE, DELETE OPTIONS
       UP-FILE1.
           PERFORM MOVE-TEMP-UP.
           WRITE FILE1-RECORD FROM TEMP-RECORD.
      *---------------MATCH, MISMATCH, REPLACE, DELETE, INSERT OPTIONS
       UP-FILE2.
           PERFORM MOVE-TEMP-UP.
           WRITE FILE2-RECORD FROM TEMP-RECORD.
      *---------------INSERT, REPLACE, DELETE, MATCH, MISMATCH
       IN-FILE1.
           PERFORM MOVE-TEMP-IN.
           WRITE FILE1-RECORD FROM TEMP-RECORD.
      *---------------APPARENTLY NOT USED
       IN-FILE2.
           PERFORM MOVE-TEMP-IN.
           WRITE FILE2-RECORD FROM TEMP-RECORD.
      *---------------ALL 5 OPTIONS FOR EQUAL-ALL, LESS-ALL,
      *--------------- GREATER-ALL, ADJUST-1, ADJUST-2, MOVE-1, MOVE-2
       EQUAL-ALL.
           GO TO REP-EQUAL.
       LESS-ALL.
           GO TO REP-LESS.
       GREATER-ALL.
           GO TO REP-GREATER.
       ADJUST-1.
           GO TO REP-ADJUST-1.
       ADJUST-2.
           GO TO REP-ADJUST-2.
       MOVE-1.
           MOVE TEMP-IN-REC (K) TO REC-1 (K).
       MOVE-2.
           MOVE TEMP-UP-REC (K) TO REC-2 (K).
      *---------------MATCH, MISMATCH OPTIONS
       MOVE-TEMP-IN.
           MOVE TEMP-IN-RECORD TO TEMP-RECORD.
           IF FROM-KEY IS NOT EQUAL TO 1, PERFORM SWITCH-OVER.
       MOVE-TEMP-UP.
           MOVE TEMP-UP-RECORD TO TEMP-RECORD.
           IF FROM-KEY IS NOT EQUAL TO 1, PERFORM SWITCH-OVER.
       SWITCH-OVER.
           PERFORM SWITCH-OVER-1 VARYING K FROM 1 BY 1 UNTIL K > TO-KEY.
           MOVE J TO I.  PERFORM SWITCH-OVER-2 VARYING K FROM 1 BY 1
               UNTIL K > RANGE-1.
           MOVE ZEROS TO I.  PERFORM SWITCH-OVER-2 VARYING K FROM
               RANGE-2 BY 1 UNTIL K > TO-KEY.
       SWITCH-OVER-1.
           MOVE TEMP-REC (K) TO TEMP1-REC (K).
       SWITCH-OVER-2.
           ADD 1 TO I.
           MOVE TEMP1-REC (K) TO TEMP-REC (I).
      *---------------HERE FOR ALL 5 OPTIONS
       EXIT-1.
           DISPLAY " ".
           DISPLAY "END OF JOB, TYPE 1 TO CONTINUE OR 0 TO TERMINATE
      -        "--" WITH NO ADVANCING.
           ACCEPT LAST-JOB.
           IF LAST-JOB = 1,
              DISPLAY " ",
              DISPLAY " ",
              GO TO START-1.
      FINAL-EXIT.
           STOP RUN.
       SORT-READ-1 SECTION.
       OPEN-READ-1.
           OPEN INPUT INITIAL-FILE.
       READ-1.
           READ INITIAL-FILE AT END GO TO END-READ-1.
           ADD 1 TO CARD-IN.
           IF FROM-KEY IS EQUAL TO 1, GO TO RELEASE-1.
           PERFORM MOVE-OUT VARYING K FROM 1 BY 1 UNTIL K > TO-KEY.
      *---------------SEE COMPUTE-1(J=FROM-KEY MINUS1)
           MOVE J TO I.  PERFORM MOVE-OVER VARYING K FROM 1 BY 1
               UNTIL K > RANGE-1.
           MOVE ZEROS TO I.  PERFORM MOVE-OVER VARYING K FROM RANGE-2
               BY 1 UNTIL K > TO-KEY.
       RELEASE-1.  MOVE INITIAL-RECORD TO SORT-REC.
           RELEASE SORT-REC.
           GO TO READ-1.
       MOVE-OUT.
           MOVE IN-REC (K) TO TEMP-REC (K).
       MOVE-OVER.
           COMPUTE I = I + 1.
           MOVE TEMP-REC (I) TO IN-REC (K).
       END-READ-1.
           CLOSE INITIAL-FILE.
       SORT-READ-UPDATE SECTION.
       OPEN-READ-UPDATE.
           OPEN INPUT UPDATE-FILE.
       READ-UPDATE.
           READ UPDATE-FILE AT END GO TO END-READ-2.
           ADD 1 TO CARD-UP.
           IF FROM-KEY IS EQUAL TO 1, GO TO RELEASE-2.
           PERFORM MOVE-OUT-2 VARYING K FROM 1 BY 1 UNTIL K > TO-KEY.
           MOVE J TO I.  PERFORM MOVE-OVER-2 VARYING K FROM 1 BY 1
               UNTIL K > RANGE-1.
           MOVE ZEROS TO I.  PERFORM MOVE-OVER-2 VARYING K FROM RANGE-2
               BY 1 UNTIL K > TO-KEY.
       RELEASE-2.
           MOVE UPDATE-RECORD TO SORT-REC.
           RELEASE SORT-REC.
           GO TO READ-UPDATE.
       MOVE-OUT-2.
           MOVE UP-REC (K) TO TEMP-REC (K).
       MOVE-OVER-2.
           COMPUTE I = I + 1.
           MOVE TEMP-REC (I) TO UP-REC (K).
       END-READ-2.
           CLOSE UPDATE-FILE.