Program control is how execution moves from one part of the program to another and how the program (or run unit) ends. The main tools are PERFORM (call a paragraph and return), GOBACK, STOP RUN, and EXIT PROGRAM. This page explains what each does and when to use it. For the order in which statements run, see Program flow.
| Statement | Effect |
|---|---|
| PERFORM paragraph/section | Call the paragraph/section; when it ends, return to the next statement |
| GOBACK | In main program: end run. In called program: return to caller |
| STOP RUN | End the entire run unit and return to the operating system |
| EXIT PROGRAM | In a called program: return to the caller (no effect in main program) |
| GO TO | Jump to a paragraph/section (avoid for clear, maintainable flow) |
PERFORM paragraph-name (or PERFORM section-name) runs that paragraph or section. When it finishes (reaches the next paragraph/section name or the end of an in-line block), control returns to the statement after the PERFORM. So the main flow “calls” the paragraph and then continues. PERFORM is the normal way to structure reusable logic without losing your place.
12345678910111213141516171819PROCEDURE DIVISION. MAIN. PERFORM INIT-WORK PERFORM PROCESS-ONE PERFORM CLEANUP GOBACK. INIT-WORK. MOVE ZEROS TO WS-COUNTER *> Control returns to PERFORM PROCESS-ONE . PROCESS-ONE. *> Do work . CLEANUP. CLOSE INFILE OUTFILE .
Execution order: MAIN runs, then INIT-WORK (and returns), then PROCESS-ONE (and returns), then CLEANUP, then GOBACK. So program control is “where we go next”; PERFORM keeps that predictable by always returning.
GOBACK means “exit this program.” In a main program (the one that was run by the job or CICS), GOBACK ends execution and returns to the operating system or CICS. In a called program (invoked by CALL or INVOKE), GOBACK returns control to the caller; the run unit continues.
STOP RUN always ends the entire run unit: the main program and all programs it called. Control goes back to the OS. Use STOP RUN when the whole job or transaction is done. In a subprogram, use GOBACK or EXIT PROGRAM so that only the subprogram exits and the caller continues.
1234567891011121314*> Main program PROCEDURE DIVISION. MAIN. CALL "SUB-PGM" USING WS-AREA *> Control returns here after SUB-PGM does GOBACK or EXIT PROGRAM GOBACK. *> Or: STOP RUN. (ends run unit) *> Called program (SUB-PGM) PROCEDURE DIVISION USING WS-AREA. SUB-MAIN. *> Do work EXIT PROGRAM. *> Or: GOBACK. (same effect: return to caller)
EXIT PROGRAM is used in a program that was called by another. It returns control to the caller. In a main program (not called by anyone), EXIT PROGRAM has no effect. Prefer GOBACK in subprograms when your compiler supports it; GOBACK works in both main and called programs and reads clearly as “exit this program.”
GO TO paragraph-name sends control to that paragraph and does not return. Overuse makes flow hard to follow (“spaghetti code”). It is still used in some legacy code and for simple one-way jumps (e.g. error exit). Prefer PERFORM for normal structure and IF/EVALUATE for branching.
1. In a called program, what should you use to return to the caller?
2. After PERFORM SOME-PARA runs, where does control go?