Previous | Contents | Index |
The following format is used to describe most entries in this manual. Each COBOL division or major topic begins a new chapter and each entry begins on a new page. The entries are in functional or alphabetical order.
Function
The function paragraph describes the function
or the effect of the entry.
General Format
A general format shows the specific arrangement of elements in the
entry. If there is more than one arrangement, the formats are numbered.
All clauses (mandatory and optional) must be used in the sequence shown
in the format. However, the syntax rules sometimes allow exceptions.
generic-term
Following the general format are
definitions of its generic terms. These terms appear in the rules in
italic type.
Syntax Rules
Syntax rules define or clarify the arrangement of words or elements.
They can also impose further restrictions or relax restrictions implied
by the general format.
General Rules
General rules define or clarify the meaning (or relationship of
meanings) of an element or set of elements. They also define the
semantics of an entry, describing its effects on program compilation or
execution.
Technical Notes
Technical notes describe, in system-specific terms, any system-specific
behavior, and any other Compaq COBOL behavior of note not described in
the rules. They define relationships between the COBOL program
and the operating system and its components.
Additional References
Additional references point to
other relevant information in this manual, the Compaq COBOL User Manual, and other
Compaq documentation sets.
Examples
Examples show the use of a statement, clause,
or other entry. The Compaq COBOL User Manual contains other examples in
application contexts.
The following example shows a general format:
A COBOL source program is a syntactically correct set of COBOL statements that:
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.
The end-program-header must be present if either:
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. 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. screen description entries PROCEDURE DIVISION. DECLARATIVES. sections paragraphs sentences END DECLARATIVES. . . . sections paragraphs sentences . . . END PROGRAM 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:
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:
Only this item can immediately follow a DECLARATIVES header:
The PROCEDURE DIVISION header can contain a USING and GIVING phrase. (See Section 6.8.) |
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.
In the Procedure Division:
user-name SECTION [ segment-number ].
Only these items can immediately follow a section header:
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:
Successive sentences or entries begin in Area B of either:
A Data Division entry begins with a level indicator or level-number and is followed, in order, by:
The level indicators are as follows:
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.
2.3 Declaratives
Declaratives specify USE procedures to be executed only when certain conditions occur. You must write USE procedures at the beginning of the Procedure Division in consecutive sections. The key word DECLARATIVES begins the DECLARATIVES part of the Procedure Division; the pair of key words END DECLARATIVES ends it. Each of these reserved word phrases must be on a line by itself, starting in Area A; and be followed by a separator period. For example:
PROCEDURE DIVISION. DECLARATIVES. IOERROR SECTION. USE AFTER ... . PAR-1. . . . END DECLARATIVES. |
When you specify USE procedures, you must divide the remainder of the Procedure Division into sections.
The Identification Division marks the beginning of a COBOL program. It also identifies a program and its source listing.
* These paragraphs are not described in individual entries; they follow the same format as the AUTHOR paragraph and are for documentation only.
The PROGRAM-ID paragraph identifies a program and assigns selected program attributes.
program-name
is a user-defined word that names the program.
See Section 6.2.6, Scope of Names.
PROGRAM-ID. PROGA. PROGRAM-ID. SUBR1 INITIAL. PROGRAM-ID. COMPUTE-PAY WITH IDENT "JOB6a-V1.1". (OpenVMS only) PROGRAM-ID. WRITEMASTERREPORT. PROGRAM-ID. PAYROLL IS COMMON. |
The AUTHOR paragraph is for documentation only.
comment-entry
is a user-supplied comment about the program's author.
AUTHOR. JOHN SMITH. AUTHOR. This program was written by John Smith 1226 Main St. Merrimack, NH 03054 AUTHOR. |
The DATE-COMPILED paragraph provides the compilation date in the source program listing file.
comment-entry
is user-supplied information about the date compiled.
The paragraph-name DATE-COMPILED causes the current date to be inserted in your source program listing during compilation. Therefore, if a DATE-COMPILED paragraph is present in your source program, it will be replaced with a paragraph of the following form:
DATE-COMPILED. dd-mmm-yyyy.
3.1.4 OPTIONS
The OPTIONS paragraph specifies information for use by the compiler in generating executable code for a source unit.
arithmetic-clause
specifies the method used in developing the intermediate results. The format is:
The period appearing in the general format after the arithmetic-clause may be omitted if the arithmetic-clause is not specified.
Previous | Next | Contents | Index |