cobol – How do I fix validation in different methods?

This program is to read in the SEQ file and take the data thru different validations, if it fails to comply with one of the validations the error message is moved to FIELD-NAME and FIELD-VALUE is the errored field.

After all data is processed all transaction are to be used to create the RPT file.

PROBLEM: When reviewing the RPT file, the current issue is in the 300’s (300, 310, 320, 330, 340, 350) section. I believe the problem is that my validation is not working properly. Validation requirements are lists below:

  • Part number validation requirements Col. 01-05 must be a number, col 06 must be a capital, 07-08 must be a number in the range 01-68 or 78-99 (300-VALIDATE-PART-NUMBER)

  • Quantity validation requirements Leading spaces are allowed(can be all spaces), if not all spaces must be a number after leading spaces, zero value is allowed, value over 20,000 is an error (310-VALIDATE-QUANTITY)

  • Date validation requirements month value must be 01-12, day value must be 01-31 (320-VALIDATE-DATE)

  • Charge Number validation requirements cannot be blank, must be left justified(no leading spaces), and no more than one dash (hyphen) allowed (330-VALIDATE-CHARGE-NUMBER)

  • Initial validation requirements both must be letters (upper or lower case OK) (340-VALIDATE-INITIALS)

  • Transaction Code validation requirements must be REC, ISS, AJ+, or AJ- (350-VALIDATE-TRANSACTION-CODE)

RELATED ISSUE: Currently if an issue is found it moves onto the next line of data. The problem code is suppose to keep processing until all errors are written to record see PART NO 2074B01 for reference.

If you run my attached program with the attached SEQ, your RPT will look like mine.

Below is the desired output. (pg 1)

SEQ:

11438A01  5000102667-X44   JBISS
12345A77   120103OK BY MIKELLREC
12789B02 14460606144-X22A    AJ+
13168A02    31231722394    mkISS
13168A02    70102221-Q18   JBAJ-
 2074B01  25 0532 OK BY JIMK RE
