COBOL Manual for TNS and TNS/R Programs

Calling Other Programs and Routines
HP COBOL Manual for TNS and TNS/R Programs522555-006
23-6
Dynamic Calls
Quotation marks around program-name are not required, but are recommended. If,
in some eventual program maintenance, someone adds a variable named APROG to a
program that already calls a program named APROG, and the name APROG is not in
quotation marks, the compiler assumes that APROG refers to the variable.
At run time, if the variable APROG does not contain the name of a valid program that is
included in the object file, the program terminates with the error message “Called
program not found.” If APROG is enclosed in quotes, the compiler recognizes it as a
program name rather than a variable.
A static call is more efficient than a dynamic call, but a dynamic call is more flexible.
Dynamic Calls
To perform a dynamic call, use the statement CALL identifier, where identifier
is an alphanumeric data item whose value is not known until run time. The value of
identifier is the PROGRAM-ID of the called program, but it cannot be qualified
with the phrase OF file-mnemonic or IN file-mnemonic.
Example 23-1 shows a CALL identifier statement in context. The identifier is
ROUTINE, and at run time its value will be either POSRTN or NEG0RTN, depending
on the value of TALLY.
A program that is to be called with a CALL identifier statement cannot use
standard (16-bit) addressing.
The compilation is unable to validate the parameters of dynamic calls (that is, to
determine whether the actual parameters of the calling program correspond to the
formal parameters of the called program).
Every program that a dynamic call could possibly call (in the preceding example, the
programs POSRTN and NEG0RTN) must be bound or linked into the run unit or user
library before you execute the program (see Binding or Linking Programs to Be Called
Dynamically).
Example 23-1. CALL Identifier Statement
DATA DIVISION.
01 ROUTINE PICTURE X(7).
...
PROCEDURE DIVISION.
...
IF TALLY IS GREATER THAN 0 MOVE "POSRTN" TO ROUTINE
ELSE MOVE "NEG0RTN" TO ROUTINE
CALL ROUTINE
...