Lecture 21 ENVIRONMENT DIVISION defines files external to the program and devices. contains two...
-
Upload
lambert-fitzgerald -
Category
Documents
-
view
215 -
download
1
Transcript of Lecture 21 ENVIRONMENT DIVISION defines files external to the program and devices. contains two...
lecture 2 1
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
lecture 2 2
INPUT-OUTPUT SECTIONsupplies 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 paragraphSELECT 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
lecture 2 3
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 . . .]]
lecture 2 4
DATA DIVISION
FILE SECTIONDefine 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.)
lecture 2 5
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
lecture 2 6
BLOCK CONTAINSSpecify blocking factor (# records per disk sector)Higher the factor fewer physical operationsToo 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 valueOptional.
FILE SECTION
lecture 2 7
RECORD DESCRIPTION
FD is followed by an associated record description :Size and type of each field within a recordOrder in which the fields appearRelationship of the fields to one another
Done through a combination of:PICTURE CLAUSESLEVEL NUMBERS
lecture 2 8
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
lecture 2 9
INCOMING RECORD DATA DIVISION RECORDDESCRIPTION
VALUES
v v v
9 87|65 4|3 | 210
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
Assumed Decimal Point
lecture 2 10
VALUE Clause
Initialize contents of a field with literals.
Literals Numeric : VALUE 3.00Non-numeric : VALUE ‘ENGINEERING’Figurative constants : VALUE SPACES
SPACE or SPACES, ZERO or ZEROS, QUOTE or QUOTES, ALL literal
lecture 2 11
Level numbersLEVEL 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
lecture 2 12
STUDENT-EXAM-RECORD
STUDENT-NAME EXAM-SCORESSS-NUM
LASTNAME
FIRSTNAME
INIT
MATH ENGLISH
ALG GEO READ VOC LIT
1 15 16 30 31 32 40 41 45 46 50 51 55 56 60 61 65
ALPHANUMERIC NUMERIC
Student Exam Record
lecture 2 13
01 STUDENT-EXAM-RECORD. 05 STUDENT-NAME. 10 LAST-NAME PICTURE IS X(15). 10 FIRST-NAME PICTURE IS X(15). 10 MID-INITIAL PICTURE IS X. 05 SOC-SEC-NUM PICTURE IS 9(9). 05 EXAM-SCORES. 10 MATH.
15 ALGEBRA PICTURE IS 9(5). 15 GEOMETRY PICTURE IS 9(5).
10 ENGLISH. 15 READING PICTURE IS 9(5). 15 VOCABULARY PICTURE IS 9(5). 15 LITERATURE PICTURE IS 9(5).
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.
(a) Initial Coding
(b) Alternative Specification
Level Numbers and PICTURE Clauses
lecture 2 14
WORKING-STORAGE SECTIONDefines data names not referenced in the FILE SECTION.Stores results of calculations, flags, switch control, constantsUsed 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.
lecture 2 15
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".
lecture 2 16
(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-CREDITS PIC 9(2). 05 STU-UNION-MEMBER PIC X. 05 STU-SCHOLARSHIP PIC 9(4). 05 STU-GPA PIC 9V99.
STUDENT NAME
LASTGPA
INITIALSCREDITS UNION 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)
lecture 2 17(b) COBOL Entries
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.
(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)
lecture 2 18
(a) Report Layout
1 2 3 4 5 6 7 8
1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6
1 S T U D E N T N A M E C R E D I T S T U I T I O N U N I O N F E E A C T F E E S C H O L A R S H I P T O T A L B I L L
2
3 X X X X X X X X X X X X X X X X X 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9
4 X X X X X X X X X X X X X X X X X 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9
5
6
Development of a COBOL Program (Print Lines)
lecture 2 19(b) COBOL Entries
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. 01 DETAIL-LINE. 05 FILLER PIC X VALUE SPACES. 05 DET-LAST-NAME PIC X(15). 05 FILLER PIC X(2) VALUE SPACES. 05 DET-INITIALS PIC X(2). 05 FILLER PIC X(5) VALUE SPACES. 05 DET-CREDITS PIC 9(2). 05 FILLER PIC X(2) VALUE SPACES. 05 DET-TUITION PIC 9(6). 05 FILLER PIC X(7) VALUE SPACES. 05 DET-UNION-FEE PIC 9(3). 05 FILLER PIC X(8) VALUE SPACES. 05 DET-SCHOLARSHIP PIC 9(5). 05 FILLER PIC X(6) VALUE SPACES. 05 DET-IND-BILL PIC 9(6).
05 FILLER PIC X(49) VALUE SPACES.
Development of a COBOL Program (Print Lines)