       IDENTIFICATION DIVISION.
       PROGRAM-ID.   RMPSUB.
      *                  Ver. 2.0B
      *              Date Revised   10 July 1984
       ENVIRONMENT DIVISION.
       CONFIGURATION SECTION.
       SOURCE-COMPUTER.  RMCOBOL.
       OBJECT-COMPUTER.  RMCOBOL.
       INPUT-OUTPUT SECTION.
       FILE-CONTROL.
       SELECT PATCH-FILE ASSIGN TO RANDOM FILE-NAME
           ORGANIZATION IS RELATIVE
           ACCESS MODE IS RANDOM
           RELATIVE KEY IS REL-KEY
           FILE STATUS IS FILE-STATUS.
       DATA DIVISION.
       FILE SECTION.
       FD  PATCH-FILE.
       01  PATCH-REC.
           03  PATCH-BYTE              PIC X        OCCURS 128 TIMES.
       WORKING-STORAGE SECTION.
       77  REL-KEY                     PIC 9(8).
       77  FILE-STATUS                 PIC XX.
       77  STATUS-IND                  PIC 9.
       01  TEMP-REC.
           03  TEMP-BYTE               PIC X        OCCURS 128 TIMES.
       77  FILE-NAME                   PIC X(74).
       77  REC-LNGTH                   PIC 999.
       77  BYTE-OFST                   PIC 9(10).
       77  Q                           PIC 999.
       77  R                           PIC 999.
       77  T                           PIC 999.
       LINKAGE SECTION.
       77  LNK-NAME                    PIC X(74).
       77  LNK-REC                     PIC X(128).
       77  LNK-LNGTH                   PIC 999.
       77  LNK-ADDR                    PIC 9(10).
       77  LNK-RTN                     PIC 9.
      *
       PROCEDURE DIVISION
           USING LNK-NAME LNK-REC LNK-LNGTH LNK-ADDR LNK-RTN.
       DECLARATIVES.
       FILE-ERROR SECTION.
           USE AFTER STANDARD ERROR PROCEDURE ON PATCH-FILE.
       FILE-PARA.
           IF FILE-STATUS = "23"
               MOVE 1 TO STATUS-IND   MOVE LOW-VALUES TO PATCH-REC
             ELSE MOVE 2 TO STATUS-IND.
       FILE-EXIT.
           EXIT.
       END DECLARATIVES.
      /
       MAIN SECTION.
       INIT-PARA.
           MOVE LNK-NAME TO FILE-NAME.
           MOVE LNK-REC TO TEMP-REC.
           MOVE LNK-LNGTH TO REC-LNGTH.
           MOVE LNK-ADDR TO BYTE-OFST.
           DIVIDE BYTE-OFST BY 128 GIVING REL-KEY REMAINDER R.
           ADD 1 TO REL-KEY.
           MOVE 0 TO STATUS-IND   OPEN I-O PATCH-FILE.
           PERFORM ERROR-PARA.
           PERFORM READ-PARA.
           COMPUTE T = 128 - R.
           MOVE 0 TO Q.
       MAIN-PARA.
           IF REC-LNGTH = 0
               MOVE PATCH-REC TO LNK-REC   GO TO END-PARA.
           IF REC-LNGTH > T
               PERFORM BYTE-MOVE T TIMES
               PERFORM OUTPUT-PARA
               ADD 1 TO REL-KEY
               PERFORM READ-PARA
               SUBTRACT T FROM REC-LNGTH
               MOVE 0 TO R.
           PERFORM BYTE-MOVE REC-LNGTH TIMES.
           PERFORM OUTPUT-PARA.
       END-PARA.
           MOVE 0 TO STATUS-IND   CLOSE PATCH-FILE.
           PERFORM ERROR-PARA.
           MOVE 1 TO LNK-RTN.
       EXIT-PARA.
           EXIT PROGRAM.
      *
       ERROR-PARA.
           IF STATUS-IND NOT = 0 GO TO EXIT-PARA.
       READ-PARA.
           READ PATCH-FILE RECORD.
           IF STATUS-IND = 2 GO TO EXIT-PARA.
       BYTE-MOVE.
           ADD 1 TO Q  ADD 1 TO R.
           MOVE TEMP-BYTE (Q) TO PATCH-BYTE (R).
       OUTPUT-PARA.
           IF STATUS-IND = 1 MOVE 0 TO STATUS-IND WRITE PATCH-REC
             ELSE IF STATUS-IND = 0 REWRITE PATCH-REC.
           PERFORM ERROR-PARA.
      *
       END PROGRAM.
