CHAPTER 2
THE IDENTIFICATION AND
ENVIRONMENT DIVISIONS
CHAPTER OBJECTIVES
After
completion of this chapter, the student should be able to:
1. Explain the parts of a COBOL coding
sheet.
2. Identify the four divisions of a COBOL
program and specify the order in which they appear in a program.
3. Describe the coding rules for division
and section names, paragraph-names, sentences, and comments.
4. Explain the purpose of the
IDENTIFICATION DIVISION.
5. Explain the purpose of the ENVIRONMENT
DIVISION.
6. Identify the two sections of the
ENVIRONMENT DIVISION.
7. Explain the purpose of the
CONFIGURATION SECTION.
8. Explain the purpose of the INPUT-OUTPUT
SECTION.
9. Explain the purpose of the SELECT
statement.
10. Describe the format of the SELECT statement.
LECTURE OUTLINE
I. Basic
Structure of a COBOL Program
A. Coding a Source Program
1. Each COBOL instruction is coded on a
single line using 80 characters per line, where specific entries must appear in
designated columns or positions.
2. COBOL coding or program sheets are
sometimes used to create an initial version of the program prior to keying it
into the computer. One main advantage of
COBOL coding sheets is that they designate where the specific items of a
program are to be placed.
B. Coding Rules
1. The Main Body of a Program
The main body of a
program and the coding sheet itself are subdivided into 72 positions or
columns.
2. Optional Entries: Identification and
Page and Serial Numbers
a. Columns 73 - 80 are reserved for
program identification.
b. Columns 1 - 6 are reserved for page and
line numbers.
c. These uses of columns 1 - 6 and 73 - 80
are carryovers from punched card days and are rarely used today.
3. Column 7, labeled Cont. on the coding
sheet has specific functions:
a. An asterisk (*) designates the line as
a comment line. Comments can be used to
provide documentation information.
b. A slash (/) in column 7 will cause the
printer to skip to the next page when the source listing is being printed. This may be used when we wish to print a
division or routine on a separate page.
c. A dash (-) denotes a continuation of a
nonnumeric literal from one line to another.
4. The main body of the coding sheet is
Columns 8 - 72. This is where COBOL
statements are coded.
a. Columns 8 - 72 are broken into two
sections called Area A and Area B.
b. Columns 8 - 11 of the coding sheet are
known as Area A. Divisions, sections, and paragraphs begin in Area A.
c. Words or statements beginning in Area A
may extend into Area B.
d. Columns 12 - 72 of the coding sheet are
known as Area B. Statements and sentences begin in Area B. Most COBOL entries
begin in Area B.
C. Types of COBOL Entries
1. The four divisions of a COBOL program
and the order in which they must appear are: IDENTIFICATION, ENVIRONMENT, DATA,
and PROCEDURE.
2. Some divisions are subdivided into
sections which may be further subdivided into paragraphs. All other entries are considered COBOL
statements. A statement or series of
statements that ends with a period is referred to as a sentence.
3. Coding rules for the division and
section names are:
a. Begin in Area A.
b. End with a period.
c. Must appear on a line with no other
entries.
4. Coding rules for paragraph-names are:
a. Begin in Area A.
b. End with a period, which must be followed
by at least one space.
c. May appear on a line by itself or with
other entries.
5. Coding rules for sentences and
statements are:
a. Begin in Area B.
b. Sentences end with a period, which must
always be followed by at least one space.
c. May appear on lines by themselves or
with other entries.
d. A sentence consists of a statement or
series of statements.
e. For COBOL 85, PROCEDURE DIVISION
statements are not ended with a period except for the last one in the
paragraph. Periods may, however, be placed
at the end of each full
statement.
6. The rather rigid Margin A and B rules
will be eliminated in COBOL
2002+.
II. Coding Requirements of the
IDENTIFICATION DIVISION
A. Paragraphs in the IDENTIFICATION
DIVISION
1. The IDENTIFICATION DIVISION has no
effect on the execution of a program, but is required. It identifies the program to the computer.
2. Paragraphs in the IDENTIFICATION
DIVISION:
a. PROGRAM-ID. program-name. (required
entry)
b. AUTHOR. (optional
comment-entry)
c. INSTALLATION. (optional
comment-entry)
d. DATE-WRITTEN. (optional
comment-entry)
e. DATE-COMPILED. (optional
comment-entry)
f. SECURITY. (optional
comment-entry)
B. Understanding Instruction Formats as
They Appear in Reference Manuals
Rules
for interpreting instruction formats:
1. Uppercase words are COBOL reserved
words that have special meaning to the compiler.
2. Underlined words are required in the
paragraph.
3. Lowercase words represent user-defined
entries.
4. Braces { } denote that one of the enclosed
items is required.
5. Brackets [ ] mean the clause or
paragraph is optional.
6. If punctuation is specified in the
format, it is required.
7. The use of dots or ellipses (...) means
that additional entries of the same type may be included.
C. All paragraphs AUTHOR through SECURITY
will be deleted from the
COBOL 2000+ standard since they can
easily be replaced with comments.
D. Examples
Examine
the examples as illustrated in this section of the text.
III.
The Sections of the ENVIRONMENT
DIVISION
A. Overview
1. The ENVIRONMENT DIVISION is the only
machine-dependent division of a COBOL program.
It supplies information about the computer equipment to be used in the
program.
2. If the program is to be run on a
different computer, the ENVIRONMENT DIVISION will have to be changed to reflect
the new computer equipment.
3. The entire ENVIRONMENT DIVISION is
optional for COBOL 85, but is required if files are to be processed.
4. The ENVIRONMENT DIVISION consists of
two sections:
a. CONFIGURATION SECTION.
b. INPUT-OUTPUT SECTION.
B. CONFIGURATION SECTION
1. The CONFIGURATION SECTION describes the
computer used to compile and execute the program. It indicates the following:
a. SOURCE-COMPUTER - the computer used to
compile the program. This is an optional
entry.
b. OBJECT-COMPUTER - the computer used to
execute the program. This is an optional
entry.
c. SPECIAL-NAMES - paragraph used in
conjunction with the display of output, which is discussed in the chapter on
interactive processing.
2. The entire CONFIGURATION SECTION is
optional in COBOL 85.
C. INPUT-OUTPUT SECTION
1. The INPUT-OUTPUT SECTION follows the
CONFIGURATION SECTION and supplies information about the input and output
devices used in the program.
2. The INPUT-OUTPUT SECTION contains the
FILE-CONTROL paragraph, which names each file and assigns it to a device.
IV. Assigning Files to Devices in the
ENVIRONMENT DIVISION
A. Overall Format
1. The FILE-CONTROL paragraph is used to
assign files to devices.
2. The FILE-CONTROL paragraph consists of
SELECT statements.
3. Each SELECT statement is coded in Area
B and ends with a period.
4. A SELECT statement defines a file-name
and assigns a machine-dependent device (provided by the computer center) to
that file.
5. Each file used in a program must have a
SELECT statement to associate it with its machine-dependent device.
6. A SELECT statement normally consists of
two clauses:
a. The user-defined file-name is specified
in the first clause. Review the rules
for forming user-defined file-names found in this section of the text.
b. The second clause contains the
implementor-name or device specifications for the file. The device specifications vary among computer
manufactures. Learn the options for your
particular computer.
c. SELECT statements for most PC COBOL
compilers require a third clause, ORGANIZATION IS LINE SEQUENTIAL.
B. SELECT Statements for PCs
1. The device specification after the word
ASSIGN is coded as in this example: SELECT
file-name
where
a. The drive, path, and filename must be
supplied.
b. The name chosen for the disk file (INVFILE.DAT
in this case) must adhere to the rules for forming file-names on the operating
system being used.
c. The entry is enclosed within quotes.
2. The ORGANIZATION IS LINE SEQUENTIAL
clause must be used with most PC COBOL compilers.
SOLUTIONS
TO REVIEW QUESTIONS
I. True-False Questions
1. T
2. F AUTHOR
is not a required entry.
3. F File
names must not contain embedded blanks.
4. T
5. T
6. T
7. F Any
number of lines may be used.
8. T
9. T
10. T
11. F As
many files as are needed may be defined, as long as
the number of files is within the limit
allowed by the operating
system.
12. F The ENVIRONMENT DIVISION may be used
with interactive
programs as well as batch programs.
II. General Questions
1. IDENTIFICATION DIVISION.
PROGRAM-ID. SAMPLE1.
2. ENVIRONMENT DIVISION.
CONFIGURATION SECTION.
3. IDENTIFICATION DIVISION.
PROGRAM-ID.
SAMPLE4.
AUTHOR.
MARY DOE.
4. DATA DIVISION.
FILE SECTION.
5. ENVIRONMENT DIVISION.
CONFIGURATION SECTION.
SOURCE-COMPUTER. IBM-AS400.
6. ENVIRONMENT DIVISION.
.
.
.
INPUT-OUTPUT SECTION.
7. SELECT FILE-A
ASSIGN TO DISK1.
8. FILE-CONTROL.
SELECT FILEA
ASSIGN TO PRINTER.
9. a. Area A e. Area B
b. Area A f. Area A
c. Area B g. Area A
d. Area A h. Area B
10. These paragraphs serve no purpose in the
execution of the program and need not be included as part of the compiled
object. Instead, this information can be
included as comments for documentation purposes.
III. Internet/Critical Thinking Questions
1.
Keywords: COBOL
self-documenting
URL: http://interex.org/pubcontent/enterprise/jan01/04cobol.html
Contents: COBOL Style
Keywords: COBOL
self-documenting
URL: http://www.cu.edu/~pubs/cobgdln.html
Contents: COBOL Guidelines
Keywords: COBOL
self-documenting
URL: http://home.swbell.net/cobol/style/style.html
Contents: COBOL Style forum
2. The new COBOL standard relaxes some of
the rules contained in previous versions of the language. The list below includes some of these
changes; these and additional changes may be found at the web site http://www.cobolstandards.com/.
·
The NOT AT END phrase can be specified
before the AT END phrase; the same is true for the other phrases with NOT.
·
When a function has no arguments, the
empty parentheses ( ) are optional. This applies to both intrinsic functions
and user-defined functions.
·
In arithmetic expressions, no space is
required between a left parenthesis and a unary operator or between a unary
operator and a left parenthesis.
·
Call arguments may be elementary or group
items with any level number. Formerly,
they had to be elementary or have a level number of 1 or 77.
·
Comment lines may be written as any line
in a compilation group, including before the identification division header.
·
EXIT PROGRAM is allowed to appear as
other than the last statement in a consecutive sequence of imperative
statements.
·
A paragraph name is not required at the
beginning of the procedure division or a section.
·
Margin A and B rules will be eliminated