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

Initial Programs
If a program has the INITIAL clause in its Identification Division, it is an initial program. Its program
state is initialized whenever it is called. The data in its Working-Storage Section is allocated when
it is called rather than being statically allocated. For more information about initial programs, see
Initial Programs (page 51).
Static Calls
A static call is achieved with the statement CALL program-name, where program-name is an
alphanumeric literal whose value is known at compilation time. program-name is the PROGRAM-ID
of the called program, and it can be qualified with the phrase OF file-mnemonic or IN
file-mnemonic.
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 250 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.
Example 250 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
...
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 linked into the run unit or user library before you execute the
program (see Linking HP COBOL Programs (page 816)).
If you want an HP COBOL program to be entirely free to call any other COBOL program that is
prepared to be called, make the programs separate processes. Separate processes communicate
through the file process $RECEIVE—the sender writes to a named process, and the receiver reads
a file named $RECEIVE. For more information about $RECEIVE, see $RECEIVE (page 916).
Calling Other COBOL Programs 797