COBOL Manual for TNS/E Programs (H06.08+, J06.03+)
and, under some circumstances, they can also call non-COBOL programs. The source file that is
input to the compiler is also called a compilation unit.
Main Programs
A main program is either compiled with the MAIN directive (see MAIN) or it has no Linkage Section
(see Absent Linkage Section (page 182)). A loadfile must contain exactly one main program. It can
also contain other programs. When the loadfile is executed, the NonStop operating system calls
the main program. Then the main program can call the other programs and the other programs
can call each other. The NonStop operating system does not call the other programs.
In Example 147, the MAIN directive makes A-PROGRAM a main program. If A-PROGRAM and
A-FRIEND are compiled in the same compilation unit, A-FRIEND is not a main program. If A-FRIEND
is compiled alone, it is a main program, because it does not have a Linkage Section.
Example 147 Main Program and Another Program
?MAIN A-PROGRAM
IDENTIFICATION DIVISION.
PROGRAM-ID. A-PROGRAM.
ENVIRONMENT DIVISION.
...
SPECIAL-NAMES.
FILE "$SYSTEM.COBSYS.BFILES" IS B-FILE.
DATA DIVISION.
...
PROCEDURE DIVISION.
...
CALL "A-FRIEND"
...
CALL "B-FRIEND" IN B-FILE
...
STOP RUN.
END PROGRAM A-PROGRAM.
IDENTIFICATION DIVISION.
PROGRAM-ID. A-FRIEND.
ENVIRONMENT DIVISION.
...
SPECIAL-NAMES.
FILE "$SYSTEM.COBSYS.BFILES" IS B-FILE,
FILE "$SYSTEM.TALSYS.TFILES" IS T-FILE.
DATA DIVISION.
...
PROCEDURE DIVISION.
...
CALL "HOME" IN BFILE
...
ENTER TAL "SPECIALIST" IN T-FILE
...
STOP RUN.
END PROGRAM A-FRIEND.
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 147, 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 (page 179)).
Compiler Input 513










