diff --git a/COBOL Programming Course #3 - Advanced Topics/Challenges/Debugging/cbl/CBL0106C.cbl b/COBOL Programming Course #3 - Advanced Topics/Challenges/Debugging/cbl/CBL0106C.cbl index 6fc400ee..776f4107 100644 --- a/COBOL Programming Course #3 - Advanced Topics/Challenges/Debugging/cbl/CBL0106C.cbl +++ b/COBOL Programming Course #3 - Advanced Topics/Challenges/Debugging/cbl/CBL0106C.cbl @@ -44,9 +44,10 @@ * WORKING-STORAGE SECTION. 01 Filler. - 05 LASTREC PIC X VALUE SPACE. + 05 LASTREC PIC X VALUE SPACE. 05 DISP-SUB1 PIC 9999. 05 SUB1 PIC 99. + 05 OVERLIMIT-MAX PIC S9(4) COMP VALUE 20. 01 OVERLIMIT. 03 FILLER OCCURS 20 TIMES. @@ -136,7 +137,7 @@ WRITE PRINT-REC FROM HEADER-3. WRITE PRINT-REC FROM HEADER-4. MOVE SPACES TO PRINT-REC. - MOVE 1 TO SUB1. + MOVE 0 TO SUB1. * READ-NEXT-RECORD. PERFORM READ-RECORD @@ -162,11 +163,19 @@ * IS-OVERLIMIT. IF ACCT-LIMIT < ACCT-BALANCE THEN + ADD 1 TO SUB1 + * Check if there is enough space in the array, in case the input + * file changes again. A handled error is easier to find and fix + * than a buffer overwrite error. + IF SUB1 > OVERLIMIT-MAX THEN + DISPLAY 'OVERFLOW TABLE OVERLIMIT' + MOVE 1000 TO RETURN-CODE + STOP RUN + END-IF MOVE ACCT-LIMIT TO OL-ACCT-LIMIT(SUB1) MOVE ACCT-BALANCE TO OL-ACCT-BALANCE(SUB1) MOVE LAST-NAME TO OL-LASTNAME(SUB1) MOVE FIRST-NAME TO OL-FIRSTNAME(SUB1) - ADD 1 TO SUB1 END-IF. * IS-STATE-VIRGINIA. @@ -175,7 +184,7 @@ END-IF. * WRITE-OVERLIMIT. - IF SUB1 = 1 THEN + IF SUB1 = 0 THEN MOVE OVERLIMIT-STATUS TO PRINT-REC WRITE PRINT-REC ELSE