Presentation is loading. Please wait.

Presentation is loading. Please wait.

The IDENTIFICATION and ENVIRONMENT DIVISIONS Chapter 2.

Similar presentations


Presentation on theme: "The IDENTIFICATION and ENVIRONMENT DIVISIONS Chapter 2."— Presentation transcript:

1 The IDENTIFICATION and ENVIRONMENT DIVISIONS Chapter 2

2 Chapter Contents Basic Structure of a COBOL Program Coding Requirements of IDENTIFICATION DIVISION Sections of ENVIRONMENT DIVISION Assigning Files to Devices in ENVIRONMENT DIVISION

3 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.

4 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

5 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

6 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

7 New Coding Rules Columns 1-80 for COBOL program statements Column 1: * (asterisk) designates entire line as comment

8 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

9 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

10 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

11 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).

12 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. ]

13 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

14 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

15 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

16 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

17 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

18 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

19 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

20 INPUT-OUTPUT SECTION Format INPUT-OUTPUT SECTION. FILE-CONTROL. SELECT file-name-1 ASSIGN TO implementor-name-1 [ORGANIZATION IS LINE SEQUENTIAL]. 1 1 Use this clause for all PC files so each line treated as separate record.

21 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

22 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

23 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

24 SELECT implementer-names Special device-names example Select 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".

25 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.

26 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


Download ppt "The IDENTIFICATION and ENVIRONMENT DIVISIONS Chapter 2."

Similar presentations


Ads by Google