![Page 1: The IDENTIFICATION and ENVIRONMENT DIVISIONS Chapter 2](https://reader030.vdocuments.site/reader030/viewer/2022032703/56649cfa5503460f949cb58b/html5/thumbnails/1.jpg)
The IDENTIFICATION and ENVIRONMENT DIVISIONS
Chapter 2
![Page 2: The IDENTIFICATION and ENVIRONMENT DIVISIONS Chapter 2](https://reader030.vdocuments.site/reader030/viewer/2022032703/56649cfa5503460f949cb58b/html5/thumbnails/2.jpg)
Chapter Contents
• Basic Structure of a COBOL Program
• Coding Requirements of IDENTIFICATION DIVISION
• Sections of ENVIRONMENT DIVISION
• Assigning Files to Devices in ENVIRONMENT DIVISION
![Page 3: The IDENTIFICATION and ENVIRONMENT DIVISIONS Chapter 2](https://reader030.vdocuments.site/reader030/viewer/2022032703/56649cfa5503460f949cb58b/html5/thumbnails/3.jpg)
Basic COBOL Program Structure
• Originally, each COBOL instruction coded on single line of 80 characters
• Positions on line reserved for special purposes
• Rules may differ for your compiler– In fact, the compiler on the VAX allows two
formats – the one described in the book, and a newer format that we will use.
![Page 4: The IDENTIFICATION and ENVIRONMENT DIVISIONS Chapter 2](https://reader030.vdocuments.site/reader030/viewer/2022032703/56649cfa5503460f949cb58b/html5/thumbnails/4.jpg)
Old Coding Rules
• Columns 1-6 and 73-80 optional and rarely used• Column 7 for continuation, comment, new page• Columns 8-72 for COBOL program statements• Column 7:
* (asterisk) designates entire line as comment
/ (slash) forces page break in source listing
- (dash) to indicate continuation of literal
![Page 5: The IDENTIFICATION and ENVIRONMENT DIVISIONS Chapter 2](https://reader030.vdocuments.site/reader030/viewer/2022032703/56649cfa5503460f949cb58b/html5/thumbnails/5.jpg)
Old Coding Rules
• Columns 8-72 divided into two areas– Area A - columns 8, 9, 10, 11– Area B - columns 12-72– (Also knows as Zone A and Zone B)
• Division, section and paragraph-names must all begin in Area A– First letter of name must begin in column 8, 9,
10 or 11– Entry may extend into Area B
![Page 6: The IDENTIFICATION and ENVIRONMENT DIVISIONS Chapter 2](https://reader030.vdocuments.site/reader030/viewer/2022032703/56649cfa5503460f949cb58b/html5/thumbnails/6.jpg)
Margin Rules
• All other statements, clauses, and sentences begin anywhere in Area B (column 12, 13, 14, etc.)– Select entries in ENVIRONMENT DIVISION– Data description entries in DATA DIVISION– All PROCEDURE DIVISION instructions
![Page 7: The IDENTIFICATION and ENVIRONMENT DIVISIONS Chapter 2](https://reader030.vdocuments.site/reader030/viewer/2022032703/56649cfa5503460f949cb58b/html5/thumbnails/7.jpg)
New Coding Rules
• Columns 1-80 for COBOL program statements• Column 1:
* (asterisk) designates entire line as comment
![Page 8: The IDENTIFICATION and ENVIRONMENT DIVISIONS Chapter 2](https://reader030.vdocuments.site/reader030/viewer/2022032703/56649cfa5503460f949cb58b/html5/thumbnails/8.jpg)
New Coding Rules
• Columns 1-80 divided into two areas– Area A - columns 1, 2, 3, 4– Area B - columns 5-80– (Also knows as Zone A and Zone B)
• Division, section and paragraph-names must all begin in Area A– First letter of name must begin in column 1, 2,
3 or 4– Entry may extend into Area B
![Page 9: The IDENTIFICATION and ENVIRONMENT DIVISIONS Chapter 2](https://reader030.vdocuments.site/reader030/viewer/2022032703/56649cfa5503460f949cb58b/html5/thumbnails/9.jpg)
Review of Margin Rules
• Division and Section Names– Begin in Area A, end with a period– Must appear on a line with no other entries
• Paragraph-names– Begin in Area A (or Zone A), end with period
followed by space– May appear on line by themselves or with
other entries
![Page 10: The IDENTIFICATION and ENVIRONMENT DIVISIONS Chapter 2](https://reader030.vdocuments.site/reader030/viewer/2022032703/56649cfa5503460f949cb58b/html5/thumbnails/10.jpg)
Review of Margin Rules
• Statements and Sentences– Begin in Area B (or Zone B)– May appear on line by themselves or with
other entries– Statements (e.g., OPEN, WRITE) may end
with period but not recommended– Sentences (e.g., a paragraph made up of one
or more statements) end with period followed by space
![Page 11: The IDENTIFICATION and ENVIRONMENT DIVISIONS Chapter 2](https://reader030.vdocuments.site/reader030/viewer/2022032703/56649cfa5503460f949cb58b/html5/thumbnails/11.jpg)
IDENTIFICATION DIVISION
• Provides identifying information about program
• Divided into paragraphs
• PROGRAM-ID only required paragraph
• Other paragraphs optional (up to ‘85) (Note: COBOL 2002 made all other paragraphs illegal – should be comments).
![Page 12: The IDENTIFICATION and ENVIRONMENT DIVISIONS Chapter 2](https://reader030.vdocuments.site/reader030/viewer/2022032703/56649cfa5503460f949cb58b/html5/thumbnails/12.jpg)
IDENTIFICATION DIVISION
• IDENTIFICATION DIVISION.• PROGRAM-ID. progname.
– Up to 8 characters– No ‘-’– Some operating systems use this name
• [AUTHOR. ]• [INSTALLATION. ]• [DATE-WRITTEN. ]• [DATE-COMPILED. ]• [SECURITY. ]
![Page 13: The IDENTIFICATION and ENVIRONMENT DIVISIONS Chapter 2](https://reader030.vdocuments.site/reader030/viewer/2022032703/56649cfa5503460f949cb58b/html5/thumbnails/13.jpg)
Understanding Instruction Formats
• Instruction formats describe syntax of all parts of COBOL language
• Describe required and optional elements, ordering and punctuation
• All formats in text are correct although additional options may be available
![Page 14: The IDENTIFICATION and ENVIRONMENT DIVISIONS Chapter 2](https://reader030.vdocuments.site/reader030/viewer/2022032703/56649cfa5503460f949cb58b/html5/thumbnails/14.jpg)
Rules for Instruction Formats
• Uppercase words are COBOL reserved words• Lowercase words are user-defined entries
IDENTIFICATION DIVISION.
PROGRAM-ID. program-name.
– DIVISION is reserved word– program-name is user-defined data-name
Example
![Page 15: The IDENTIFICATION and ENVIRONMENT DIVISIONS Chapter 2](https://reader030.vdocuments.site/reader030/viewer/2022032703/56649cfa5503460f949cb58b/html5/thumbnails/15.jpg)
Rules for Instruction Formats
• Underlined words are required• Punctuation if specified is required
IDENTIFICATION DIVISION. PROGRAM-ID. program-name.
– IDENTIFICATION, DIVISION required– PROGRAM-ID is required paragraph– Periods required after division header, paragraph
name and program-name
Example
![Page 16: The IDENTIFICATION and ENVIRONMENT DIVISIONS Chapter 2](https://reader030.vdocuments.site/reader030/viewer/2022032703/56649cfa5503460f949cb58b/html5/thumbnails/16.jpg)
Rules for Instruction Formats
• Brackets [ ] mean item is optional, braces { } mean one of enclosed items required
• Ellipses (. . .) mean entry may be repeated
IDENTIFICATION DIVISION.
PROGRAM-ID. program-name.
[AUTHOR. [comment-entry] …]
– AUTHOR paragraph optional– If included it may have any number of comment
entries
Example
![Page 17: The IDENTIFICATION and ENVIRONMENT DIVISIONS Chapter 2](https://reader030.vdocuments.site/reader030/viewer/2022032703/56649cfa5503460f949cb58b/html5/thumbnails/17.jpg)
ENVIRONMENT DIVISION
• Describes files and computer devices used to process them
• Required by programs that process files
• This division is machine-dependent since devices differ from computer to computer
• Only division that may change if program run on different computer
![Page 18: The IDENTIFICATION and ENVIRONMENT DIVISIONS Chapter 2](https://reader030.vdocuments.site/reader030/viewer/2022032703/56649cfa5503460f949cb58b/html5/thumbnails/18.jpg)
Sections of Environment Division
• CONFIGURATION SECTION– Describes computer used to compile/execute
program– Optional and recommended that you omit it
• INPUT-OUTPUT SECTION– Describes input and output files and devices
used by program– Required for all programs using files
![Page 19: The IDENTIFICATION and ENVIRONMENT DIVISIONS Chapter 2](https://reader030.vdocuments.site/reader030/viewer/2022032703/56649cfa5503460f949cb58b/html5/thumbnails/19.jpg)
INPUT-OUTPUT SECTION
• Follows CONFIGURATION SECTION (if coded)
• Includes FILE-CONTROL paragraph– Contains one SELECT statement for each file
used by program– Each SELECT defines a file-name and
assigns device name to that file
![Page 20: The IDENTIFICATION and ENVIRONMENT DIVISIONS Chapter 2](https://reader030.vdocuments.site/reader030/viewer/2022032703/56649cfa5503460f949cb58b/html5/thumbnails/20.jpg)
INPUT-OUTPUT SECTION
Format
INPUT-OUTPUT SECTION.FILE-CONTROL.
SELECT file-name-1 ASSIGN TO implementor-name-1 [ORGANIZATION IS LINE SEQUENTIAL].1
1Use this clause for all PC files so each line treated as separate record.
![Page 21: The IDENTIFICATION and ENVIRONMENT DIVISIONS Chapter 2](https://reader030.vdocuments.site/reader030/viewer/2022032703/56649cfa5503460f949cb58b/html5/thumbnails/21.jpg)
SELECT Statement file-names
• Choose meaningful file-names– EMPLOYEE-FILE instead of E-FILE– EMP-REPORT-FILE instead or OUT-FILE
• File-names are user-defined words– Words chosen by programmer to represent
some element of program
• Must follow rules for forming user-defined words
![Page 22: The IDENTIFICATION and ENVIRONMENT DIVISIONS Chapter 2](https://reader030.vdocuments.site/reader030/viewer/2022032703/56649cfa5503460f949cb58b/html5/thumbnails/22.jpg)
Rules for User-Defined Words
1. 1 to 30 characters
2. Letters, digits, hyphens (-) only
3. No embedded blanks
4. At least one alphabetic character
5. May not begin or end with hyphen
6. May not be COBOL reserved word
![Page 23: The IDENTIFICATION and ENVIRONMENT DIVISIONS Chapter 2](https://reader030.vdocuments.site/reader030/viewer/2022032703/56649cfa5503460f949cb58b/html5/thumbnails/23.jpg)
User-Defined Words
Valid• NUMBER-1-GRADE• GROSS-PAY• GROSSPAY• GROSS-PAYROLL• 2ND-QTR-EARNINGS• YTD-SOCIAL-
SECURITY-TAX• X100
Invalid• #1-GRADE• GROSS.PAY• GROSS PAY• -GROSS-PAYROLL• 2ND-QTR-EARN-• YEAR-TO-DATE-
SOCIAL-SECURITY-TAX• 100
![Page 24: The IDENTIFICATION and ENVIRONMENT DIVISIONS Chapter 2](https://reader030.vdocuments.site/reader030/viewer/2022032703/56649cfa5503460f949cb58b/html5/thumbnails/24.jpg)
SELECT implementer-names
• Special device-names exampleSelect Transaction-File Assign to Disk "Data1".Select Report-File Assign to Printer.
• Some systems use name of file stored on disk (VAX or Alpha systems)
Select Sales-File Assign to "SALES1.DATA".
![Page 25: The IDENTIFICATION and ENVIRONMENT DIVISIONS Chapter 2](https://reader030.vdocuments.site/reader030/viewer/2022032703/56649cfa5503460f949cb58b/html5/thumbnails/25.jpg)
Coding Guidelines
1. Separate divisions by blank comment line, page eject symbol or blank line
2. Code a single statement per line
3. Code paragraph-names on line by themselves
4. Be liberal in use of comments. Box lengthy comments using asterisks.
![Page 26: The IDENTIFICATION and ENVIRONMENT DIVISIONS Chapter 2](https://reader030.vdocuments.site/reader030/viewer/2022032703/56649cfa5503460f949cb58b/html5/thumbnails/26.jpg)
Coding Guidelines
5. Code SELECT statements in logical order (input files first, then output files) although order not required
6. Use separate lines for SELECT, ASSIGN, ORGANIZATION clauses for readability
7. Avoid use of device-specific file-names