COBOL Manual for TNS and TNS/R Programs
Program Execution
HP COBOL Manual for TNS and TNS/R Programs—522555-006
12-26
Called Program Termination
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 were executed
for each of the affected files. If the program is called again, it is placed in its initial
state.
When a called program that does not have the initial attribute terminates its own
execution, each internal entity (except a data item described in the Linkage Section)
retains its status:
•
Each internal data item (except those described in the Linkage Section) retains its
current value.
•
Each internal file connector retains all of its current dynamic attributes; therefore, if
it is open in some mode, it remains open in that mode and the record area for the
file associated with the internal file connector retains its current contents.
•
Each GO TO statement modified by execution of an ALTER statement retains the
last destination procedure specified.
If the program is called again during this execution of the run unit, its state upon entry
is normally unchanged from the state in which its termination logic left it, except that
those data items described in the Linkage Section have whatever values are supplied
by the calling program; however, if a CANCEL statement designating the program is
executed after the program terminates, it causes the value of each internal data item to
become undefined and performs an implicit close operation for each internal file
connector that is neither closed nor locked. The implicit close operations proceed as if
a CLOSE statement without any of the optional phrases were executed for each of the
affected files. In this case, the program is placed in its initial state the next time it is
called.