[an error occurred while processing this directive]

HP OpenVMS Systems Documentation

Content starts here

HP COBOL
Reference Manual


Previous Contents Index


Chapter 2
Organization of a COBOL Program

A COBOL source program is a syntactically correct set of COBOL statements that:

  • Mark the beginning of the program
  • Describe its physical environment
  • Describe the data the program creates, receives as input, manipulates, and produces as output
  • Specify the processing of the program's files and data

identification-division

represents a COBOL Identification Division.

environment-division

represents a COBOL Environment Division.

data-division

represents a COBOL Data Division.

procedure-division

represents a COBOL Procedure Division.

source-program

represents a contained (nested) COBOL source program. A COBOL source program may be nested; more than one source program may be present in a single source file.

end-program-header

represents a COBOL END PROGRAM header.

Syntax Rule

The end-program-header must be present if either:

  1. The COBOL source program contains one or more other COBOL source programs.
  2. The COBOL source program is contained within another COBOL source program.
  3. The COBOL source program precedes another separately compiled program.

General Rules

  1. The appropriate division header indicates the beginning of a division.
  2. The following indicates the end of a division:
    1. Another division header
    2. An Identification Division header that indicates the start of another source program
    3. The end-program-header
    4. The physical position at which no further source lines occur
  3. A COBOL source program may contain other COBOL source programs.
  4. A COBOL source program that is directly or indirectly contained within another program is called a contained or nested program. It may reference certain resources in the containing program.
  5. A separately compiled program has a nesting level number of 1. If this program contains other source-programs, it is the outermost containing program.
  6. A contained program has a nesting level number greater than 1.

Additional References

  • Identification Division
  • Environment Division
  • Data Division
  • Procedure Division
  • END PROGRAM Header

2.1 Program Structure

Figure 2-1 shows the basic structure of a COBOL program, which is organized in divisions, sections, paragraphs, sentences, and entries.

Figure 2-1 Structure of a COBOL Program



IDENTIFICATION DIVISION.
   PROGRAM-ID. program-name.
   AUTHOR.
   INSTALLATION.
   DATE-WRITTEN.
   DATE-COMPILED.
   SECURITY.
   OPTIONS.

ENVIRONMENT DIVISION.
 CONFIGURATION SECTION.
   SOURCE-COMPUTER.
   OBJECT-COMPUTER.
   SPECIAL-NAMES.
 INPUT-OUTPUT SECTION.
   FILE-CONTROL.
   I-O-CONTROL.

DATA DIVISION.
 SUBSCHEMA SECTION.
   subschema entries and keeplist entries
 FILE SECTION.
   file and record description entries
   report file description entries
   sort-merge file and record description entries
 WORKING-STORAGE SECTION.
   record description entries
 LINKAGE SECTION.
   record description entries
 REPORT SECTION.
   report and report group description entries.
 SCREEN SECTION.    (Alpha, I64)
   screen description entries   (Alpha, I64)

PROCEDURE DIVISION.
 DECLARATIVES.
   sections
     paragraphs
       sentences
 END DECLARATIVES.
       .
       .
       .
   sections
     paragraphs
       sentences
       .
       .
       .
 END PROGRAM header

2.1.1 Division Header

A division header identifies and marks the beginning of a division. It is a specific combination of reserved words followed by a separator period. Division headers start in Area A.

Except for the COPY and REPLACE statements, and the END PROGRAM header (see Section 6.9 in Chapter 6), the statements, entries, paragraphs, and sections of a COBOL source program are grouped into four divisions in this order:

  1. IDENTIFICATION DIVISION.
  2. ENVIRONMENT DIVISION.
  3. DATA DIVISION.
  4. PROCEDURE DIVISION.

The end of a COBOL source program is indicated either by the END PROGRAM header ( Section 6.9) or by the end of that program's Procedure Division.

Only these items can immediately follow a division header:

  • Another division header
  • A section header
  • A paragraph header or paragraph-name
  • A comment line
  • A blank line
  • A DECLARATIVES header for the USE procedure sections (after the PROCEDURE DIVISION header only)
  • A PROGRAM-ID paragraph (after the IDENTIFICATION DIVISION header only)

Only this item can immediately follow a DECLARATIVES header:

  • A section header for a USE procedure

Note

The PROCEDURE DIVISION header can contain a USING and GIVING phrase. (See Section 6.8.)

2.1.2 Section Header

A section header identifies and marks the beginning of a section in the Environment, Data, and Procedure Divisions. In the Environment and Data Divisions, a section header is a specific combination of reserved words followed by a separator period. In the Procedure Division, a section header is a user-defined word followed by the word SECTION (and an optional segment-number). A separator period always follows a section header. Section headers start in Area A.

The valid section headers follow for each division.

In the Environment Division:

CONFIGURATION SECTION.
INPUT-OUTPUT SECTION.

In the Data Division:

FILE SECTION.
WORKING-STORAGE SECTION.
LINKAGE SECTION.
REPORT SECTION.
SCREEN SECTION. (Alpha, I64)

In the Procedure Division:

user-name SECTION [ segment-number ].

Only these items can immediately follow a section header:

  • A division header
  • Another section header
  • A paragraph header or paragraph-name
  • A comment line
  • A USE statement (in the DECLARATIVES part of the Procedure Division only)
  • A blank line
  • A DATA DIVISION entry (in the Data Division)

2.1.3 Paragraph, Paragraph Header, Paragraph-Name

A paragraph consists of a paragraph header or paragraph-name (depending on the division) followed by zero, one, or more entries (or sentences).

A paragraph header is a reserved word followed by a separator period. Paragraph headers identify paragraphs in the Identification and Environment Divisions.

The paragraph headers are as follows:

Identification
Division
Environment
Division
PROGRAM-ID. SOURCE-COMPUTER.
AUTHOR. OBJECT-COMPUTER.
INSTALLATION. SPECIAL-NAMES.
DATE-WRITTEN. FILE-CONTROL.
DATE-COMPILED. I-O-CONTROL.
SECURITY.  
OPTIONS.  

A paragraph-name is a user-defined word followed by a separator period. Paragraph-names identify paragraphs in the Procedure Division.

Paragraph headers and paragraph-names start in Area A of any line after the first line of a division or section.

The first entry or sentence of a paragraph begins either:

  • On the same line as the paragraph header or paragraph-name
  • In Area B of the next nonblank line that is not a comment line

Successive sentences or entries begin in Area B of either:

  • The same line as the preceding entry or sentence
  • The next nonblank line that is not a comment line

2.2 Data Division Entries

A Data Division entry begins with a level indicator or level-number and is followed, in order, by:

  1. A space
  2. The name of a data item, file connector, or screen item
  3. A sequence of independent descriptive clauses
  4. A separator period

The level indicators are as follows:

  • FD (for file description entries)
  • SD (for sort-merge file description entries)
  • RD (for report file description entries)

Level indicators can begin anywhere to the right of Area A.

Entries that begin with level-numbers are called either data description or screen description entries, depending on their context. The level-number values are 01 to 49, 66, 77, and 88 for data description items and 01 to 49 for screen description entries. Level-numbers 01 to 09 can be represented as one- or two-digit numbers.

All data description entries and screen description entries can begin anywhere to the right of Margin A. However, indentation has no effect on level-number magnitude; it merely enhances readability.


Previous Next Contents Index