Presentation is loading. Please wait.

Presentation is loading. Please wait.

Lecture 21 ENVIRONMENT DIVISION  defines files external to the program and devices.  contains two sections: 1.CONFIGURATION SECTION.  identifies computers.

Similar presentations


Presentation on theme: "Lecture 21 ENVIRONMENT DIVISION  defines files external to the program and devices.  contains two sections: 1.CONFIGURATION SECTION.  identifies computers."— Presentation transcript:

1 lecture 21 ENVIRONMENT DIVISION  defines files external to the program and devices.  contains two sections: 1.CONFIGURATION SECTION.  identifies computers for compiling and executing the program SOURCE-COMPUTER. system-name.  the computer that will be used for compiling the program OBJECT-COMPUTER. system-name.  the computer that will be used for executing or running the program 2. INPUT-OUTPUT SECTION.  associates files in a COBOL program with files known to the OS

2 lecture 22 INPUT-OUTPUT SECTION  supplies information concerning the input and output devices used in the program [INPUT-OUTPUT SECTION. FILE-CONTROL. SELECT file-name ASSIGN TO implementor-name.]  FILE-CONTROL paragraph  SELECT statements start in Area B followed by a period.  file-name = name used in program.  implementor-name = device on which file resides (i.e., file path and name on disk in our case)  varies from compiler to compiler

