Sections [ HP COBOL II/XL Reference Manual ] MPE/iX 5.0 Documentation
HP COBOL II/XL Reference Manual
Sections
A section is the second level construct in a COBOL program. In the
source program, sections allow you to group logically related items
together within a division. In the PROCEDURE DIVISION, you can organize
logically related functions into the same sections in such a way that
often used routines reside in main memory for longer periods of time than
routines used infrequently. This minimizes the total number of
input-output operations that the operating system must perform on the
code segments belonging to the program. It also facilitates program
debugging. In other divisions, the features that a program uses
determine which sections must be specified in the program.
Sections are optional in the PROCEDURE DIVISION. If you do not specify
sections in a division, the entire division is treated as a single
section. Sections are not used, however, in the IDENTIFICATION DIVISION.
Section Format
Each section begins with a header entry that is optionally followed by
zero, one, or more paragraphs (in the ENVIRONMENT or PROCEDURE DIVISION)
or clauses (in the DATA DIVISION). The paragraphs or clauses comprise the
section body. A section is terminated by the next section header, the
next division header, the END DECLARATIVES keywords (in the declarative
portion of the PROCEDURE DIVISION), or the physical end of the program.
Section Header Format
In the ENVIRONMENT and DATA DIVISIONs, the section header consists of a
COBOL reserved word that identifies the section, followed by the word
SECTION, followed by a period and a space. In the ENVIRONMENT DIVISION,
only the following section headers are permitted:
CONFIGURATION SECTION.
INPUT-OUTPUT SECTION.
In the DATA DIVISION, only the following section headers are allowed:
FILE SECTION.
WORKING-STORAGE SECTION.
LINKAGE SECTION.
In the PROCEDURE DIVISION, the section header consists of a user-defined
section name that identifies the section, followed by the word "SECTION",
followed by an optional segment number, followed by a period and a space.
In the PROCEDURE DIVISION, unlike the ENVIRONMENT and DATA DIVISIONs,
names are not restricted to specific words, so you can supply any section
names you desire. Here are some examples of section headers that might
be used in the PROCEDURE DIVISION:
INITIALIZATION SECTION.
HOUSEKEEPING SECTION 3.
In the second example above, the number 3 represents the segment number.
This number is used in program segmentation (partitioning of a program
into distinct code segments.) Segmentation is described in Chapter 8
.
For clarity, programmers usually write a section header on a line by
itself, although you are not formally required to do so.
In Figure 2-2 , the WORKING-STORAGE SECTION (item 5) appears in the
DATA DIVISION. Because no section is specified in the PROCEDURE DIVISION,
the whole division is regarded as a section by the compiler.
MPE/iX 5.0 Documentation