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 and the
COBOL for Windows 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.
Following is
the format for the entries and statements that constitute a separately compiled
COBOL source program.
| Format: COBOL source program |
 >>-+-IDENTIFICATION-+--DIVISION.--PROGRAM-ID--+---+------------->
'-ID-------------' '-.-'
>--program-name-1--+------------------------------------+------->
'-+----+--+-RECURSIVE-+--+---------+-'
'-IS-' '-INITIAL---' '-PROGRAM-'
>--+---+--+---------------------------------+------------------->
'-.-' '-identification-division-content-'
>--+-----------------------------------------------------+------>
'-ENVIRONMENT DIVISION.--environment-division-content-'
>--+---------------------------------------+-------------------->
'-DATA DIVISION.--data-division-content-'
>--+-------------------------------------------------+---------->
'-PROCEDURE DIVISION.--procedure-division-content-'
>--+-----------------------------------------------------------------+-><
'-+-------------------------------+--END PROGRAM--program-name-1.-'
| .---------------------------. |
| V | |
'---| Nested source program |-+-'
nested source program:
|--+-IDENTIFICATION-+--DIVISION.--PROGRAM-ID--+---+------------->
'-ID-------------' '-.-'
>--program-name-2----------------------------------------------->
>--+----------------------------------------------+--+---+------>
'-+----+--+-COMMON--+---------+-+--+---------+-' '-.-'
'-IS-' | '-INITIAL-' | '-PROGRAM-'
'-INITIAL--+--------+-'
'-COMMON-'
>--+---------------------------------+-------------------------->
'-identification-division-content-'
>--+-----------------------------------------------------+------>
'-ENVIRONMENT DIVISION.--environment-division-content-'
>--+---------------------------------------+-------------------->
'-DATA DIVISION.--data-division-content-'
>--+-------------------------------------------------+---------->
'-PROCEDURE DIVISION.--procedure-division-content-'
>--+-------------------------------+--END PROGRAM--------------->
| .---------------------------. |
| V | |
'---| nested source program |-+-'
>--program-name-2.----------------------------------------------|
|
A sequence of separate COBOL
programs can also be input to the compiler. The following is the format for the
entries and statements that constitute a sequence of source programs (batch
compile).
| Format: sequence of COBOL source programs |
 .----------------------.
V |
>>---COBOL-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 a
user-defined word. 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.
|