unloadOnExit

The unloadOnExit property specifies whether to unload a called program after it ends. The valid values are YES or NO.
The following restrictions apply to the unloadOnExit property:
When you set the unloadOnExit property to NO, you get the following results:
When you set the unloadOnExit property to YES:

Unloading a program does not automatically unload other programs called by that program. Each program is unloaded or retained individually.

Retained programs are kept until they are unloaded after a subsequent call, or until the run unit ends. A transfer to transaction statement ends the run unit, and therefore overrides the value of the unloadOnExit property. Retained programs are kept after a transfer to program statement.

The following elements are shared by all programs in a run unit and are therefore not affected when a called program is unloaded:

DL/I programs have one scheduled PSB active at a time. This PSB is shared by any number of programs. Unloading a called program does not affect the PSB. It is still scheduled.

The forms that a program uses are considered to be global data. They are retained when a called program is retained and discarded when it is unloaded.

Unloading does not imply a commit or rollback.

Recursive program calls

COBOL does not support recursive program calls.

Java supports recursive local calls except in situations like the one in the following example:
  1. ProgramA calls ProgramB, directly or indirectly.
  2. ProgramB returns and is retained.
  3. ProgramA calls ProgramB again.
  4. ProgramB calls itself, directly or indirectly.

In this example, the final call statement causes an InvocationException to be thrown. Therefore, after a locally called Java program returns and is retained, only one copy of the program can be active at a time, although it can be unloaded later.

Values

The unloadOnExit property has the following values:
YES
Release all memory for the program, including SQL result sets. This value is the default for Java generation. For debugging, set the Called programs release resources by default upon return preference; see Setting preferences for the EGL debugger.
NO
Keep the called program in memory, along with SQL result sets and all other variables. This value is the default for COBOL generation.

Example

In the following example, the program will be retained in memory after it returns control to the program that called it, unless it encounters an unrecoverable error:

Program custProcess1 type basicProgram (custNum INT) {unloadOnExit = NO}

  ...

  if(myErrorCode == TERM_ERROR)
    exit program {unloadOnExit = YES};
  end
end

Feedback