Ending and reentering main programs or subprograms
Whether a program is left in its last-used state or its initial state, and to which caller it returns, can depend on the termination statements that you use.
About this task
You can use any of three termination statements in a program, but they have different effects as shown in the following table.
| 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.)
In a threaded environment, the entire Language Environment enclave is terminated, including all threads running within the enclave. In a CICS® environment, the entire transaction is terminated, including all programs running within the transaction. |
Return directly to the program that called the
main program.1 (Might be the operating system, and application
will end.)
In a threaded environment, the entire Language Environment enclave is terminated, including all threads running within the enclave. In a CICS environment, the entire transaction is terminated, including all programs running within the transaction. |
GOBACK |
Return to calling program.1 (Might
be the operating system, and application will end.)
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 points for PERFORMed paragraphs
and sections are reset to their initial values. (In contrast, a main
program is initialized each time it is called.)
There are some cases in which programs will be in their initial state:
- A subprogram that is dynamically called and then canceled will be in the initial state the next time it is called.
- A program that has the
INITIALclause in thePROGRAM-IDparagraph, or is compiled with theINITIALcompiler option, will be in the initial state each time it is called. - Data items defined in the
LOCAL-STORAGE SECTIONwill be reset to the initial state specified by theirVALUEclauses each time the program is called.
Comparison of WORKING-STORAGE and LOCAL-STORAGE
Language Environment Programming Guide (What happens during termination:
thread termination)