Whether a program is left in its last-used state or its initial state, and to what caller it returns, can depend on the termination statements that you use.
You can use any of three termination statements in a program, but they have different effects, as shown in the table below.
| Termination statement | Main program | Subprogram |
|---|---|---|
| EXIT PROGRAM | No action taken | Return to calling program
without ending the run unit.
An implicit EXIT PROGRAM statement is generated if the called program
has no next executable statement.
In a threaded environment, the thread is not terminated unless the program is the first (oldest) one in the thread. |
| STOP RUN | Return to calling
program.1 (Might be the operating system, and application will
end.)
STOP RUN terminates the run unit, and deletes all dynamically called programs in the run unit and all programs link-edited with them. (It does not delete the main program.) In a threaded environment, the entire Language Environment enclave is terminated, including all threads running within the enclave. |
Return directly to the
program that called the main program.1
(Might be the operating system, and application will
end.)
STOP RUN terminates the run unit, and deletes all dynamically called programs in the run unit and all programs link-edited with them. (It does not delete the main program.) In a threaded environment, the entire Language Environment enclave is terminated, including all threads running within the enclave. |
| GOBACK | Return to calling
program.1 (Might be the operating system, and application will
end.)
GOBACK terminates the run unit, and deletes all dynamically called programs in the run unit and all programs link-edited with them. (It does not delete the main program.) In a threaded environment, the thread is terminated.2 |
Return to calling
program.
In a threaded environment, if the program is the first program in a thread, the thread is terminated.2 |
|
||
A subprogram is usually left in its last-used state when it terminates with EXIT PROGRAM or GOBACK. The next time the subprogram is called in the run unit, its internal values are as they were left, except that return values for PERFORM statements are reset to their initial values. (In contrast, a main program is initialized each time it is called.)
There are some cases where programs will be in their initial state:
related concepts
Comparison of WORKING-STORAGE and LOCAL-STORAGE
Language Environment Programming Guide (Language Environment termination:
thread termination)
related tasks
Calling nested COBOL programs
Making recursive calls