Presentation is loading. Please wait.

Presentation is loading. Please wait.

1 IDENTIFICATION and ENVIRONMENT DIVISIONS. 2 Objectives Basic Structure of COBOL Programs General Coding and Formatting Rules Identification and the.

Similar presentations


Presentation on theme: "1 IDENTIFICATION and ENVIRONMENT DIVISIONS. 2 Objectives Basic Structure of COBOL Programs General Coding and Formatting Rules Identification and the."— Presentation transcript:

1 1 IDENTIFICATION and ENVIRONMENT DIVISIONS

2 2 Objectives Basic Structure of COBOL Programs General Coding and Formatting Rules Identification and the Environment Divisions – –Old and new.

3 3 Divisions in a COBOL Program IDENTIFICATION DIVISION –Identifies your program to the computer –Provides a program-id and other optional information describing your program ENVIRONMENT DIVISION –Describes the environment within which your program must operate. –Sets up relationships (Select statement) between your physical files on disk and your program-name (logical name) for these files within your program. DATA DIVISION –Describes all input and output files and their formats –Describes all supporting working areas such as tables, print lines, counters, accumulators, and similar independent items. PROCEDURE DIVISION –Contains the program logic of your program – your instructions. Sequence, Selection, Iteration statements

4 4 Programming Area in Net Express Each line holds about 80 columns room for around twenty statements Each line ‘should’ contain a single COBOL entry (instruction, data…) Positions 1-6 and 73-80 will not be used in this course. Columns 1-6 were used to enter statement numbers; columns 73-80 were used to enter a program-id Column 7: Very useful: Placing an asterisk (*) in column 7 causes the compiler to treat the entire line as a comment. These are used a lot to internally document your program. Use of a dash ‘-’ in column 7 can be used to indicate the the continuation of a nonnumeric literal (a string of characters). A slash (/) in column 7 (only entry in line) causes the source program listing to be continued on the next page if you are seeking hard copy listing of your program. Nice for printing different modules on separate pages.

5 5 Main Coding Areas Area A (column 8-11):. All division, section, and paragraph entries should start within this area. Clearly these may extend beyond column 11. Area B (column 12-72):. All statements and sentences must start in this area A number of other program entries will start in column 12 too – by our conventions. The new COBOL 2002 Standard does not discuss Areas A and B very explicitly. But the likelihood of your running into older COBOL programs requiring maintenance is very high. So, we will ‘modestly’ refer to these areas.

6 6 Let’s take a look: Sample from my web page: http://www.unf.edu/~broggio/cop2120/P6.cbl

7 7 IDENTIFICATION DIVISION. PROGRAM-ID. GRADE-TABLES. AUTHOR. author's name omitted. DATE-WRITTEN. 04/17/06 DATE-COMPILED. ENVIRONMENT DIVISION. INPUT-OUTPUT SECTION. FILE-CONTROL. SELECT STUDENT-REC ASSIGN TO "C:\COP2120\P6\MumboJumbo\2120P5FL.TXT" ORGANIZATION IS LINE SEQUENTIAL. SELECT REG-PRINT-REC ASSIGN TO "C:\COP2120\P6\MumboJumbo\REG-REPORT.TXT" ORGANIZATION IS LINE SEQUENTIAL. SELECT SPEC-PRINT-REC ASSIGN TO "C:\COP2120\P6\MumboJumbo\SPEC-REPORT.TXT" ORGANIZATION IS LINE SEQUENTIAL.

8 8

9 9 Divisions and Sections and Paragraphs Divisions: identification, environment, data, and procedure Ordered. Must appear in order (Environment Division does not ‘have’ to appear, but…) Most are divided into Sections Many Sections are divided into paragraphs. All division, section, and paragraph entries must end with a period. Division and section entries must reside on a line by themselves. Example: Environment Division. Configuration section. Source-computer. PC. Object-computer. PC. Special-names.. Insofar as statements and sentences, these may appear on lines by themselves and with other entries. Example: move spaces to print-rec. add 1 to result. /* Do one statement per line – convention */

10 10 Coding the Identification Division Small, simplest division of a COBOL program. Is required to identify your program to system. Contents does not affect program execution Identification division: no sections, only paragraphs. Program-id is the only required paragraph.. All A-margin (A area) entries.

