IGZ0037S: Flow of control went past the last line
IGZ0037S means a COBOL program kept running until it passed the last statement in its Procedure Division without reaching STOP RUN, GOBACK or another statement that ends it. The runtime stops the program, and the step usually ends with abend U4038.
Other names for this code
Also written as IGZ0037, IGZ037S, IGZ0037S U4038, flow of control proceeded beyond the last line, COBOL no GOBACK, COBOL missing STOP RUN.
What it means
COBOL runs paragraphs in the order they appear unless a statement sends control somewhere else. A program is expected to end itself with STOP RUN or GOBACK, or EXIT PROGRAM in a called program. If execution finishes the last statement in the program and none of those has run, there is nowhere left to go. The COBOL runtime then writes IGZ0037S, names the program, and ends it.
The message comes with a line that gives the compile unit, the entry point and the offset. That offset is near the end of the program's code, because that is where control ran out.
The S suffix marks a severe error. Under Language Environment the step usually ends with U4038.
You see this mostly in main programs, the ones started by EXEC PGM=. The COBOL rules give a called program an implicit EXIT PROGRAM when it runs out of statements, so it returns to its caller instead. A main program has no such safety net.
IBM COBOL on AIX and Windows reports the same situation with message IWZ037I.
Common causes
- The main paragraph performs the other paragraphs but has no GOBACK or STOP RUN at its end, so control falls through every paragraph below it and off the end.
- The GOBACK is inside an IF, and a misplaced period or a missing END-IF means it only runs on some paths.
- STOP RUN was typed as STOP-RUN. On a line of its own that compiles as a paragraph name, so the program never stops.
- The program uses EXIT PROGRAM to end, but it was started as a main program. EXIT PROGRAM does nothing in a main program, so execution carries on.
- A GO TO jumps into the last paragraph, which was written to be performed and has no way out once reached by GO TO.
- A copy-and-paste error leaves a PERFORM pointing at the wrong paragraph or range, so the flow takes a path nobody intended.
How to find the problem
- Find IGZ0037S in the step's SYSOUT. It names the program that ran off the end.
- Look at the last few statements in the Procedure Division of that program in the compile listing. The offset in the message should point there.
- Trace the main line from the top. Check that every path ends in GOBACK or STOP RUN, and check where each period falls in IF statements.
- If the failure only happens on some runs, find which input took the program down the path without an ending statement.
How to fix it
- Put a GOBACK as the last statement of the main paragraph, after the PERFORMs, so control never reaches the paragraphs below by falling through.
- Use GOBACK rather than EXIT PROGRAM or STOP RUN. GOBACK works the same whether the program is run as a main program or called.
- Replace period-delimited IF logic with explicit END-IF scope terminators so a stray period can't move the ending statement out of its path.
- Fix the spelling of STOP RUN if it was typed with a hyphen, and recompile.
- Remove GO TO jumps into paragraphs that are meant to be performed.
What it looks like
IGZ0037S The flow of control in program PAYEDIT proceeded beyond the last line of the program.
From compile unit PAYEDIT at entry point PAYEDIT at compile unit offset +000002E8 at entry offset +000002E8 at address 1A6002E8.
IEF450I PAYRUN01 STEP010 - ABEND=S000 U4038 REASON=00000001IBM documentation
IBM z/OS documentation. Use the documentation for your installed release.
This link opens the relevant IBM reference library or lookup instructions. Match the complete code and your installed product release; it is not a code-specific review.
Related codes
Questions
Why did the program work for years and then get IGZ0037S?
The path without an ending statement usually depends on the data. A new kind of record or a changed IF sent the flow down a path that falls off the end of the program.
Should I use STOP RUN or GOBACK?
GOBACK is the safer choice. It ends a main program and returns from a called one, while STOP RUN in a called program ends the whole run unit.
What is IWZ037I?
It is the same condition reported by IBM COBOL on AIX and Windows. The fix is the same.