Nested programs

A COBOL program can contain other COBOL programs, which in turn can contain still other COBOL programs. These contained programs are called nested programs. Nested programs can be directly or indirectly contained in the containing program.

Nested programs are not supported for programs compiled with the THREAD option.

In the following code fragment, program Outer-program directly contains program Inner-1. Program Inner-1 directly contains program Inner-1a, and Outer-program indirectly contains Inner-1a:


Id division.
Program-id. Outer-program.
  Procedure division.
    Call "Inner-1".
    Stop run.
Id division.
  Program-id. Inner-1
  ...
    Call Inner-1a.
    Stop run.
  Id division.
  Program-id. Inner-1a.
  ...
  End Inner-1a.
  End Inner-1.
End Outer-program.

The following figure describes a more complex nested program structure with directly and indirectly contained programs.

This figure illustrates a nested program structure similar to that shown in the code above. This figure shows the same concepts with more programs.