11 11 Syntax of Identification Division Identification Division. Program-id. Program-name. [Author. [Comment-entry]...] [Installation. [Comment-entry]...] [Date-written. [Comment-entry]...] [Date-compiled. [Comment-entry]...] [Security. [Comment-entry]...] Comments : Upper case: COBOL reserved words; special meaning Lower case: programmer-defined Underlined: required entries Punctuation: if specified, it is required. Brackets: option entry Braces: (not shown above): must select the entity or one of the items enclosed in the braces. Later Dots or ellipses (...) means repeated occurrences of preceding items. Called: BNF - Backus Naur Form (Backus normal form) A metalanguage  Discuss...

12 12 Environment Division Machine-dependent division of a COBOL program Entries are dependent upon the hardware associated. Two sections: Configuration section. (no longer required) Configuration section supplies information on the computer system (source computer and object computer paragraphs) and a few other items. Input-output section. Input-output section names files and associates them with devices. Typically, this is the division that may be changed from computer system to computer system. Older view of COBOL programs might include: Environment division. Configuration section. Source-computer. IBM-370. Object-computer. IBM-370. Note: if entries for source and object computer are used, characters must be contiguous (no embedded spaces) and must be followed with a period.

13 13 Environment Division Input-Output Section. Name the devices used in the program and Associate a filename with these devices. (In the file-control paragraph) Most of these entries are machine and computing system dependent, while only one part is programmer-defined. File-control paragraph consists of select statements: One select statement per file. Most computer applications have at least one input and one output file - but others may have several of each! Syntax: Select input-transaction-file Assign to “C:\cop2120\p2\BobRoggio\indata.txt” Organization is line sequential. Select master-employee-file Assign to “C:\cop2120\p2\masterfile.dat” Organization is line sequential. Select report-file Assign to “C:\cop2120\p2\output.txt”. Discuss: logical (internal) file names vs external file names. (If extension is.txt, may open with Notepad..dat should be accessed via WordPad)

14 14 Rules for the Select Statements Rules. use two or three lines for select statements. The file-name-1, like all programmer-defined names, must conform with: 1-30 characters, Letters, digits, hyphens only; No embedded spaces At least one alphabetic character Cannot use any COBOL reserved words (words that have special meaning to the COBOL compiler) (Names should be meaningful and connote proper representation. E.G., Employee-file not "infile" - although i may use these as examples) Implementor names or device specifications Varies widely from manufacturer to manufacturer. Have shown formats to be used using NetExpress.

15 15 More on Select Statements IBM mainframes use different forms: Examples: Select emp-file assign to ut-s-infile. Select junk-file assign to da-i-myfile. Recognize that this is a standard part of a COBOL program that very frequently is changed when you are moving your COBOL program from one machine to another - particularly between machines manufactured by different vendors!! You can count on this. Whenever you move a program, you will need to find out the new system's select statement formats with regard to the implementation names. Device classes may be ‘ur’ ‘ut’ or ‘da’ (Unit record, utility, or direct access) ur used for: readers, printers, punches, and terminals; ut used for tapes and disk files accessed sequentially; and da used for direct access disk files.) S ==> sequential files; I ==> indexed sequential file; R ==> relative or random files; D ==> direct access;

16 16 Coding Conventions (Standards) Coding guidelines: see standards!!! See my web page. These standards will be rigidly enforced. Don't use page eject on program listings handed in to me. Do have a single statement per line. (Several statements require two lines. So far: The Select statement) Have all division, section, and paragraph names by themselves on a line. (Division and section entries require their own line. Syntactically, paragraph names are permitted on a line with other code. But don't do this. All paragraph entries on their own line. Use comments liberally! (See standards...) Use meaningful file and data field names such as employee-file or payroll-file

17 17 Know these things: Divisions SectionsParagraphs (Know this hierarchy) Identification Division. Program-id. (Required). Author. Installation. Date-written. Date-compiled. Security. Environment Division. Configuration Section.(optional) Source-computer. Object-computer. Special-names. Input-output Section. File-control. Select statements…. Data Division. Coming….. File Section. Working-Storage Section. Procedure Division. (procedure division has user-defined sections and paragraph names.)


Download ppt "1 IDENTIFICATION and ENVIRONMENT DIVISIONS. 2 Objectives Basic Structure of COBOL Programs General Coding and Formatting Rules Identification and the."

Similar presentations


Ads by Google