Download presentation
Presentation is loading. Please wait.
Published byJeremy Black Modified over 9 years ago
1
PowerPoint Presentation: Richard H. Baum, Ph.D. DeVry Institute of Technology 9th Edition Structured COBOL Programming Nancy Stern Hofstra University Robert A. Stern Nassau Community College “Copyright @ 2000 John Wiley & Sons, In. All rights reserved. Reproduction or translation of this work beyond that permitted in Section 117 of the 1976 United States Copyright Act without the express permission of the copyright owner is unlawful. Request for further information should be addressed to the permissions Department, John Wily & Sons, Inc. The purchaser may make back-up copies for his/her own use only and not for distribution or resale. The Publisher assumes no responsibility for errors, omissions, or damages, caused by the use of these programs or from the use of the information contained herein.”
2
Structured COBOL Programming, Stern & Stern, 9th Edition Chapter 3 The Data Division: File Section and Working-Storage Section
3
Structured COBOL Programming, Stern & Stern, 9th Edition OBJECTIVES To familiarize you with: 1. Systems design considerations that relate to programming. 2. The ways in which data is organized. 3. The rules for forming data-names and constants in COBOL. 4. How input and output files are defined and described in the DATA DIVISION. 5. How storage can be reserved for fields not part of input or output, such as constants and work areas.
4
Structured COBOL Programming, Stern & Stern, 9th Edition CONTENTS SYSTEMS DESIGN CONSIDERATIONS –The Relationship between a Business Information System and its Programs –Interactive and Batch Processing –Designing Input for Applications Using Batch Processing
5
Structured COBOL Programming, Stern & Stern, 9th Edition CONTENTS FORMING DATA-NAMES –Rules –Guidelines THE FILE SECTION OF THE DATA DIVISION –An Overview –File Description Entries –Record Description Entries
6
Structured COBOL Programming, Stern & Stern, 9th Edition CONTENTS TYPES OF DATA –Variable and Constant Data –Types of Constants THE WORKING-STORAGE SECTION OF THE DATA DIVISION –Introduction –Uses of WORKING-STORAGE –VALUE Clauses for WORKING-STORAGE Entries
7
Structured COBOL Programming, Stern & Stern, 9th Edition THE FILE SECTION OF THE DATA DIVISION
8
Structured COBOL Programming, Stern & Stern, 9th Edition AN OVERVIEW 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.
9
Structured COBOL Programming, Stern & Stern, 9th Edition AN OVERVIEW THE TWO MAIN SECTIONS OF THE DATA DIVISION 1. FILE SECTION -- defines all input and output files. 2. WORKING-STORAGE SECTION - reserves storage for fields that are not part of input or output but are required for processing. – These include constants, end-of- file indicators, and work areas.
10
Structured COBOL Programming, Stern & Stern, 9th Edition INTERACTIVE PROCESSING Interactive programs that just accept input from a keyboard and display output on a screen do not need SELECT statements or a FILE SECTION.
11
Structured COBOL Programming, Stern & Stern, 9th Edition File Description Entries AN OVERVIEW Defining a File The FILE SECTION, as the name implies, describes all input and output files used in the program in the FILE SECTION of the DATA DIVISION.
12
Structured COBOL Programming, Stern & Stern, 9th Edition File Description Entries AN OVERVIEW Defining a File The FILE SECTION describes the input and output areas used in the program. A READ instruction, in the PROCEDURE DIVISION, will transmit one record of the designated file to this input area. Similarly, an output area is primary storage reserved for a record to be produced in an output file.
13
Structured COBOL Programming, Stern & Stern, 9th Edition File Description Entries Each file is described in the FILE SECTION with an FD sentence that may consist of a series of clauses. After the clauses are specified, the FD sentence ends with a period. FD is an abbreviation for File Description.
14
Structured COBOL Programming, Stern & Stern, 9th Edition FILE DESCRIPTION ENTRIES An example: SELECT INVENTORY-FILE ASSIGN TO DISK1. SELECT ERROR-LIST ASSIGN TO PRINTER. * DATA DIVISION. FILE SECTION. FDINVENTORY-FILE.. FDERROR-LIST
15
Structured COBOL Programming, Stern & Stern, 9th Edition LABEL RECORD(S) Clause FORMAT: LABEL {RECORD IS}{RECORDS ARE} {OMITTED}{STANDARD} Interpreting Instruction Formats –Each set of braces {} denotes that one of the enclosed items is required.
16
Structured COBOL Programming, Stern & Stern, 9th Edition LABEL RECORD(S) Clause Label records are usually created as the first and last records of a disk file – They provide identifying information about the file. – They can be used to check if the correct file is being accessed for a specific program.
17
Structured COBOL Programming, Stern & Stern, 9th Edition RECORD CONTAINS Clause -- (Optional) Format: RECORD CONTAINS integer-1 CHARACTERS The RECORD CONTAINS clause indicates the size of each record. – A print file, for example, may have the following entry: RECORD CONTAINS 80 CHARACTERS.
18
Structured COBOL Programming, Stern & Stern, 9th Edition BLOCK CONTAINS Clause - (Optional) Format BLOCK CONTAINS integer-1 RECORDS The BLOCK CONTAINS clause is 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.
19
Structured COBOL Programming, Stern & Stern, 9th Edition QUESTIONS??!!
20
Structured COBOL Programming, Stern & Stern, 9th Edition SELF-TEST 1. What is the purpose of the DATA DIVISION? SOLUTION--It describes and defines fields, records, and files in storage.
21
Structured COBOL Programming, Stern & Stern, 9th Edition SELF-TEST 2. What are the two primary sections of a DATA DIVISION? SOLUTION-----FILE SECTION; WORKING-STORAGE SECTION
22
Structured COBOL Programming, Stern & Stern, 9th Edition SELF-TEST 3. What is the purpose of the FILE SECTION of the DATA DIVISION? SOLUTION: It defines and describes all data areas that are part of input or output.
23
Structured COBOL Programming, Stern & Stern, 9th Edition SELF-TEST 4. File-names must be from one to ______ characters in length, contain at least one ______, and have no _______. SOLUTION: 30; alphabetic character; special characters or blanks.
24
Structured COBOL Programming, Stern & Stern, 9th Edition SELF-TEST 5. File-names (must, need not) be unique. SOLUTION: must
25
Structured COBOL Programming, Stern & Stern, 9th Edition SELF-TEST 6. For every file defined in a SELECT statement, there will be one _______ entry in the FILE SECTION. SOLUTION: FD
26
Structured COBOL Programming, Stern & Stern, 9th Edition SELF-TEST 7. The three clauses that may be used with an FD are _______, _________, and ___________. SOLUTION: LABEL RECORD; RECORD CONTAINS; BLOCK CONTAINS
27
Structured COBOL Programming, Stern & Stern, 9th Edition RECORD DESCRIPTION ENTRIES Defining a Record A record is a unit of information consisting of related data items within a file. –A file consists of records that all have the same length and format called fixed-length records.
28
Structured COBOL Programming, Stern & Stern, 9th Edition RECORD DESCRIPTION ENTRIES Level Numbers –After a file is described by an FD, the record description entries for each record format within the file follow. The record description specifies the format of a record. –Just as the file-name is specified on the FD level, a record- name is coded on the 01 level.
29
Structured COBOL Programming, Stern & Stern, 9th Edition RECORD DESCRIPTION ENTRIES Level Numbers--Example 1 –A transaction disk file with only one record format may have the following entries: FDTRANSACTION-FILE LABEL RECORDS ARE OMITTED RECORD CONTAINS 80 CHARACTERS. 01TRANSACTION-REC-IN...{Entries of the record}
30
Structured COBOL Programming, Stern & Stern, 9th Edition RECORD DESCRIPTION ENTRIES Level Numbers Data is grouped in COBOL using the concept of a level. Records are considered the highest level of data in a file, and are coded on the 01 level. – A record consists of fields.
31
Structured COBOL Programming, Stern & Stern, 9th Edition RECORD DESCRIPTION ENTRIES Level Numbers The record description entries following the FD are: 01 EMPLOYEE-REC-IN. 05 NAME-IN 05 ANNUAL-SALARY-IN 05 JOB-DESCRIPTION-IN All fields on the 05 level are subordinate to, or part of, the 01- level entry. All fields coded on the same level are independent items.
32
Structured COBOL Programming, Stern & Stern, 9th Edition RECORD DESCRIPTION ENTRIES Fields May Be Defined as Either Elementary or Group Items A field that is not further subdivided is called an elementary item. A field that is further subdivided is called a group item.
33
Structured COBOL Programming, Stern & Stern, 9th Edition RECORD DESCRIPTION ENTRIES Fields May Be Defined as Either Elementary or Group Items All elementary items must be additionally described with a PICTURE clause that indicates the size and type of the field. A group item, because it is subdivided, needs no further specification and ends with a period.
34
Structured COBOL Programming, Stern & Stern, 9th Edition RECORD DESCRIPTION ENTRIES PICTURE (PIC) Clauses Group items are defined by a level number and a name, which is followed by a period. Elementary items or fields not further subdivided must be described with a PICTURE (or PIC, for short) clause.
35
Structured COBOL Programming, Stern & Stern, 9th Edition RECORD DESCRIPTION ENTRIES FUNCTIONS OF THE PICTURE CLAUSE 1. To specify the type of data contained within an elementary item. 2. To indicate the size of the field.
36
Structured COBOL Programming, Stern & Stern, 9th Edition RECORD DESCRIPTION ENTRIES TYPES OF DATA FIELDS 1. Alphabetic –A field that may contain only letters or blanks is classified as alphabetic. 2. Alphanumeric –A field that may contain any character is considered alphanumeric. 3. Numeric –Any signed or unsigned field that will contain only digits is considered numeric.
37
Structured COBOL Programming, Stern & Stern, 9th Edition RECORD DESCRIPTION ENTRIES CHARACTERS USED IN PICTURE CLAUSES A for alphabetic X for alphanumeric 9 for numeric
38
Structured COBOL Programming, Stern & Stern, 9th Edition DEBUGGING TIP Data entered into a field should be consistent with the data type specified in the PIC clause to ensure that errors do not occur. If you define a field with a PIC of 9’s it must contain numeric characters to be processed correctly. Use a PIC of 9’s only for fields used in arithmetic operations. *NOTE: a space is not a valid character in a numeric field.
39
Structured COBOL Programming, Stern & Stern, 9th Edition RECORD DESCRIPTION ENTRIES Size of Data Fields The size of the field is denoted by the number of A's, X's, or 9's used in the PICTURE. Example: 01 CUST-REC-IN. 05 CUST-ID-IN PICTURE XXXX. (4 positions) 05 AMT-IN PICTURE 99999. (5 positions)
40
Structured COBOL Programming, Stern & Stern, 9th Edition RECORD DESCRIPTION ENTRIES Size of Data Fields Group items are those fields that are further subdivided – They do not have PICTURE clauses. Elementary items require a PICTURE clause – The clause denotes the size of a field and the type of data.
41
Structured COBOL Programming, Stern & Stern, 9th Edition RECORD DESCRIPTION ENTRIES Example of an Output Record: 01 CREDIT-CARD-ACCT-OUT. 05 NAME-OUT. 10 INIT1-OUT PICTURE X. 10 INIT2-OUT PICTURE X. 10 LAST-NAME-OUT PICTURE X(18). 05 CREDIT-CARD-NO-OUT PICTURE X(5). 05 ADDRESS-OUT PICTURE X(20). 05 AMT-OF-TRANS-OUT PICTURE 9(5).
42
Structured COBOL Programming, Stern & Stern, 9th Edition RECORD DESCRIPTION ENTRIES THE USE OF THE IMPLIED DECIMAL POINT In order for a five-position input amount field: 10000, to be interpreted as 100.00, we want the computer to “assume” that a decimal point exists. –Its PICTURE clause, then, is: 05 AMT-IN PICTURE 999V99. The symbol V denotes an implied decimal point, which does not occupy a storage position.
43
Structured COBOL Programming, Stern & Stern, 9th Edition RECORD DESCRIPTION ENTRIES: SUMMARY An 01-level entry and its corresponding field description must be included for every record format in a file. All record formats within an FD are described before the next FD is defined. The syntax rules governing the DATA DIVISION indicate the sequence in which entries are coded.
44
Structured COBOL Programming, Stern & Stern, 9th Edition THE WORKING-STORAGE SECTION OF THE DATA DIVISION
45
Structured COBOL Programming, Stern & Stern, 9th Edition INTRODUCTION Any field necessary for processing that is not part of an input or output file may be defined in the WORKING-STORAGE SECTION of the DATA DIVISION. 1. The WORKING-STORAGE SECTION follows the FILE SECTION. 2. WORKING-STORAGE SECTION is coded on a line by itself beginning in Area A and ending with a period.
46
Structured COBOL Programming, Stern & Stern, 9th Edition INTRODUCTION 3. A group item that will be subdivided into individual storage areas as needed may then be defined. All necessary fields can be described within this 01-level entry. 4. Names associated with group and elementary items must conform to the rules for data-names. WS- is frequently used as a prefix to denote fields as WORKING-STORAGE entries. 5. Each elementary item must contain a PIC clause. 6. Each elementary item may contain an initial value, if desired.
47
Structured COBOL Programming, Stern & Stern, 9th Edition VALUE CLAUSES FOR WORKING- STORAGE The Purpose of VALUE Clauses 1. Level 01 may be used to define a group of independent or elementary items. These independent elementary items would be coded on a level subordinate to 01. 2. A user-defined data-name or identifier defines each field. 3. The size of a field and its data type are defined by the PIC clause. 4. An initial value may be stored in the field by a VALUE clause defined on the elementary level. VALUE clauses may also be used on the group level for initializing a series of fields.
48
Structured COBOL Programming, Stern & Stern, 9th Edition DEBUGGING TIP It is best to initialize fields in WORKING-STORAGE with VALUE clauses rather than with MOVE statements in the PROCEDURE DIVISION. –You are more apt to remember to initialize at the time you are defining the fields.
49
Structured COBOL Programming, Stern & Stern, 9th Edition DEBUGGING TIP Failure to initialize a field used in an arithmetic operation is a frequent cause of program interrupts. Be sure to use a VALUE of zeros to initialize all numeric fields prior to processing.
50
Structured COBOL Programming, Stern & Stern, 9th Edition COBOL 2000+ CHANGES 1. The LABEL RECORDS clause will be phased out entirely. 2. VALUE clauses will be permitted in the FILE SECTION for defining initial contents of fields. 3. The way nonnumeric literals are continued will change. The hyphen from the continuation column (7) will be eliminated. Instead, you will add a - on the line being continued.
51
Structured COBOL Programming, Stern & Stern, 9th Edition COBOL 2000+ CHANGES 4. As noted previously, rules for Margins A and B will become guidelines rather than requirements. 5. Commas and dollar signs will be permissible in numeric literals. Thus, $1,000.00 would be a valid numeric literal.
52
Structured COBOL Programming, Stern & Stern, 9th Edition CHAPTER SLIDES END HERE CHAPTER SUMMARY COMES NEXT
53
Structured COBOL Programming, Stern & Stern, 9th Edition CHAPTER SUMMARY A. Data Organization 1. File - The major classification of data for a specific business use or application. 2. Record - Data within a file that contains a unit of information. 3. Field - A group of consecutive positions reserved for an item of data.
54
Structured COBOL Programming, Stern & Stern, 9th Edition CHAPTER SUMMARY B. Types of Data 1. Variable Data - Data that varies with each run. 2. Constant or Literal - Data that is defined within the program; it is not entered as input to the system. Numeric Literal - A constant that may be used in the PROCEDURE DIVISION for arithmetic operations.
55
Structured COBOL Programming, Stern & Stern, 9th Edition SUMMARY B2. Constants or Literals (continued) –Nonnumeric Literal - A constant that may be used in the PROCEDURE DIVISION for all operations except arithmetic. –Figurative Constant - A COBOL reserved word with special significance to the compiler (e.g.., ZERO or ZEROES or ZEROS; SPACE or SPACES).
56
Structured COBOL Programming, Stern & Stern, 9th Edition SUMMARY C. The FILE SECTION 1. FD Entries FD is coded in Area A. The file-name, which is typically coded in Area B, must be the same name that is used in the SELECT statement.
57
Structured COBOL Programming, Stern & Stern, 9th Edition SUMMARY C. The FILE SECTION (continued) CLAUSES LABEL RECORDS ARE{OMITTED}{ STANDARD} RECORD CONTAINS integer CHARACTERS BLOCK CONTAINS integer RECORDS. All clauses are optional for COBOL85. LABEL RECORDS is required for COBOL78. After any clauses have been specified, a single period ends the FD.
58
Structured COBOL Programming, Stern & Stern, 9th Edition SUMMARY 2. Record Description Entries –Record-names are coded on the 01 level. –Field-names are coded on levels 02--49. –Level 01 is coded in Area A. All other levels are coded in Area B for COBOL 74, although Area A can be used for COBOL 85.
59
Structured COBOL Programming, Stern & Stern, 9th Edition SUMMARY 2. Record Description Entries –Items with higher-level numbers are considered subordinate to, or contained within, items with lower-level number. –Group items are further subdivided; elementary items are not.
60
Structured COBOL Programming, Stern & Stern, 9th Edition SUMMARY 2. Record Description Entries –Only elementary items have PICTURE or PIC clauses to describe the data: X - alphanumeric A - alphabetic 9 - numeric V - implied decimal position (used only with numeric fields) – A period must follow a PICTURE clause in an elementary item; a period directly follows a group item name.
61
Structured COBOL Programming, Stern & Stern, 9th Edition SUMMARY 2. Record Description Entries (4 OF 4) –Fields must be defined in the DATA DIVISION in the same sequence as they appear in the record being described. –FILLER is a COBOL reserved word used to define areas within a record that will not be referenced individually during processing. With COBOL 85, a blank field- name can be used instead of the word FILLER.
62
Structured COBOL Programming, Stern & Stern, 9th Edition SUMMARY D. The WORKING-STORAGE SECTION 1. Used for storing intermediate results, counters, end-of-file indicators, and interactive data to be displayed or accepted as input. 2. VALUE clauses may be used to initialize fields.
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.