Flowchart and accompanying code for PAYEDIT.CBL





PAYEDIT.CBL

       IDENTIFICATION DIVISION.
       PROGRAM-ID.  EDIT1.
       AUTHOR. GROCER.
       ENVIRONMENT DIVISION.
       INPUT-OUTPUT SECTION.
       FILE-CONTROL.
           SELECT PAYROLL-KEYED
               ASSIGN TO "C:\PCOBWIN\CIS12FST\PAYKEY.DAT".
           SELECT PAYROLL-TRAN
               ASSIGN TO "C:\PCOBWIN\CIS12FST\PAYTRAN.DAT".
           SELECT PRINT-FILE
               ASSIGN TO "A:\payout.dat".
       DATA DIVISION.
       FILE SECTION.
       FD  PAYROLL-KEYED
           DATA RECORD IS PAY-KEYED-REC.
       01  PAY-KEYED-REC.
           05  EMP-ID.
               10  EMP-CD        PIC X.
                   88  VALID-EMP-CD       VALUE "F" "P" "C" "T".
               10  ID-NO         PIC 9(4).
               10  RDF-ID-NO REDEFINES ID-NO    PIC X(4).
           05  WORK-HRS          PIC 99.
           05  RDF-WORK-HRS REDEFINES WORK-HRS  PIC XX.
           05  OVT-HRS           PIC 99.
           05  RDF-OVT-HRS REDEFINES OVT-HRS  PIC XX.
           05  SICK-HRS          PIC 99.
           05  RDF-SICK-HRS REDEFINES SICK-HRS  PIC XX.
           05  VACA-HRS          PIC 99.
           05  RDF-VACA-HRS REDEFINES VACA-HRS  PIC XX.
           05  HOLIDAY-HRS       PIC 99.
           05  RDF-HOLIDAY-HRS REDEFINES HOLIDAY-HRS PIC XX.
           05  HOLIDAY-CODE      PIC X.
               88  VALID-HOLIDAY-CODE
                     VALUES " " "N" "K" "M" "L" "T" "C".
           05  BONUS-PAY         PIC 9999V99.
           05  RDF-BONUS-PAY REDEFINES BONUS-PAY PIC X(6).
       FD  PAYROLL-TRAN
           DATA RECORD IS PAY-TRAN-REC.
       01  PAY-TRAN-REC.
           05  INFO-FROM-REC     PIC X(22).
           05  DATE-TRAN         PIC 9(6).
       FD  PRINT-FILE
           DATA RECORD IS PRINTZ.
       01  PRINTZ.
           05  FILLER            PIC X.
           05  EMP-ID-PR         PIC X(5).
           05  FILLER            PIC X(5).
           05  DATA-IN-ERR-PR    PIC X(7).
           05  RDF-DATA-IN-ERR-PR REDEFINES DATA-IN-ERR-PR
                 PIC 9999.99.
           05  FILLER            PIC X(4).
           05  ERROR-MSG-PR      PIC X(50).
           05  FILLER            PIC X(8).
       WORKING-STORAGE SECTION.
       01  INDICATORS.
           05  EOF-IND           PIC XXX      VALUE "NO ".
               88  IT-IS-EOF                  VALUE "YES".
           05  ERROR-IND         PIC XXX      VALUE "NO ".
               88  THERE-IS-AN-ERROR          VALUE "YES".
               88  NO-ERRORS                  VALUE "NO ".
       01  WORK-AREAS.
           05  EMP-HRS-WS        PIC 999      VALUE 0.
       01  ACCUMULATORZ.
           05  NUM-VALID-TRANS   PIC 999      VALUE 0.
           05  NUM-INVALID-TRANS PIC 999      VALUE 0.
       01  DATE-AND-HDR-INFO.
           05  DATE-WS.
               10  YR-WS         PIC 99.
               10  MO-WS         PIC 99.
               10  DA-WS         PIC 99.
           05  PAGE-NO           PIC 99       VALUE 1.
           05  LNCT              PIC 99       VALUE 0.
       01  PAGE-HDR.
           05  FILLER            PIC X(5)     VALUE SPACES.
           05  DATE-HDR.
               10  MO-HDR        PIC 99       VALUE 0.
               10  FILLER        PIC X        VALUE "/".
               10  DA-HDR        PIC 99       VALUE 0.
               10  FILLER        PIC X        VALUE "/".
               10  YR-HDR        PIC 99       VALUE 0.
           05  FILLER            PIC X(13)    VALUE SPACES.
           05  FILLER            PIC X(28)
                 VALUE "TRANSACTION EXCEPTION REPORT".
           05  FILLER            PIC X(17)    VALUE SPACES.
           05  FILLER            PIC X(5)     VALUE "PAGE ".
           05  PAGE-NO-HDR       PIC Z9.
           05  FILLER            PIC XX       VALUE SPACES.
       01  COL-HDR.
           05  FILLER            PIC X(11)    VALUE " ID #      ".
           05  FILLER            PIC X(11)    VALUE "DATA       ".
           05  FILLER            PIC X(13)   VALUE "ERROR MESSAGE".
           05  FILLER            PIC X(45)    VALUE SPACES.
       01  TOTAL-LINE.
           05  FILLER               PIC X(32)
                 VALUE " NUMBER OF VALID TRANSACTIONS = ".
           05  NUM-VALID-TRANS-TL   PIC ZZ9.
           05  FILLER               PIC X(38)
                 VALUE "     NUMBER OF INVALID TRANSACTIONS = ".
           05  NUM-INVALID-TRANS-TL PIC ZZ9.
           05  FILLER               PIC X(4).
       PROCEDURE DIVISION.
       MAINLINE.
           PERFORM A-100-STARTUP.
           PERFORM B-100-PROCESS.
           PERFORM C-100-WRAPUP.
           STOP RUN.
       A-100-STARTUP.
           OPEN INPUT PAYROLL-KEYED
                OUTPUT PAYROLL-TRAN
                       PRINT-FILE.
           ACCEPT DATE-WS FROM DATE.
           MOVE MO-WS TO MO-HDR.
           MOVE DA-WS TO DA-HDR.
           MOVE YR-WS TO YR-HDR.
       B-100-PROCESS.
           READ PAYROLL-KEYED
               AT END
                   MOVE "YES" TO EOF-IND.
           PERFORM B-200-LOOP
               UNTIL IT-IS-EOF.
           PERFORM B-210-TOTAL-ROUT.
       B-200-LOOP.
           IF PAGE-NO = 1 OR LNCT > 55
               PERFORM B-300-HDR-ROUT.
           MOVE "NO " TO ERROR-IND.
           MOVE 0 TO EMP-HRS-WS.
           PERFORM B-310-EDIT-RECORD.
           IF NO-ERRORS
              ADD 1 TO NUM-VALID-TRANS
              MOVE PAY-KEYED-REC TO INFO-FROM-REC
              MOVE DATE-WS TO DATE-TRAN
              WRITE PAY-TRAN-REC
           ELSE
              ADD 1 TO NUM-INVALID-TRANS.
           READ PAYROLL-KEYED
               AT END
                   MOVE "YES" TO EOF-IND.
       B-210-TOTAL-ROUT.
           MOVE NUM-VALID-TRANS TO NUM-VALID-TRANS-TL.
           MOVE NUM-INVALID-TRANS TO NUM-INVALID-TRANS-TL.
           WRITE PRINTZ FROM TOTAL-LINE
               AFTER ADVANCING 2 LINES.
       B-300-HDR-ROUT.
           MOVE PAGE-NO TO PAGE-NO-HDR.
           WRITE PRINTZ FROM PAGE-HDR
               AFTER ADVANCING PAGE.
           WRITE PRINTZ FROM COL-HDR
               AFTER ADVANCING 2 LINES.
           MOVE SPACES TO PRINTZ.
           WRITE PRINTZ
               AFTER ADVANCING 1 LINES.
           ADD 1 TO PAGE-NO.
           MOVE 4 TO LNCT.       
       B-310-EDIT-RECORD.
           IF NOT VALID-EMP-CD
               MOVE EMP-CD TO DATA-IN-ERR-PR
               MOVE "INVALID EMP-CD - MUST BE F, P, C OR T" TO
                       ERROR-MSG-PR
               PERFORM U-100-WRITE-ERROR.
           IF ID-NO NOT NUMERIC
               MOVE RDF-ID-NO TO DATA-IN-ERR-PR
               MOVE "EMPLOYEE NUMBER NOT NUMERIC" TO ERROR-MSG-PR
               PERFORM U-100-WRITE-ERROR.
           IF WORK-HRS NOT NUMERIC
               MOVE RDF-WORK-HRS TO DATA-IN-ERR-PR
               MOVE "WORK HOURS NOT NUMERIC" TO ERROR-MSG-PR
               PERFORM U-100-WRITE-ERROR
           ELSE
               ADD WORK-HRS TO EMP-HRS-WS
               IF WORK-HRS > 40
                   MOVE WORK-HRS TO DATA-IN-ERR-PR
                   MOVE "ENTRY IN WORK HOURS EXCEEDS 40"
                     TO ERROR-MSG-PR
                   PERFORM U-100-WRITE-ERROR.
           IF OVT-HRS NOT NUMERIC
               MOVE RDF-OVT-HRS TO DATA-IN-ERR-PR
               MOVE "OVERTIME HOURS NOT NUMERIC" TO ERROR-MSG-PR
               PERFORM U-100-WRITE-ERROR
           ELSE
               ADD OVT-HRS TO EMP-HRS-WS
               IF OVT-HRS > 20
                   MOVE OVT-HRS TO DATA-IN-ERR-PR
                   MOVE "OVERTIME HOURS EXCEED 20" TO ERROR-MSG-PR
                   PERFORM U-100-WRITE-ERROR.
           IF SICK-HRS NOT NUMERIC
               MOVE RDF-SICK-HRS TO DATA-IN-ERR-PR
               MOVE "SICK HOURS NOT NUMERIC" TO ERROR-MSG-PR
               PERFORM U-100-WRITE-ERROR
           ELSE
               ADD SICK-HRS TO EMP-HRS-WS
               IF SICK-HRS > 40
                   MOVE SICK-HRS TO DATA-IN-ERR-PR
                   MOVE "SICK HOURS GREATER THAN 40" TO ERROR-MSG-PR
                   PERFORM U-100-WRITE-ERROR.
           IF VACA-HRS NOT NUMERIC
               MOVE RDF-VACA-HRS TO DATA-IN-ERR-PR
               MOVE "VACATION HOURS NOT NUMERIC" TO ERROR-MSG-PR
               PERFORM U-100-WRITE-ERROR
           ELSE
               ADD VACA-HRS TO EMP-HRS-WS
               IF VACA-HRS > 40
                   MOVE VACA-HRS TO DATA-IN-ERR-PR
                   MOVE "VACATION HOURS GREATER THAN 40" TO
                        ERROR-MSG-PR
                   PERFORM U-100-WRITE-ERROR.
           IF HOLIDAY-HRS NOT NUMERIC
                MOVE RDF-HOLIDAY-HRS TO DATA-IN-ERR-PR
                MOVE "HOLIDAY HOURS NOT NUMERIC" TO ERROR-MSG-PR
                PERFORM U-100-WRITE-ERROR
           ELSE
                ADD HOLIDAY-HRS TO EMP-HRS-WS
                IF HOLIDAY-HRS > 8
                    MOVE HOLIDAY-HRS TO DATA-IN-ERR-PR
                    MOVE "HOLIDAY HOURS GREATER THAN 8" TO
                         ERROR-MSG-PR
                    PERFORM U-100-WRITE-ERROR
                END-IF
                IF HOLIDAY-HRS = 0
                    IF HOLIDAY-CODE = " "
                        NEXT SENTENCE
                    ELSE
                        MOVE HOLIDAY-CODE TO DATA-IN-ERR-PR
                        MOVE "NO HOLIDAY HOURS" TO ERROR-MSG-PR
                        PERFORM U-100-WRITE-ERROR
                    END-IF
                ELSE
                    IF NOT VALID-HOLIDAY-CODE
                        MOVE HOLIDAY-CODE TO DATA-IN-ERR-PR
                        MOVE
                          "INVALID HOLIDAY CODE - NOT N, K, M, L, T, C"
                            TO ERROR-MSG-PR
                        PERFORM U-100-WRITE-ERROR
                    END-IF
                END-IF
           END-IF.
           IF BONUS-PAY NOT NUMERIC
               MOVE RDF-BONUS-PAY TO DATA-IN-ERR-PR
               MOVE "BONUS PAY NOT NUMERIC" TO ERROR-MSG-PR
               PERFORM U-100-WRITE-ERROR
           ELSE
               IF BONUS-PAY > 1000
                   MOVE BONUS-PAY TO RDF-DATA-IN-ERR-PR
                   MOVE "BONUS PAY OUT OF RANGE - VALID TO 1000"
                       TO ERROR-MSG-PR
                   PERFORM U-100-WRITE-ERROR.
           IF EMP-CD = "F" AND EMP-HRS-WS < 40
               MOVE EMP-HRS-WS TO DATA-IN-ERR-PR
               MOVE "HOURS WORKED LESS THAN 40" TO ERROR-MSG-PR
               PERFORM U-100-WRITE-ERROR
           ELSE
               IF EMP-HRS-WS > 80
                   MOVE EMP-HRS-WS TO DATA-IN-ERR-PR
                   MOVE "HOURS WORKED GREATER THAN 80" TO ERROR-MSG-PR
                   PERFORM U-100-WRITE-ERROR.
       C-100-WRAPUP.
           CLOSE PAYROLL-KEYED
                 PAYROLL-TRAN
                 PRINT-FILE.
       U-100-WRITE-ERROR.
           MOVE EMP-ID TO EMP-ID-PR.
           WRITE PRINTZ
               AFTER ADVANCING 1 LINES.
           ADD 1 TO LNCT.
           MOVE "YES" TO ERROR-IND.
      *
      *Input data (paykey.dat:
      *F12124010000000 050000
      *P23452400000000 000000
      *C24241000000000 010000
      *T25254008000000 000000
      *F26263200080000 000000
      *F27272400080008M000000
      *F28281640001608T000000
      *F30004525242424X000000
      *G45451212121212V800000
      *G56569045342323M000000
      *J66660000000000 000000
      *T67672020202020 000000
      *GJHGG5656565656 000000
      *UYITY1010000000 000000
      *
      *Output data to disk - good transactions (paytran.dat):
      *F12124010000000 050000990317
      *P23452400000000 000000990317
      *C24241000000000 010000990317
      *T25254008000000 000000990317
      *F26263200080000 000000990317
      *F27272400080008M000000990317
      *
      *Output data to printer - errors:
      *     03/17/99             TRANSACTION EXCEPTION REPORT                 PAGE  1
      *
      * ID #      DATA       ERROR MESSAGE
      *
      * F2828     40         OVERTIME HOURS EXCEED 20
      * F3000     45         ENTRY IN WORK HOURS EXCEEDS 40
      * F3000     25         OVERTIME HOURS EXCEED 20
      * F3000     24         HOLIDAY HOURS GREATER THAN 8
      * F3000     X          INVALID HOLIDAY CODE - NOT N, K, M, L, T, C
      * F3000     142        HOURS WORKED GREATER THAN 80
      * G4545     G          INVALID EMP-CD - MUST BE F, P, C OR T
      * G4545     12         HOLIDAY HOURS GREATER THAN 8
      * G4545     V          INVALID HOLIDAY CODE - NOT N, K, M, L, T, C
      * G4545     8000.00    BONUS PAY OUT OF RANGE - VALID TO 1000
      * G5656     G          INVALID EMP-CD - MUST BE F, P, C OR T
      * G5656     90         ENTRY IN WORK HOURS EXCEEDS 40
      * G5656     45         OVERTIME HOURS EXCEED 20
      * G5656     23         HOLIDAY HOURS GREATER THAN 8
      * G5656     215        HOURS WORKED GREATER THAN 80
      * J6666     J          INVALID EMP-CD - MUST BE F, P, C OR T
      * T6767     20         HOLIDAY HOURS GREATER THAN 8
      * T6767     100        HOURS WORKED GREATER THAN 80
      * GJHGG     G          INVALID EMP-CD - MUST BE F, P, C OR T
      * GJHGG     JHGG       EMPLOYEE NUMBER NOT NUMERIC
      * GJHGG     56         ENTRY IN WORK HOURS EXCEEDS 40
      * GJHGG     56         OVERTIME HOURS EXCEED 20
      * GJHGG     56         SICK HOURS GREATER THAN 40
      * GJHGG     56         VACATION HOURS GREATER THAN 40
      * GJHGG     56         HOLIDAY HOURS GREATER THAN 8
      * GJHGG     280        HOURS WORKED GREATER THAN 80
      * UYITY     U          INVALID EMP-CD - MUST BE F, P, C OR T
      * UYITY     YITY       EMPLOYEE NUMBER NOT NUMERIC
      *
      *NUMBER OF VALID TRANSACTIONS =   6     NUMBER OF INVALID TRANSACTIONS =   8