Library View Topics Framed Contents Revised Topics Previous Topic Next Topic Search Search ResultsPrevious Topic MatchNext Topic Match Notes List Notes Print Download No PDF Handheld DisconnectedHandheld ConnectedHelp

2.1 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. These 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 contained and containing programs, see B. For more information on nested programs, see "Nested Programs" in topic 2.1.1 and the IBM COBOL Programming Guide for your platform.

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.

Run Unit
A run unit is one or more object programs that interact with one another and that function at object time as an entity to provide problem solutions.

Sibling program
Sibling programs are programs that are directly contained by the same program.

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

The end of a COBOL source program is indicated by the END PROGRAM header. 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 _____________________________________________ 
   |                                                                              |
   |                                                (1)                           |
   | >>__ _IDENTIFICATION_ __DIVISION.__PROGRAM-ID._____program-name-1__________> |
   |     |_ ID ___________|                                                       |
   |                                                                              |
   |                                                (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._|       |
   |      | <___________________________  |                                       |
   |      |___| nested source program |_|_|                                       |
   |                                                                              |
   | nested source program:                                                       |
   |                                               (1)                            |
   | |__ _IDENTIFICATION_ __DIVISION.__PROGRAM-ID._____program-name-2___________> |
   |    |_ ID ___________|                                                        |
   |                                                                              |
   |                                                        (1)                   |
   | >__ ______________________________________________ __._____________________> |
   |    |_ ____ __ _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__program-name-2._________| |
   |    | <___________________________  |                                         |
   |    |___| nested source program |_|_|                                         |
   |                                                                              |
   | Note:                                                                        |
 X | (1)  This separator period is optional as an IBM extension.                  |
   |                                                                              |
   |______________________________________________________________________________|

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


    ___ Format--Sequence of COBOL Source Programs __________________________ 
   |                                                                        |
   |     <______________________                                            |
   | >>____COBOL-source-program_|________________________________________>< |
   |                                                                        |
   |________________________________________________________________________|
END PROGRAM program-name
An end program header separates each program in the sequence of programs. The program-name must conform to the rules for forming a user-defined word. It must be identical to a program-name declared in a preceding PROGRAM-ID paragraph.


X Program-name can be a nonnumeric literal, but cannot be a figurative
X constant. The content of the literal must follow the rules for
X formation of program names. Any lowercase letters in this literal
X will be folded to uppercase.

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

Subtopics:



Previous Topic Next Topic Copyright IBM Corp. 1991, 1998

IBM Library Server Copyright 1989, 2005 IBM Corporation. All rights reserved.





Return to library:   z/OS | z/OS.e | TPF | z/VSE | z/VM | IBM Hardware | IBM System z Redbooks
Glossary:   IBM terminology
Publications:   How to order publications
Readers:   Download IBM Library Reader | Download IBM Softcopy Reader | Download Adobe® Acrobat® Reader®
Library management:   Download IBM Softcopy Librarian
Contacts:   Contact z/OS


Adobe, the Adobe logo, Acrobat, the Acrobat logo, and Acrobat Reader are registered trademarks of Adobe Systems incorporated.