COBOL program structure

A COBOL source program is a syntactically correct set of COBOL statements.

Nested programs
A nested program is a program that is contained in another program. Contained programs can reference some of the resources of the programs that contain them. If program B is contained in program A, it is directly contained if there is no program contained in program A that also contains program B. Program B is indirectly contained in program A if there exists a program contained in program A that also contains program B. For more information about nested programs, see Nested programs in the Enterprise COBOL Programming Guide.
Object program
An object program is a set or group of executable machine language instructions and other material designed to interact with data to provide problem solutions. An object program is generally the machine language result of the operation of a COBOL compiler on a source program. The term object program also refers to the methods that result from compiling a class definition.
Run unit
A run unit is one or more object programs that interact with one another and that function at run time as an entity to provide problem solutions.
Sibling program
Sibling programs are programs that are directly contained in the same program.

With the exception of the COPY and REPLACE statements and the end program marker, the statements, entries, paragraphs, and sections of a COBOL source program are grouped into the following four divisions:

  • IDENTIFICATION DIVISION
  • ENVIRONMENT DIVISION
  • DATA DIVISION
  • PROCEDURE DIVISION

The end of a COBOL source program is indicated by the END PROGRAM marker. If there are no nested programs, the absence of additional source program lines also indicates the end of a COBOL program.

The following format is for the entries and statements that constitute a separately compiled COBOL source program.

Format: COBOL source program

Read syntax diagramSkip visual syntax diagramIDENTIFICATIONIDDIVISION.PROGRAM-ID.program-name-1ISRECURSIVEINITIALPROGRAM.identification-division-content ENVIRONMENT DIVISION.environment-division-contentDATA DIVISION.data-division-contentPROCEDURE DIVISION.procedure-division-contentNested source programEND PROGRAMprogram-name-1.
nested source program
Read syntax diagramSkip visual syntax diagramIDENTIFICATIONIDDIVISION.PROGRAM-ID.program-name-2ISCOMMONINITIALINITIALCOMMONPROGRAM.identification-division-content ENVIRONMENT DIVISION.environment-division-contentDATA DIVISION.data-division-contentPROCEDURE DIVISION.procedure-division-content| nested source program |END PROGRAMprogram-name-2.

A sequence of separate COBOL programs can also be input to the compiler. The following format is for the entries and statements that constitute a sequence of source programs (batch compile).

Format: sequence of COBOL source programs

Read syntax diagramSkip visual syntax diagramCOBOL-source-program
END PROGRAM program-name
An end program marker separates each program in the sequence of programs. program-name must be identical to a program-name declared in a preceding program-ID paragraph.

program-name can be specified either as a user-defined word or in an alphanumeric literal. Either way, program-name must follow the rules for forming program-names. program-name cannot be a figurative constant. Any lowercase letters in the literal are folded to uppercase.

An end program marker is optional for the last program in the sequence only if that program does not contain any nested source programs.