3 lecture 23 DATA DIVISION  Data items that appear in the program DATA DIVISION. [FILE SECTION. [FD file-description-entry record-description-entry ] [WORKING STORAGE SECTION. [ record-description-entry...]]

4 lecture 24 DATA DIVISION  FILE SECTION  Define an FD for every file  I.e., for every SELECT statement in the ENVIRONMENT DIVISION.  File type (input or output file information)  The “physical characteristics” of these files must be defined exactly  WORKING-STORAGE SECTION (note the hyphen)  Reserves memory for non-I/O fields, e.g. variables and constants  Defines output lines (Printing reports, results, etc.)

5 lecture 25  FD (File Description) statement FD file-name [BLOCK CONTAINS integer-1 RECORDS] [RECORD CONTAINS integer-2 CHARACTERS]  BLOCK CONTAINS (block description) statement (optional)  RECORD CONTAINS (record description) statement (optional) FILE SECTION

6 lecture 26  BLOCK CONTAINS  Specify blocking factor (# records per disk sector)  Higher the factor fewer physical operations  Too low-level for us. OS does it for us.  Optional.  RECORD CONTAINS  Indicates the number of characters in a record  The compiler verifies the sum of individual data item sizes against the declared value  Optional. FILE SECTION

7 lecture 27 RECORD DESCRIPTION FD is followed by an associated record description :  Size and type of each field within a record  Order in which the fields appear  Relationship of the fields to one another Done through a combination of:  PICTURE CLAUSES  LEVEL NUMBERS

8 lecture 28 Picture Clauses  Describe the type and size of a field  Only three data types: Alphanumeric (PIC X) Numeric (PIC 9) Alphabetic (PIC A)  Format size is indicated by the number of times 9, X, or A appear  XXXX is the same as X(4)  Can use PICTURE IS, PICTURE, PIC IS, PIC  S denotes sign and appears at the beginning of PIC  Assumed decimal point –Use of a V, PIC 9V99 can hold 1.23

9 lecture 29 INCOMING RECORDDATA DIVISION RECORD DESCRIPTION VALUES v v v 9 87|65 4|3 | 210 01 INCOMING-DATA-RECORD. 05 STUDENT-NAME PIC 9V99. 05 STUDENT-NAMEPIC 99V9. 05 STUDENT-NAMEPIC 9. 05 STUDENT-NAMEPIC V999. 9.87 65.4. 3.210 Assumed Decimal Point

10 lecture 210 VALUE Clause  Initialize contents of a field with literals.  Literals  Numeric : VALUE 3.00  Non-numeric : VALUE ‘ENGINEERING’  Figurative constants : VALUE SPACES  SPACE or SPACES, ZERO or ZEROS, QUOTE or QUOTES, ALL literal

11 lecture 211 Level numbers LEVEL Numbers express DATA hierarchy Describe the relationship between the fields in the record Order in which the fields appear matter Valid levels numbers between 01 to 49 01 level is the record-name; highest level of data (Starts in Area A) Items : 02 - 49 (Start in Area B) –Group - can be further divided, cannot have PIC claus –Elementary - cannot be further divided, must have PIC clause Levels with the same number are independent items Lower levels of data have higher level #’s Indentation is not required, but good for readability Group item names end with a period

12 lecture 212 STUDENT-EXAM-RECORD STUDENT-NAMEEXAM-SCORESSS-NUM LAST NAME FIRST NAME INIT MATHENGLISH ALGGEOREADVOCLIT 1 15 16 30 31 32 40 41 45 46 50 51 55 56 60 61 65 ALPHANUMERICNUMERIC Student Exam Record

13 lecture 213 01 STUDENT-EXAM-RECORD. 05 STUDENT-NAME. 10 LAST-NAMEPICTURE IS X(15). 10 FIRST-NAMEPICTURE IS X(15). 10 MID-INITIALPICTURE IS X. 05 SOC-SEC-NUMPICTURE IS 9(9). 05 EXAM-SCORES. 10 MATH. 15 ALGEBRAPICTURE IS 9(5). 15 GEOMETRYPICTURE IS 9(5). 10 ENGLISH. 15 READINGPICTURE IS 9(5). 15 VOCABULARYPICTURE IS 9(5). 15 LITERATUREPICTURE IS 9(5). 01 STUDENT-EXAM-RECORD. 04 STUDENT-NAME. 08 LAST-NAMEPIC X(15). 08 FIRST-NAMEPIC X(15). 08 MID-INITIALPIC X. 04 SOC-SEC-NUMPIC 9(9). 04 EXAM-SCORES. 08 MATH. 12 ALGEBRAPIC 99999. 12 GEOMETRYPIC 99999.. 08 ENGLISH. 12 READINGPIC 99999. 12 VOCABULARYPIC 99999. 12 LITERATUREPIC 99999. (a) Initial Coding (b) Alternative Specification Level Numbers and PICTURE Clauses

14 lecture 214 WORKING-STORAGE SECTION  Defines data names not referenced in the FILE SECTION.  Stores results of calculations, flags, switch control, constants  Used to define print lines (headings and details)  Intermediate data storage  FILLER (reserved word)  Defines a field not referenced elsewhere in the program  Typically holds spaces or constants  The word can be omitted (is optional)  Can be used to denote format of a print line WORKING-STORAGE SECTION. 01 HEADING LINE. 05 FILLER PIC X(10) VALUE SPACES. 05 PIC X(12) VALUE ‘STUDENT NAME’. 05 PIC X(110) VALUE SPACES.

15 lecture 215 COUNTERS and ACCUMULATORS  Counters and accumulators compute totals and/or averages.  Defined in the DATA DIVISION and given initial values: 01 COUNTERS-AND-ACCUMULATORS. 05 EMPLOYEE-COUNT PIC 999 VALUE ZERO. 05 TOTAL-PAY-AMOUNT PIC 9(6)V99 VALUE ZERO.  COBOL has reserved words that you cannot use for variable names.  You cannot use the word "COUNT" as a variable name, so use something descriptive like "EMPLOYEE-COUNT".

16 lecture 216 (b) COBOL Entries 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-CREDITSPIC 9(2). 05 STU-UNION-MEMBER PIC X. 05 STU-SCHOLARSHIP PIC 9(4). 05 STU-GPAPIC 9V99. STUDENT NAME LAST GPA INITIALS CREDITSUNION MEMBER SCHOLARSHIP (a) Program Specifications 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 Development of a COBOL Program (File Section)

17 lecture 217 (b) COBOL Entries WORKING-STORAGE SECTION. 01 CONSTANTS-AND-RATES. 05 PRICE-PER-CREDIT PIC 9(3) VALUE 200. 05 UNION-FEEPIC 9(2) VALUE 25. 05 ACTIVITY-FEES. 10 1ST-ACTIVITY-FEEPIC 99 VALUE 25. 10 1ST-CREDIT-LIMITPIC 99 VALUE 6. 10 2ND-ACTIVITY-FEEPIC 99 VALUE 50. 10 2ND-CREDIT-LIMITPIC 99 VALUE 12. 10 3RD-ACTIVITY-FEEPIC 99 VALUE 75. 05 MINIMUM-SCHOLARHSIP-GPA PIC 9V9 VALUE 2.5. (a) Excerpt from the Program Specifications 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, and $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. Development of a COBOL Program (Constants and Rates)

18 lecture 218 (a) Report Layout Development of a COBOL Program (Print Lines)

19 lecture 219 (b) COBOL Entries 01 HEADING-LINE. 05 FILLERPIC X VALUE SPACES. 05 FILLERPIC X(12) VALUE ‘STUDENT NAME’. 05 FILLERPIC X(10) VALUE SPACES. 05 FILLERPIC X(7) VALUE ‘CREDITS’. 05 FILLERPIC X(2) VALUE SPACES. 05 FILLERPIC X(7) VALUE ‘TUITION’. 05 FILLERPIC X(2)VALUE SPACES. 05 FILLERPIC X(9)VALUE ‘UNION FEE’. 05 FILLERPIC X(2)VALUE SPACES. 05 FILLERPIC X(7)VALUE ‘ACT FEE’. 05 FILLERPIC X(2)VALUE SPACES. 05 FILLERPIC X(11)VALUE ‘SCHOLARSHIP’. 05 FILLERPIC X(2)VALUE SPACES. 05 FILLERPIC X(10)VALUE ‘TOTAL BILL’. 05 FILLERPIC X(48)VALUE SPACES. 01 DETAIL-LINE. 05 FILLERPIC X VALUE SPACES. 05 DET-LAST-NAMEPIC X(15). 05 FILLERPIC X(2) VALUE SPACES. 05 DET-INITIALSPIC X(2). 05 FILLERPIC X(5) VALUE SPACES. 05 DET-CREDITSPIC 9(2). 05 FILLERPIC X(2)VALUE SPACES. 05 DET-TUITIONPIC 9(6). 05 FILLERPIC X(7)VALUE SPACES. 05 DET-UNION-FEEPIC 9(3). 05 FILLERPIC X(8)VALUE SPACES. 05 DET-SCHOLARSHIPPIC 9(5). 05 FILLERPIC X(6)VALUE SPACES. 05 DET-IND-BILLPIC 9(6). 05 FILLERPIC X(49)VALUE SPACES. Development of a COBOL Program (Print Lines)


Download ppt "Lecture 21 ENVIRONMENT DIVISION  defines files external to the program and devices.  contains two sections: 1.CONFIGURATION SECTION.  identifies computers."

Similar presentations


Ads by Google