Interprogram Communication
12.1 Multiple COBOL Program Run Units
Example 12–1 Run Unit with Three Separately Compiled Programs
IDENTIFICATION DIVISION.
PROGRAM-ID. MAIN-PROGRAM.
.
.
.
CALL SUB1.
.
.
.
STOP RUN.
END PROGRAM MAIN-PROGRAM
A separately compiled program has a nesting level number of 1. If this
program contains other source programs, it is the outermost containing
program. A contained program has a nesting level number greater
than 1.
Example 12–2 shows a run unit with one main program (
programs (SUB1 (
(
) is an indirectly contained program of MAIN-PROGRAM).
6
Example 12–3 shows a run unit with three separately compiled programs (
and
). One of the separately compiled programs, MAIN-PROGRAM (
1 1
two directly contained programs, SUB1 and SUB2 (
12.1.2 Calling Procedures
A COBOL main (driver) program calls subprograms (contained or separately
compiled). Image execution begins and ends in the main program's Procedure
Division. The program contains one or more CALL statements and is a calling
program.
A COBOL subprogram is called by a main program or another subprogram. The
subprogram may or may not contain CALL statements. If a subprogram contains
a CALL statement, it is both a calling and a called program. If the subprogram
does not contain a CALL statement, it is a called program only.
12–2 Interprogram Communication
1
IDENTIFICATION DIVISION.
PROGRAM-ID. SUB2.
.
.
.
EXIT PROGRAM.
END PROGRAM SUB2.
Note
) is a directly contained program of MAIN-PROGRAM; SUB2
5
IDENTIFICATION DIVISION.
PROGRAM-ID. SUB1.
.
.
.
CALL SUB2.
.
.
.
EXIT PROGRAM.
END PROGRAM SUB1.
3
) and two contained
4
and
).
8
9
2
,
,
7
1 0
), has
7