This code causes S0C7 (data exception). Find the bug:
01 WS-NUM PIC 9(5).
MOVE SPACES TO WS-NUM.
ADD 1 TO WS-NUM.
Fix the S0C7 ABEND
Problem Description
Expected Output
Should add 1 without ABEND
Hints
S0C7 occurs when non-numeric data is used in arithmetic.
Solution
IDENTIFICATION DIVISION.
PROGRAM-ID. FIXS0C7.
DATA DIVISION.
WORKING-STORAGE SECTION.
01 WS-NUM PIC 9(5).
PROCEDURE DIVISION.
* BUG: Moving SPACES to numeric field causes S0C7 on ADD
* FIX: Initialize numeric fields with ZEROS, not SPACES
MOVE ZEROS TO WS-NUM.
ADD 1 TO WS-NUM.
DISPLAY "RESULT: " WS-NUM.
STOP RUN.
Explanation:
S0C7 ABEND: Numeric field contained spaces. Always use ZEROS for numeric initialization.