COBOL Troubleshooting
S0C7 data exception during numeric calculation
S0C7 is a data exception: the program tried arithmetic on a field that does not contain valid numeric data. It is the most common COBOL abend in production.
What it means
- S0C7 (data exception) fires when a packed-decimal, zoned-decimal or binary field holds bytes that are not valid digits.
- It almost always happens on COMPUTE, ADD, SUBTRACT, MULTIPLY, DIVIDE or a numeric comparison.
- The classic trigger is an alphanumeric value moved into a numeric field, or a numeric field that was never initialized.
Common causes
- Alphanumeric data (spaces, letters) moved into a PIC 9 / COMP-3 field.
- Working-storage numeric field never given a VALUE and never set before use.
- Packed-decimal sign nibble corrupted (must be C, D or F) by a bad MOVE or overlay.
- Input record layout does not match the FD — the program reads text where it expects digits.
- REDEFINES overlaying a group item with a numeric field, picking up non-numeric bytes.
How to diagnose
- Get the SYSUDUMP or SYSABEND and find the failing PSW address; match it to the statement offset in the compiler listing.
- Display the field in hex at abend time — look for non-digit nibbles or a bad sign nibble.
- Check where the field gets its value: file read, parameter, or computation upstream.
- Reproduce with the same input file; bad data usually comes from one specific record.
How to fix it
- Add an IS NUMERIC test before every arithmetic operation on data from files or screens.
- Initialize numeric fields (VALUE ZEROS) and validate input records on the way in.
- Fix the sending field or the record layout so digits arrive where digits are expected.
- For packed fields, verify the sign nibble with a hex display after the fix.
Example: Guard arithmetic with IS NUMERIC
IF WS-AMOUNT-RAW IS NUMERIC
COMPUTE WS-TOTAL = WS-TOTAL + WS-AMOUNT-RAW
ELSE
ADD 1 TO WS-REJECT-COUNT
*> write the bad record to a reject file, do not abend
END-IF.
One IS NUMERIC test prevents the most common production S0C7.
Interview tip
- Q: How would you troubleshoot a S0C7 data exception during numeric calculation in production?
- A: I would take the dump, locate the failing statement offset in the compiler listing, display the field in hex to see the bad nibbles, trace where the field got its value, then add IS NUMERIC validation and fix the data source.
Prevention checklist
- Validate every numeric field that comes from a file, screen or parameter with IS NUMERIC.
- Give numeric working-storage fields VALUE ZEROS.
- Add a reject path for bad records instead of letting the job abend.
