HP 3000 Manuals

Transfer of Control [ HP COBOL II/XL Reference Manual ] MPE/iX 5.0 Documentation


HP COBOL II/XL Reference Manual

Transfer of Control 

The CALL statement is the means used in COBOL programs to pass control
from one object program to another, and there are no restrictions on a
called program itself calling another object program.  Caution should be
used, however, to avoid calling a program that preceded, in the calling
chain, the program currently having control.  Otherwise, results of the
run unit are unpredictable. 

When control is passed to a called program, execution begins either at
the first PROCEDURE DIVISION statement or at a secondary entry point of
the PROCEDURE DIVISION. Secondary entry points are described later in
this chapter under the ENTRY statement, an HP extension to ANSI COBOL'85.
Program execution begins at the point of entry to the called program in
the normal, line-by-line sequence, following the same conventions used
for COBOL main programs.  Termination takes place in a COBOL subprogram
under two possible conditions.

The first condition that causes termination is when an EXIT PROGRAM or
GOBACK statement is encountered.  When this occurs, control reverts to
the calling program, which begins execution at the line immediately
following the CALL statement that originally passed control.

The second condition that causes termination in a COBOL program is when a
STOP RUN statement is encountered.  In this case, the entire run unit is
terminated.

In summary, the EXIT PROGRAM and GOBACK statements terminate only the
program in which they appear, while the STOP RUN statement terminates the
entire run unit.

An exception to this is when a GOBACK statement appears in a main
program.  In this case, it is equivalent to issuing a STOP RUN statement.

If the called program is not a COBOL program, termination of the run
unit, or the return of control to the calling program, must be performed
in accordance with the rules of the language in which the called program
is written.



MPE/iX 5.0 Documentation