Master Mainframe Technologies - COBOL, JCL, DB2, VSAM, CICS & More
ABEND Codes SQLCODEs File Status Interview Prep Contact
← Back to Debugging
Debugging | Intermediate | COBOL

Fix Truncation Error

Problem Description

Why does this show 0 instead of 150?
01 WS-A PIC 99 VALUE 15.
01 WS-B PIC 99 VALUE 10.
01 WS-C PIC 99.
MULTIPLY WS-A BY WS-B GIVING WS-C.

Expected Output

Should display 150

Hints

Check if the result field is large enough.

Solution

IDENTIFICATION DIVISION. PROGRAM-ID. FIXTRUNC. DATA DIVISION. WORKING-STORAGE SECTION. 01 WS-A PIC 99 VALUE 15. 01 WS-B PIC 99 VALUE 10. * FIXED: Increased size to hold result 01 WS-C PIC 9(4). PROCEDURE DIVISION. MULTIPLY WS-A BY WS-B GIVING WS-C. DISPLAY "RESULT: " WS-C. STOP RUN.

Explanation:

BUG: PIC 99 only holds 0-99. 15*10=150 is truncated. FIX: Use larger PIC.