22109A04 20000325669-Y5Z   DCISS
3077.B22  1000801144X      MWAJ-
32149A01    10625567-X1    dcREC
39886B02  2000203517-AA    JBAJ+
40442A2(   33    333-Q67   MKISS
43009B01  1440801899-23    MKISS
47890A02 30000422X-4-8     DCISS
49000B01  1000831901-Y6    MWAJ+
51111A011052X0905901-Y66   JBREC
52301A02    10228733876-X1 ABREC
55986b01 99990430A         DCISS
57989A01    21130144X      JBAJ+
57989A01   500831722394-XX MKISS
59901B0220300133X966-QQ22  MWREC
60022A01   400823 517-X1-33MWAJ+
66780B01  1000831722-YY    BwREC
68999A01    21028123-Q88   MKISS
75312B01   500222966-32     BISS
77771A03 12780606          ABISS
78896B02  1000831123456-X13DCREC
80090B01   881$25983334-X25jbAJ
82432A05   420912722-X9    MWISS
83058C04 65000325Q1234     K*AJ+
85987D02  1061214Charge #32KBAJ-
87167B01  7000930144XX     DCAJ+
91986 01   25072 900-23    MWISS
9576XA00  1001122j55       kbREC
96134B05    60214GOOD      BSAJ-
98407C03254*00416Confirmed EHISS

Code:

       IDENTIFICATION DIVISION.
       PROGRAM-ID. INVTRAN.
      * Tate
      ***************************************************************
      * This program reads a fie of inventory transaction,
      * validates the data, prints a report showing all transactions
      * (with errors indicated), and writes a data file of
      * all transactions without errors.
      ***************************************************************
       ENVIRONMENT DIVISION.
       INPUT-OUTPUT SECTION.
       FILE-CONTROL.
       
           SELECT INVENTORY-TRANS-FILE-IN
               ASSIGN TO 'INVTRAN.SEQ'
               ORGANIZATION IS LINE SEQUENTIAL.
               
      *    SELECT INVENTORY-TRANS-FILE-OUT
      *        ASSIGN TO 'INVTRAN.OUT'
      *        ORGANIZATION IS LINE SEQUENTIAL.
               
           SELECT INVENTORY-TRANS-FILE-OUT-2
               ASSIGN TO 'INVTRAN.RPT'
               ORGANIZATION IS LINE SEQUENTIAL.
               
       DATA DIVISION.
       FILE SECTION.
       
       FD INVENTORY-TRANS-FILE-IN.
       01 INVENTORY-TRANS-RECORD-IN.
           05 PART-NUMBER-IN.
               10 PART-NUMERIC-1-IN    PIC X(5).
               10 PART-ALPHABETIC-IN   PIC X.
               10 PART-NUMERIC-2-IN    PIC XX.
                   88 VALID-PART-NUMERIC-2 VALUE '01' THRU '68' '78' THRU '99'.
           05 QUANTITY-IN.
               10 QUANTITY-9-IN        PIC 9(5).
           05 DATE-IN.
               10 MONTH-IN             PIC XX.
                   88 VALID-MONTH-IN  VALUE '01' THRU '12'.
               10 DAY-IN               PIC XX.
                   88 VALID-DAY-IN    VALUE '01' THRU '31'.
           05 CHARGE-NUMBER-IN         PIC X(10).
           05 INITIALS-IN.
               10 INITIALS-1-IN        PIC X.
               10 INITIALS-2-IN        PIC X.
           05 TRANS-CODE-IN            PIC X(3).
               88 VALID-TRANS-CODE-IN VALUE 'REC' 'ISS' 'AJ+' 'AJ-'.
       
       FD INVENTORY-TRANS-FILE-OUT-2.
       01 INVENTORY-TRANS-RECORD-OUT-2 PIC X(80).
       
       WORKING-STORAGE SECTION.
       01 WS-FIRST-TIME-THRU           PIC X(3)    VALUE 'YES'.
       01 WS-BLANK-LINE                PIC X(80)   VALUE SPACES.
       01 LINES-PRINTED                PIC 99      VALUE 99.
       01 PAGE-NUMBER                  PIC 99      VALUE ZERO.
       01 RECORDS-ERROR-SWITCH         PIC X(3).
       01 FIELD-ERROR-SWITCH           PIC X(3).
       01 WS-TOTAL                     PIC 99      VALUE ZERO.
       01 WS-ERROR                     PIC 99      VALUE ZERO.
       01 WS-GOOD                      PIC 99      VALUE ZERO.
       01 WS-QUANTITY                  PIC 9(4)    VALUE ZERO.
       01 TOTAL-ERROR-COUNT            PIC 9(3)    VALUE ZERO.
       01 TOTAL-GOOD-COUNT             PIC 9(3)    VALUE ZERO.
       01 TOTAL-GOOD-QUANTITY          PIC 9(5)    VALUE ZERO.
       
       01 WS-CURRENT-DATE-DATA.
           05 WS-CURRENT-DATE.
               10 RUN-YEAR             PIC XX.
               10 RUN-MONTH            PIC XX.
               10 RUN-DAY              PIC XX.
       
       01 HEADING-LINE-1.
           05                          PIC X(17)   VALUE SPACES.
           05                          PIC X(35)   VALUE 'INVENTORY TRANSACTIONS AUDIT TRAIL'.
           05                          PIC X(8)    VALUE SPACES.
           05 HL-1-DATE.
               10 MONTH-1              PIC XX.
               10                      PIC X       VALUE '/'.
               10 DAY-1                PIC XX.
               10                      PIC X       VALUE '/'.
               10 YEAR-1               PIC XX.
           05                          PIC X(3)    VALUE SPACES.
           05                          PIC X(5)    VALUE 'PAGE'.
           05 HL-1-PAGE-NUMBER         PIC Z9.
           
       01 HEADING-LINE-2.
           05                          PIC X(10)   VALUE 'PART NO'.
           05                          PIC X(5)    VALUE 'QUAN'.
           05                          PIC X(5)    VALUE 'DATE'.
           05                          PIC X(11)   VALUE 'CHARGE NO'.
           05                          PIC X(3)    VALUE 'IN'.
           05                          PIC X(4)    VALUE 'TRN'.
           05                          PIC X(3)    VALUE SPACES.
           05                          PIC X(20)   VALUE 'ERROR FIELD NAME'.
           05                          PIC X(17)   VALUE 'ERROR FIELD VALUE'.
       01 DETAIL-LINE.
           05 PART-NUMBER              PIC X(8).
           05                          PIC X       VALUE SPACE.
           05 QUANTITY                 PIC X(5).
           05                          PIC X       VALUE SPACE.
           05 DATE-X                   PIC X(4).
           05                          PIC X       VALUE SPACE.
           05 CHARGE-NUMBER            PIC X(10).
           05                          PIC X       VALUE SPACE.
           05 INITIALS                 PIC XX.
           05                          PIC X       VALUE SPACE.
           05 TRANS-CODE               PIC X(3).
           05                          PIC X(4)    VALUE SPACES.
           05 FIELD-NAME               PIC X(18).
           05                          PIC XX      VALUE SPACES.
           05 FIELD-VALUE              PIC X(10).
           
       01 TRANSACTIONS.
           05                          PIC X(41)   VALUE 'Total Transactions:'.
           05 T-1                      PIC 99.
           
       01 ERROR-TRANSACTIONS.
           05                          PIC X(41)   VALUE 'Total Error Transactions:'.
           05 T-2                      PIC 99.
           
       01 GOOD-TRANSACTIONS.
           05                          PIC X(41)   VALUE 'Total Good Transactions:'.
           05 T-3                      PIC 99.
           
       01 QUANTITY-TOTAL.
           05                          PIC X(41)   VALUE 'Good Transactions Quantity Total:'.
           05 Q-4                      PIC 9,999.
           
       PROCEDURE DIVISION.
       100-MAIN.
           OPEN INPUT INVENTORY-TRANS-FILE-IN
           OPEN OUTPUT INVENTORY-TRANS-FILE-OUT-2
           
           ACCEPT WS-CURRENT-DATE FROM DATE
           MOVE RUN-MONTH TO MONTH-1
           MOVE RUN-DAY TO DAY-1
           MOVE RUN-YEAR TO YEAR-1
           PERFORM 150-WRITE-HEADINGS
           
           PERFORM UNTIL RECORDS-ERROR-SWITCH = 'YES'
               READ INVENTORY-TRANS-FILE-IN
                   AT END
                       PERFORM 500-TRANSACTIONS
                       PERFORM 510-ERROR-TRANSACTIONS
                       PERFORM 520-GOOD-TRANSACTIONS
                       PERFORM 530-QUANTITY
                       MOVE 'YES' TO RECORDS-ERROR-SWITCH
                   NOT AT END
                       PERFORM 200-PROCESS-ONE-RECORD
              END-READ
          END-PERFORM
          
          CLOSE INVENTORY-TRANS-FILE-IN
          CLOSE INVENTORY-TRANS-FILE-OUT-2
          STOP RUN.
       
       150-WRITE-HEADINGS.
           ADD 1 TO PAGE-NUMBER
           MOVE PAGE-NUMBER TO HL-1-PAGE-NUMBER
           MOVE HEADING-LINE-1 TO INVENTORY-TRANS-RECORD-OUT-2
           
           IF WS-FIRST-TIME-THRU = 'YES'
               WRITE INVENTORY-TRANS-RECORD-OUT-2
               MOVE WS-BLANK-LINE TO INVENTORY-TRANS-RECORD-OUT-2
               WRITE INVENTORY-TRANS-RECORD-OUT-2
               MOVE 'NO' TO WS-FIRST-TIME-THRU
           ELSE
               WRITE INVENTORY-TRANS-RECORD-OUT-2 AFTER ADVANCING PAGE
               MOVE WS-BLANK-LINE TO INVENTORY-TRANS-RECORD-OUT-2
               WRITE INVENTORY-TRANS-RECORD-OUT-2
           END-IF
           
           MOVE HEADING-LINE-2 TO INVENTORY-TRANS-RECORD-OUT-2
           WRITE INVENTORY-TRANS-RECORD-OUT-2
           MOVE WS-BLANK-LINE TO INVENTORY-TRANS-RECORD-OUT-2
               WRITE INVENTORY-TRANS-RECORD-OUT-2
           MOVE 1 TO LINES-PRINTED.
       
       200-PROCESS-ONE-RECORD.
           IF LINES-PRINTED > 54
               PERFORM 150-WRITE-HEADINGS
           END-IF
           
           MOVE 'NO' TO RECORDS-ERROR-SWITCH
           PERFORM 300-VALIDATE-PART-NUMBER
           PERFORM 310-VALIDATE-QUANTITY
           PERFORM 320-VALIDATE-DATE
           PERFORM 330-VALIDATE-CHARGE-NUMBER
           PERFORM 340-VALIDATE-INITIALS
           PERFORM 350-VALIDATE-TRANSACTION-CODE
           
           MOVE PART-NUMBER-IN TO PART-NUMBER
           MOVE QUANTITY-IN TO QUANTITY
           MOVE DATE-IN TO DATE-X
           MOVE CHARGE-NUMBER-IN TO CHARGE-NUMBER
           MOVE INITIALS-IN TO INITIALS
           MOVE TRANS-CODE-IN TO TRANS-CODE
           
           
           IF RECORDS-ERROR-SWITCH = 'NO'
               ADD 1 TO TOTAL-GOOD-COUNT
               ADD 1 TO TOTAL-GOOD-QUANTITY
               MOVE DETAIL-LINE TO INVENTORY-TRANS-RECORD-OUT-2
               WRITE INVENTORY-TRANS-RECORD-OUT-2
               MOVE WS-BLANK-LINE TO INVENTORY-TRANS-RECORD-OUT-2
               WRITE INVENTORY-TRANS-RECORD-OUT-2
               MOVE SPACES TO FIELD-NAME
               MOVE SPACES TO FIELD-VALUE
           ELSE
               ADD 1 TO TOTAL-ERROR-COUNT
           END-IF.
        
       300-VALIDATE-PART-NUMBER.
           IF PART-NUMERIC-1-IN NOT NUMERIC
               MOVE 'Part Number' TO FIELD-NAME
               MOVE PART-NUMBER-IN TO FIELD-VALUE
           END-IF
           IF PART-ALPHABETIC-IN NOT ALPHABETIC
               MOVE 'Part Number' TO FIELD-NAME
               MOVE PART-NUMBER-IN TO FIELD-VALUE
           END-IF
           IF NOT VALID-PART-NUMERIC-2
               MOVE 'Part Number' TO FIELD-NAME
               MOVE PART-NUMBER-IN TO FIELD-VALUE
           END-IF.
           
       310-VALIDATE-QUANTITY.
           IF QUANTITY-9-IN IS GREATER THAN 20000
               MOVE 'Quantity' TO FIELD-NAME
               MOVE QUANTITY-9-IN TO FIELD-VALUE
           END-IF.
           IF QUANTITY-IN IS EQUAL TO '254*0'
               MOVE 'Quantity' TO FIELD-NAME
               MOVE QUANTITY-IN TO FIELD-VALUE
           END-IF.
       
       320-VALIDATE-DATE.
           IF NOT VALID-MONTH-IN
               MOVE 'Date' TO FIELD-NAME
               MOVE DATE-IN TO FIELD-VALUE
           ELSE
               IF NOT VALID-DAY-IN
                   MOVE 'Date' TO FIELD-NAME
                   MOVE DATE-IN TO FIELD-VALUE
               END-IF
           END-IF.
       
       330-VALIDATE-CHARGE-NUMBER.
           IF CHARGE-NUMBER-IN IS EQUAL TO ' '
               MOVE 'Charge Number' TO FIELD-NAME
               MOVE CHARGE-NUMBER-IN TO FIELD-VALUE
           END-IF.
       
       340-VALIDATE-INITIALS.
           IF ((INITIALS-1-IN IS EQUAL TO ' ') OR (INITIALS-2-IN IS EQUAL TO ' '))
               MOVE 'Initials' TO FIELD-NAME
               MOVE INITIALS-IN TO FIELD-VALUE
           END-IF.
       
       350-VALIDATE-TRANSACTION-CODE.
           IF NOT VALID-TRANS-CODE-IN
               MOVE 'Transaction Code' TO FIELD-NAME
               MOVE TRANS-CODE-IN TO FIELD-VALUE
           END-IF.
           
       500-TRANSACTIONS.
       MOVE WS-TOTAL TO TRANSACTIONS
       MOVE T-1 TO INVENTORY-TRANS-RECORD-OUT-2
       WRITE INVENTORY-TRANS-RECORD-OUT-2 AFTER ADVANCING 2 LINES.
       
       510-ERROR-TRANSACTIONS.
       MOVE WS-ERROR TO ERROR-TRANSACTIONS
       MOVE T-2 TO INVENTORY-TRANS-RECORD-OUT-2
       WRITE INVENTORY-TRANS-RECORD-OUT-2 AFTER ADVANCING 2 LINES.
       
       520-GOOD-TRANSACTIONS.
       MOVE WS-GOOD TO GOOD-TRANSACTIONS
       MOVE T-3 TO INVENTORY-TRANS-RECORD-OUT-2
       WRITE INVENTORY-TRANS-RECORD-OUT-2 AFTER ADVANCING 2 LINES.
       
       530-QUANTITY.
       MOVE WS-QUANTITY TO QUANTITY-TOTAL
       MOVE Q-4 TO INVENTORY-TRANS-RECORD-OUT-2
       WRITE INVENTORY-TRANS-RECORD-OUT-2 AFTER ADVANCING 2 LINES.

Please ask questions if you need more clarification.

Thank you.