COBOL Manual for TNS/E Programs (H06.08+, J06.03+)

The control mechanisms for all PERFORM statements in the program are set to their initial state
(inactive).
GO TO statements whose destinations can be modified by ALTER statements are restored to
the forms specified in the source program.
A program is placed in its initial state at these times:
The first time the program is executed in a run unit. For a main program, this is at the beginning
of each separate execution of the run unit. For a called program, this is the first time it is called
by a CALL statement during each execution of the run unit.
The first time the program is called after a CANCEL statement cancels it.
For an initial program, each time it is called.
Status of Internal Entities During Program Execution
During the execution of a program, each internal entity retains the status in which it was left by
the execution of the last statement that affected its status:
Each internal data item retains the last value assigned to it. If no new value has been assigned
since the last time the program was placed in its initial state, its “last value” is its initial value.
Each internal file connector retains the open-mode state and other dynamic attributes, such
as the file position indicator, set or assigned by execution of the last statement that affects
them. The record area for a file associated with an internal file connector retains whatever
contents were last assigned to it. If the file has not been opened since the last time the program
was placed in its initial state, the file is closed (and perhaps locked), and the other dynamic
attributes are undefined. In this case, the record area contents are also undefined.
Each GO TO statement that was modified by execution of an ALTER statement retains the last
destination procedure specified.
A PERFORM statement is active if it has been executed during the current execution of the
program it is in, and the termination conditions for its control mechanism have not yet occurred
(see PERFORM (page 389)); otherwise, the statement is inactive, and its control mechanism is
in the initial state.
Status of External Entities During Program Execution
The values of external data items and the statuses of external file connectors are not affected by
the actions performed for individual programs. When a program is called, placed in its initial
state, terminated by its own execution logic, or cancelled, the status of each external entity remains
unchanged. Of course, the execution of a statement that makes reference to an external data item
or an external file connector changes its status as the topic on that statement in Chapter 9: Procedure
Division Verbs (page 278), describes.
Called Program Termination
A called program terminates its own execution either by executing an EXIT PROGRAM statement
or by allowing control to pass beyond the end of its Procedure Division. The completion of the
program’s execution implicitly completes the execution of all of its statements; therefore, if any
PERFORM statement contained in the program is still active, it is rendered inactive by the program’s
resetting its control mechanism to the initial state. The final status of any other internal entity depends
on whether or not the program has the initial attribute.
When a called program that has the initial attribute terminates its own execution, an implicit
CANCEL statement referencing the program is executed just after control passes from the called
program. This causes the value of each internal data item to become undefined and performs an
implicit close operation for each internal file connector that is not closed (with or without lock). The
implicit close operations proceed as if a CLOSE statement without any of the optional phrases
Status of Internal Entities During Program Execution 597