Result is wrong:
01 WS-A PIC 9(3) VALUE 999.
01 WS-B PIC 9(3) VALUE 999.
01 WS-C PIC 9(3).
ADD WS-A TO WS-B GIVING WS-C.
Fix Truncation Error
Problem Description
Expected Output
Should show 1998, shows 998
Hints
Result field is too small for the sum.
Solution
IDENTIFICATION DIVISION.
PROGRAM-ID. FIXTRUNC.
DATA DIVISION.
WORKING-STORAGE SECTION.
01 WS-A PIC 9(3) VALUE 999.
01 WS-B PIC 9(3) VALUE 999.
* BUG: WS-C can only hold 999 max
* FIX: Make result field larger
01 WS-C PIC 9(4).
PROCEDURE DIVISION.
ADD WS-A TO WS-B GIVING WS-C.
DISPLAY "999 + 999 = " WS-C.
STOP RUN.
Explanation:
Result field must be large enough. 9(3) holds max 999, need 9(4) for 1998.