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.
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. |
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. |
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 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 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
INITIAL
clause in thePROGRAM-ID
paragraph will be in the initial state each time it is called. - Data items defined in the
LOCAL-STORAGE SECTION
will be reset to the initial state specified by theirVALUE
clauses each time the program is called.
Comparison of WORKING-STORAGE and LOCAL-STORAGE
Language Environment Programming Guide (What happens during termination:
thread termination)