COBOL Manual for TNS and TNS/R Programs

Program Compilation
HP COBOL Manual for TNS and TNS/R Programs522555-006
11-4
Calling and Called Programs
Calling and Called Programs
Many languages have declarations that distinguish main programs from subprograms.
COBOL does not use the term “subprogram.” Instead, it defines a program as a
“calling program” if it contains a CALL or ENTER statement and defines a program as
a “called program” if it is the object of a CALL or ENTER statement. A program can be
both a calling program and a called program. The distinction is one of usage, not of
explicit declaration. In Example 11-1, A-PROGRAM is a calling program and A-
FRIEND is both a called program and a calling program.
If a called COBOL program is to receive parameters, it must have a Linkage Section
(see Linkage Section).
The statement a COBOL program uses to call another program depends on the
language in which the called program was written.
Called programs are not required to be in the main programs compilation unit (see
Compilation Units).
How an HP COBOL Program Calls a Non-COBOL Program
Any HP COBOL program can call a non-COBOL program with the ENTER statement.
An HP COBOL program that runs in the CRE and was compiled with the PORT
directive can also call a non-COBOL program with the X/Open CALL statement. The
difference between the ENTER statement and the X/Open CALL statement is that the
ENTER statement attempts to coerce the actual parameters into the types of the
formal parameters, while the X/Open CALL statement reports an error if the types of
the actual and formal parameters do not match.
Just as HP COBOL object programs can be read from an object file and included in the
target file during the binding phase of COBOL85 compilation or the (optional) linking
phase of NMCOBOL compilation, object programs from other languages can also.
Table 11-1. Statements for Calling Programs
Language of Called Program Statement for Calling Program
HP COBOL CALL
HP C ENTER or X/Open CALL
HP C++ ENTER or X/Open CALL
FORTRAN* ENTER or X/Open CALL
Pascal* ENTER or X/Open CALL
pTAL ENTER or X/Open CALL
TAL* ENTER or X/Open CALL
* Native HP COBOL programs cannot call programs written in this language.
Note. You cannot put any combination of TNS, TNS/R, or TNS/E object files into a single
object file.