Key Takeaways — Chapter 33: Debugging Strategies
Core Principles
-
Debugging is systematic hypothesis testing — observe, hypothesize, test, narrow, fix, prevent. Never guess randomly.
-
S0C7 is the #1 COBOL abend — caused by non-numeric data in packed decimal fields. Common sources: uninitialized fields, group moves, corrupted file data, cross-platform interfaces.
-
Group moves do not convert — they copy bytes. Elementary moves between numeric types perform conversion. This single distinction causes more bugs than any other COBOL feature.
-
Always check return codes — file status, SQLCODE, PCB status code, CICS RESP. Processing after a failed I/O operation is the second most common source of bugs.
-
Compiler options are your allies — SSRANGE catches subscript errors, CHECK catches numeric issues, LIST/MAP/OFFSET are essential for dump analysis.
Practical Techniques
- Use debug levels controlled by runtime parameters — leave diagnostic code in production permanently.
- Bracket suspicious fields with delimiters in DISPLAY output:
DISPLAY '>' WS-FIELD '<' - Display hex values when character display looks correct but the program fails — null characters and other invisible bytes are the usual suspects.
- Read dumps systematically: abend code, offset, compiler listing, MAP, dump data. Follow the chain.
- Use CEEDUMP for formatted variable values and call stacks — dramatically faster than raw dump analysis.
- Use CEDF for CICS debugging — intercepts every EXEC CICS command.
- Test SQL separately with DSNTEP2 or SPUFI before embedding in COBOL.
Common Bug Patterns
| Bug | Symptom | Prevention |
|---|---|---|
| Uninitialized COMP-3 | S0C7 on first use | VALUE ZEROS on all numeric fields |
| Group move to numeric | S0C7 | Use elementary moves for numeric fields |
| Subscript out of range | S0C4 or data corruption | SSRANGE compiler option |
| Unchecked file status | Wrong data processed | Check status after every I/O |
| Null characters from interfaces | Wrong comparisons | INSPECT REPLACING LOW-VALUES |
| Missing END-IF | Wrong execution path | Always use scope terminators |
Connections
- Chapter 32 (Transaction Design Patterns): Transaction failures produce abends that require dump analysis
- Chapter 34 (Unit Testing): Good tests prevent many debugging scenarios
- Chapter 35 (Code Reviews): Reviews catch common bug patterns before they reach production