1 / 44

Chapter 4 The Identification, Environment, and Data Divisions

Chapter 4 The Identification, Environment, and Data Divisions. COBOL CODING RULES. Comments * column 7 Must start in Area A (columns 8 -11) Divisions Sections Paragraphs FD’s - file descriptions 01’s - record descriptions Must start in Area B (columns 12 -72) Everything else.

drew
Download Presentation

Chapter 4 The Identification, Environment, and Data Divisions

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Chapter 4The Identification,Environment, andData Divisions

  2. COBOL CODING RULES • Comments * column 7 • Must start in Area A (columns 8 -11) • Divisions • Sections • Paragraphs • FD’s - file descriptions • 01’s - record descriptions • Must start in Area B (columns 12 -72) • Everything else

  3. GREATER THAN LESS THANEQUAL TO identifier-1 GREATER THAN OR EQUAL TO identifier-2IF literal-1 IS [ NOT ] LESS THAN OR EQUAL TO literal-2 arithmetic expression-1 > arithmetic expression-2 < = >= <= Choice required Programmer supplied Optional entry Optional reserved words Required word Figure 4.1 COBOL Notation

  4. 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. RULES FOR INTERPRETING INSTRUCTION FORMATS • 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 if desired.

  6. The IDENTIFICATION DIVISION • first of the four divisions in a COBOL program • consists of a division header and up to six paragraphs: • provides identifying information about the program, • author • date written • security.

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

  8. ENVIROMENT DIVISION • Contains two sections • Configuration Section. (optional) • Input-Output Section. • Associates COBOL file names with Operating System file names • The one area in the program that is likely to need change from one platform to another

  9. SELECT STATEMENT One required for every file used by the programSELECT file-name-1 ASSIGN TO { implementor-name-1 / literal} [ORGANIZATION IS [LINE]SEQUENTIAL]ex. SELECT Student-File ASSIGN TO “c:\records\student.dat” ORGANIZATION IS LINE SEQUENTIAL

  10. 1 to 30 characters Letters, digits, and hyphens (-) only No embedded blanks. At least one alphabetic character. May not begin or end with a hyphen. No COBOL reserved words such as D A T A D I V I S I 0 N, etc. RULES FOR FORMING USER-DEFINED WORDS

  11. User Defined Names • Date-In • Employee Name • Discount-% • Name-Out • Input • 123 • Last-Name-In • Input-File

  12. DATA DIVISION • The DATA DIVISION is that part of a COBOL program that defines and describes fields, records, and files in storage. • Any area of storage that is required for the processing of data must be established in the DATA DIVISION.

  13. DATA DIVISION • Consists of one or more Sections • FILE SECTION • describes all input and output files • WORKING STORAGE SECTION • reserves storage for fields not part of input or output but required for processing. These include constants, end-of- file indicators, and work areas

  14. FD - File Description Entries • Need an FD for each SELECT entry • Each file is described in the FILE SECTION • An FD sentence that may consist of a series of clauses. • The FD sentence ends with a period.

  15. FILE DESCRIPTION ENTRIES • An example: SELECT INVENTORY-FILE ASSIGN TO DISK1. SELECT ERROR-LIST ASSIGN TO PRINTER. * DATA DIVISION. FILE SECTION. FD INVENTORY-FILE . FD ERROR-LIST .

  16. FD FDfile-name-1 [ LABELRECORD(S) ARE {STANDARD, OMITTED][ RECORD CONTAINS integer-1 CHARACTERS ] [ BLOCK CONTAINS integer-2 RECORDS] [ DATARECORD(S) {IS, ARE} data-name-1 ... ] .

  17. LABEL RECORD(S) Clause - • What Is a Label Record? • Usually created as the first and last records of a disk or tape file • Provides identifying information about the file • Can be used to check if the correct file is being accessed for a specific program.

  18. LABEL RECORD(S) Clause - • LABEL RECORDS ARE STANDARD • Only for magnetic media such as disk. • LABEL RECORDS ARE OMITTED • Used for printed files since they do not use label records. • Sometimes a disk file may also not have any labels

  19. RECORD CONTAINS Clause --(Optional) • The RECORD CONTAINS clause indicates the size of each record. • A print file, for example, may have the following entry: • RECORD CONTAINS 80 CHARACTERS

  20. RECORD CONTAINS Clause -- • Record Size for Print Files • PC printers usually print 80 or 1100 characters per line.. • Mainframes and minicomputers print 132 characters per line. • Record Size for Disk Files • For disk files, the RECORD CONTAINS clause varies.

  21. DEBUGGING TIP • The RECORD CONTAINS • recommended to check on record size • easier to detect and fix errors at compile-time rather than at run-time • if the sum characters in the PICTURE clause(s) are greater than the RECORD CONTAINS clause some compiler reports an error

  22. BLOCK CONTAINS Clause - (Optional) • Format • BLOCK CONTAINS integer-1 RECORDS

  23. BLOCK CONTAINS Clause • Included in the File Description entry only for files on magnetic media • A group of logical records is included within one block to maximize the efficient use of a disk area.

  24. | ADAMS | | BAKER | | BROWN | | CHARLES | | DAVIS | | EDISON | | ADAMS | BAKER | |BROWN | CHARLES | | DAVIS | EDISON | | ADAMS | BAKER |BROWN | | CHARLES | DAVIS | EDISON | Figure 4.2 Blocked versus Unblocked Records (a) Unblocked Records(One Logical Record per Physical Record) (b) Blocking Factor of Two(Two Logical Records per Physical Record) (b) Blocking Factor of Three(Three Logical Records per Physical Record)

  25. RULES FOR CODING FILE DESCRIPTION ENTRIES • FD is coded in Area A. • Other entries coded in Area B. • No period is coded until the last clause. • Recommend that each clause appear on a separate line for clarity and ease of debugging.

  26. FD - FILE DESCRIPTION • FD STUDENT-FILE • LABEL RECORDS ARE STANDARD • RECORD CONTAINS 43 CHARACTERS • BLOCK CONTAINS 10 RECORDS • DATA RECORD IS STUDENT-IN.

  27. DATA RECORD(S) IS Clause • Specifies the names of the 01 entry(s)

  28. STUDENT-EXAM-RECORD STUDENT-NAME SS-NUM EXAM-SCORES MATH ENGLISH LASTNAME FIRSTNAME INIT ALG GEO READ VOC LIT 1 15 16 30 31 32 40 41 45 46 50 51 55 56 60 61 65 ALPHANUMERIC NUMERIC Figure 4.3 Student Exam Record

  29. RECORD DESCRIPTION(S) • For each data item (field) - identifies • SIZE • DATE TYPE • NUMERIC 9 • ALPHANUMERIC X • ALPHA A • EDITED • ORDER IN WHICH THEY APPEAR • RELATIONSHIP TO OTHER FIELDS

  30. DATA RECORD(S) IS Clause • PICTURE (PIC) clause used to specify size and data type • PIC X(5) = PIC XXXXX. • LEVEL NUMBERS describe the relationship between fields • All record descriptions begin with 01 • 01 must be coded in AREA A

  31. DATA RECORD(S) IS Clause • LEVEL NUMBERS • 01 denotes the record’s name • 02 - 49 used to denote field names • GROUP ITEMS • Can be further divided • No PICTURE clause • type assumed X • size is sum of its elementary items

  32. DATA RECORD(S) IS Clause • ELEMENTARY ITEMS • Can’t be further divided • must contain a picture clause • level number must be greater than itsgroup’s level number • FIELD NAMES • Meaningful • Follow COBOL rules for User- Defined Words

  33. DATA RECORD(S) IS Clause • FILLER • COBOL reserved word • Defines field(s) not referenced • Word is optional but entry must contain PICTURE clause

  34. RECORD DESCRIPTION 01 STUDENT-EXAM-RECORD. 04 STUDENT-NAME. 08 LAST-NAME PIC X(15). 08 FIRST-NAME PIC X(15). 08 MID-INITIAL PIC X. 04 SOC-SEC-NUM PIC 9(9). 04 EXAM-SCORES. 08 MATH. 12 ALGEBRA PIC 99999. 12 GEOMETRY PIC 99999.. 08 ENGLISH. 12 READING PIC 99999. 12 VOCABULARY PIC 99999. 12 LITERATURE PIC 99999.

  35. Figure 4.5 Assumed Decimal Point INCOMING RECORD DATA DIVISION RECORDDESCRIPTION LOGICALVALUES 01 INCOMING-DATA-RECORD. 05 STUDENT-NAME PIC 9V99. 05 STUDENT-NAME PIC 99V9. 05 STUDENT-NAME PIC 9. 05 STUDENT-NAME PIC V999. 9.87 65.4. 3 .210 vvv9 87|65 4|3 | 210

  36. FD STUDENT-FILE RECORD CONTAINS 27 CHARACTERS.01 STUDENT-RECORD. 05 STU-NAME. 10 STU-LAST-NAME PIC X(15). 10 STU-INITIALS PIC XX. 05 STU-CREDITS PIC 9(2). 05 STU-UNION-MEMBER PIC X. 05 STU-SCHOLARSHIP PIC 9(4). 05 STU-GPA PIC 9V99. (b) COBOL Entries Figure 4.7 Development of a COBOL Program (File Section) CREDITS UNION MEMBER INITIALS SCHOLARSHIP STUDENT NAME GPA LAST 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 (a) Program Specifications

  37. Figure 4.8 Development of a COBOL Program (Constants and Rates) 1. Calculate tuition due at the rate of $200 per credit.2. The union fee is $25.3. Compute the activity fee based on the number of credits taken; $25 for 6 credits or less, $50 for 7 to 12 credits, $75 for more than 12 credits.4. Award a scholarship equal to the amount in the incoming record if, and only if, the GPA is greater than 2.5.

  38. Figure 4.8 Development of a COBOL Program (Constants and Rates) WORKING-STORAGE SECTION.01 CONSTANTS-AND-RATES. 05 PRICE-PER-CREDIT PIC 9(3) VALUE 200. 05 UNION-FEE PIC 9(2) VALUE 25. 05 ACTIVITY-FEES. 10 1ST-ACTIVITY-FEE PIC 99 VALUE 25. 10 1ST-CREDIT-LIMIT PIC 99 VALUE 6. 10 2ND-ACTIVITY-FEE PIC 99 VALUE 50. 10 2ND-CREDIT-LIMIT PIC 99 VALUE 12. 10 3RD-ACTIVITY-FEE PIC 99 VALUE 75. 05 MINIMUM-SCHOLARHSIP-GPA PIC 9V9 VALUE 2.5. (b) COBOL Entries

  39. VALUE clause • Initializes the contents of a data name • Can only be used in WORKING-STORAGE SECTION • VALUE IS literal • Numeric • Alphanumeric -- enclosed in quotes • Figurative Constant • SPACE(S) • ZERO(S) • ALL

  40. Figure 4.9 Development of a COBOL Program (Print Lines) (a) Report Layout

  41. Figure 4.9 Development of a COBOL Program (Print Lines) 01 HEADING-LINE. 05 FILLER PIC X VALUE SPACES. 05 FILLER PIC X(12) VALUE ‘STUDENT NAME’. 05 FILLER PIC X(10) VALUE SPACES. 05 FILLER PIC X(7) VALUE ‘CREDITS’. 05 FILLER PIC X(2) VALUE SPACES. 05 FILLER PIC X(7) VALUE ‘TUITION’. 05 FILLER PIC X(2) VALUE SPACES. 05 FILLER PIC X(9) VALUE ‘UNION FEE’. 05 FILLER PIC X(2) VALUE SPACES. 05 FILLER PIC X(7) VALUE ‘ACT FEE’. 05 FILLER PIC X(2) VALUE SPACES. 05 FILLER PIC X(11) VALUE ‘SCHOLARSHIP’. 05 FILLER PIC X(2) VALUE SPACES. 05 FILLER PIC X(10) VALUE ‘TOTAL BILL’. 05 FILLER PIC X(48) VALUE SPACES. (b) COBOL Entries

  42. Figure 4.9 Development of a COBOL Program (Print Lines) 01 DETAIL-LINE. 05 PIC X VALUE SPACES. 05 DET-LAST-NAME PIC X(15). 05 PIC X(2) VALUE SPACES. 05 DET-INITIALS PIC X(2). 05 PIC X(5) VALUE SPACES. 05 DET-CREDITS PIC 9(2). 05 PIC X(2) VALUE SPACES. 05 DET-TUITION PIC 9(6). 05 PIC X(7) VALUE SPACES. 05 DET-UNION-FEE PIC 9(3). 05 PIC X(8) VALUE SPACES. 05 DET-SCHOLARSHIP PIC 9(5). 05 PIC X(6) VALUE SPACES. 05 DET-IND-BILL PIC 9(6). 05 PIC X(49) VALUE SPACES. (b) COBOL Entries

  43. Figure 4.9 Development of a COBOL Program (Print Lines) 01 TOTAL-LINE. 05 PIC X(4) VALUE SPACES. 05 PIC X(14) VALUE “STUDENT TOTALS”. 05 PIC X(2) VALUE SPACES. 05 TOT-STUDENTS PIC 9(3) VALUE ZEROS.. 05 PIC X(110) VALUE SPACES. 01 DASHED-LINE. 05 PIC X(132). VALUE ALL ‘-’.. (b) COBOL Entries

  44. End of Chapter 4

More Related