Presentation is loading. Please wait.

Presentation is loading. Please wait.

2-1 Chapter 2.  Coding Requirements of IDENTIFICATION DIVISION  Sections of ENVIRONMENT DIVISION  Assigning Files to Devices in ENVIRONMENT DIVISION.

Similar presentations


Presentation on theme: "2-1 Chapter 2.  Coding Requirements of IDENTIFICATION DIVISION  Sections of ENVIRONMENT DIVISION  Assigning Files to Devices in ENVIRONMENT DIVISION."— Presentation transcript:

1 2-1 Chapter 2

2  Coding Requirements of IDENTIFICATION DIVISION  Sections of ENVIRONMENT DIVISION  Assigning Files to Devices in ENVIRONMENT DIVISION 2-2

3  Originally, each COBOL instruction coded on single line of 80 characters  Positions on line reserved for special purposes  Rules may differ for your compiler  Rigid column rules dropped in 2008  Be careful of these column rules, improper start of line location may cause a compiler error 2-3

4  Columns 1-6 and optional and rarely used today  Column 7 for continuation, comment, starting new page  Columns 8-72 for COBOL program statements  Usually I edit an existing program, that helps keep the columns straight.  Notice we start right at the edge, other versions may not (not exactly what the book says). 2-4

5 Column 7 * (asterisk) designates entire line as comment / (slash) forces page break when printing source listing - (dash) to indicate continuation of nonnumeric literal from the previous line. - experiment with this 2-5

6  Columns 8-72 divided into two areas ◦ Area A - columns 8, 9, 10, 11 ◦ Area B - columns  Division, section and paragraph-names must all begin in Area A ◦ First letter must begin in column 8, 9, 10 or 11 but we almost always start on 8 ◦ Entry may extend into Area B (of course, else we’d be in trouble) 2-6

7  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 2-7

8  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, end with period followed by space ◦ May appear on line by themselves or with other entries 2-8

9  Statements and Sentences ◦ Begin in Area 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  What are Divisions, Sections, Paragraphs & Sentences again? (Page 44 has nice diagram) 2-9

10 2- 10

11  Provides identifying information about program  Divided into paragraphs  PROGRAM-ID only required paragraph  Other paragraphs optional  First part of the program 2- 11

12 Format IDENTIFICATION DIVISION. PROGRAM-ID. program-name. [AUTHOR. [comment-entry] …] [other optional paragraphs] 2- 12

13  Author’s Policy for this book ◦ 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

14  Underlined words are required (as show in book)  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

15  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

16  Describes files and computer devices used to process data (open files for I/O)  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 is run on a different computer 2- 16

17  CONFIGURATION SECTION ◦ Describes computer used to compile/execute program ◦ Optional and recommended that you omit it ◦ We won’t be needing this.  INPUT-OUTPUT SECTION ◦ Describes input and output files and devices used by program ◦ Required for all programs using files 2- 17

18  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 2- 18

19 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. We probably won’t ever use this in this class because we’ll be telneting to the alpha INPUT-OUTPUT SECTION

20  Choose meaningful file-names ◦ EMPLOYEE-FILE instead of E-FILE ◦ EMP-REPORT-FILE instead or OUT-FILE  File-names are user-defined words  Must follow rules for forming user-defined words (next slide) 2- 20

21 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 2- 21

22 Conventions for these names vary widely among computers Most enable use of special device names for frequently used devices Printer SYSLST, SYS$OUT, PRINTER Disk DISC or DISK and disk file-name 2- 22

23 Special device-names example Select Transaction-File Assign to Disk "Data1". Select Report-File Assign to Printer. VAX or Alpha systems use Select Sales-File Assign to "Sales1"

24  For PCs, use device names specifying ◦ Drive on which file appears followed by a colon ◦ Folder name if file is in a folder ◦ Name of file  PC example Select Inventory-File Assign To "C:\Inventory\Inv-File.dat". ◦ May want to experiment with this but we’ll be running programs on the vax so it may not work

25  This clause describes organization of records in the file  Most PC disk files created as text files ◦ Following data for each record, Enter key is pressed ◦ Indicates end of the line and end of the record ◦ If record is 80 characters or less, each record appears on single line on screen or printer 2- 25

26  Include LINE SEQUENTIAL to ◦ Correctly read records from files when Enter key used to mark the end of each record ◦ Create disk files with each record followed by Enter key so each record appears on separate line when printed 2- 26

27 PC Example Select Sales-File Assign to "C:\Chapter2\Sales.dat" Organization is Line Sequential

28 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

29 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 2- 29

30  Coding rules for Margins A and B will be recommended not required.  PROGRAM-ID will be only paragraph in IDENTIFICATION DIVISION. All others can be specified as comments.  Length of user-defined words will be increased from 30 to 60 characters

31  IDENTIFICATION DIVISION ◦ Defines program name ◦ Program name up to eight characters, letters and digits only, acceptable on all computers ◦ PROGRAM-ID is only required paragraph, all others optional ◦ Use comments by coding an * in column

32  ENVIRONMENT DIVISION ◦ Division is optional for COBOL 85 ◦ Not needed for fully interactive programs  Lack of IO via files ◦ INPUT-OUTPUT SECTION required for any program using files ◦ Only machine-dependent division since device specification, file-name rules vary among computers 2- 32


Download ppt "2-1 Chapter 2.  Coding Requirements of IDENTIFICATION DIVISION  Sections of ENVIRONMENT DIVISION  Assigning Files to Devices in ENVIRONMENT DIVISION."

Similar presentations


Ads by Google