Nested programs
A COBOL program can nest, or contain, other COBOL programs. The nested programs can themselves contain other programs. A nested program can be directly or indirectly contained in a program.
There are four main advantages to nesting called programs:
- Nested programs provide a method
for creating modular functions
and maintaining structured programming techniques.
They can be used
analogously to perform procedures (using the
PERFORM
statement), but with more structured control flow and with the ability to protect local data items. - Nested programs let you debug a program before including it in an application.
- Nested programs enable you to compile an application with a single invocation of the compiler.
- Calls to nested programs have
the best performance of all the
forms of COBOL
CALL
statements.
The following example describes a nested structure that has directly and indirectly contained programs: