Debugging, performance, JSON/XML and maintainable code
When a program fails, the LE messages, the CEEDUMP and the compile listing together tell you exactly which statement failed and what the data looked like. The same discipline that makes code debuggable — clear data types, small paragraphs, shared copybooks and tests — also makes it fast and safe to change.
From abend to failing statement
When a COBOL program hits a program check, LE writes a message to the job log and, depending on run-time options, a CEEDUMP. The workflow is the same every time: read the message, find the program and offset, then use the listing.
CEE3207S The system detected a data exception (System Completion Code=0C7).
From compile unit PAYCALC at entry point PAYCALC at
compile unit offset +00000A3E at entry offset +00000A3E
at address 1A40CA3E.- Note the program (compile unit) name and the offset, here PAYCALC at +A3E.
- Open the listing for exactly the version of PAYCALC that ran. A listing from another compile is useless.
- Use the LIST or OFFSET section to find the statement covering that offset.
- Look at the fields that statement uses. In the CEEDUMP, find them in the program's storage section and check their contents in hex.
- Decide whether the code or the data is wrong. For S0C7 it is usually the data.
The CEEDUMP traceback shows the chain of calls that led to the failure, which matters when the abend is in a shared subprogram: you need to know which caller passed the bad data.
Performance-minded coding
COBOL performance problems are usually about doing unnecessary work millions of times, not about clever tricks. Habits that pay off:
- Use binary (COMP or COMP-5) fields or indexes for subscripts and loop counters, not display numerics.
- Keep arithmetic in one data type. Mixing display, packed and binary forces conversions on every statement.
- Declare packed (COMP-3) fields with an odd number of digits so they fill whole bytes.
- Use
SEARCH ALL(binary search) on large sorted tables instead of a sequentialSEARCH. - Do not
INITIALIZEa large table inside a loop when only a few entries change. - Let the system choose block sizes for sequential files; tiny blocks multiply I/O.
JSON and XML in COBOL
Recent Enterprise COBOL releases can convert between COBOL data structures and JSON or XML directly, which is how many batch and CICS programs now feed APIs. Availability of each statement depends on your compiler version.
| Statement | What it does |
|---|---|
| JSON GENERATE | Builds JSON text from a group item; field names come from the data names unless renamed with NAME |
| JSON PARSE | Fills a group item from JSON text, matching names to fields |
| XML GENERATE | Builds an XML document from a group item |
| XML PARSE | Reads XML as a stream of events (start of element, content, end of element) passed to a processing procedure you write |
All of these can fail on bad input or a too-small receiving field, so code ON EXCEPTION and check the result. Code pages matter: JSON and XML exchanged with other platforms are normally Unicode, while your COBOL data is usually EBCDIC. See JSON GENERATE / JSON PARSE.
Testing and maintainability
- One paragraph, one job. Name paragraphs with a number and purpose, such as
2100-VALIDATE-ACCOUNT. - Avoid
GO TOjumping between paragraphs; structuredPERFORMandEVALUATEare easier to follow. - Use 88-levels for conditions so tests read like business rules.
- Keep interfaces in copybooks and change them deliberately, with every user recompiled.
Common mistakes
Offsets only match the exact compile that produced the running load module. Retrieve the listing for the promoted version, not your latest test compile.
A shared routine often fails because a caller passed bad data. Read the traceback to find who called it before changing shared code.
Text that looks fine on z/OS can be garbled elsewhere. Agree the encoding with the other side and check that conversion happens exactly once.
What you will see at work
- First-line support collects the job log, CEEDUMP and listing before paging a developer, so the developer can go straight to the failing statement.
- Performance reviews look at CPU per transaction or per record; changing subscript types or table searches can make a visible difference.
- Teams modernising to APIs use JSON GENERATE and PARSE to put existing COBOL logic behind REST services without rewriting it.
Key terms
Check your understanding.
Take this lesson's quiz and save your progress. Free.