The CHAIN Statement
The CHAIN statement transfers control from one object program to another
in the run unit with no subsequent return of control. The effect is as though
the chained program is the main program in the new run unit.
General Format

Syntax Rules
- The syntax of the CHAIN statement is similar to the syntax of the CALL statement
and the two are subject to common syntax rules as indicated in the topic The
CALL Statement. All the identifiers, literals and integers in the general
format of the CHAIN statement correspond to the identifiers, literals and
integers of the CALL statement.
General Rules
- Literal-1 or the content of the data item referenced by identifier-1 is the
name of the chained program. The program in which the CHAIN statement appears
is the chaining program.
The chained program must be a COBOL program that is not a nested program.
The name of the chained program must contain the name contained in the Program-ID
paragraph of the chained program (seethe section The Program-ID Paragraph,
particularly in regard to case sensitivity). Alternatively, the name of the
chained program may contain a name which identifies a file that contains executable
program code for the chained program. See your COBOL system documentation
for details of how your system matches the given name to previously chained
programs, program filenames or programs held in library files.
- If, when a CHAIN statement is executed, the program specified by the CHAIN
statement is made available for execution, control is transferred to the chained
program, and the chaining program, and any COBOL programs called by the chaining
program, are canceled. The chained program is not under the control of a chaining
program and so any EXIT PROGRAM executed within the chained program has no
effect.
- If, when a CHAIN statement is executed, the program specified by the CHAIN
statement is not made available for execution, then a fatal run-time error
is given.
- Chained programs can contain CHAIN statements. A CHAIN statement within a
chained program may reference any program except itself.
- The form of the CHAIN statement is similar to the form of the CALL statement
and the two are subject to common general rules as indicated in the topic
The CALL Statement. All the identifiers, literals and integers in the
general format of the CHAIN statement correspond to the identifiers, literals
and integers of the CALL statement. Also, where the expressions calling program
and called program are used, these can be considered equivalent to the expressions
chaining program and chained program.
- The chain operation moves the value from each data item referenced in the
USING phrase of the CHAIN statement to the data item referenced by the corresponding
data-name in the USING phrase of the PROCEDURE DIVISION header of the chained
program.
- The value of any data item with USAGE POINTER or USAGE PROCEDURE-POINTER
that is passed as an operand in the USING phrase must not represent the address
that was originally derived from a COBOL data item.
- The END-CHAIN phrase delimits the scope of the CHAIN statement.
- The USING phrase must not be used if you have specified the Compiler directive
INTLEVEL"1".