CHAPTER 3

 

THE DATA DIVISION

 

 

CHAPTER OBJECTIVES

 

After completion of this chapter, the student should be able to:

 

1.         Define the terms "file," "records," and "fields."

 

2.         Explain the rules for forming user-defined data-names.

 

3.         Explain the purpose of the DATA DIVISION.

 

4.         Explain the purpose of the FILE and WORKING-STORAGE sections.

 

5.         Code and explain the rules for File Description (FD) entries.

 

6.         Explain the format of the LABEL RECORDS clause, RECORD CONTAINS clause, and BLOCK CONTAINS clause.

 

7.         Code and explain record description entries.

 

8.         Describe the kind of data that can be stored in alphabetic, alphanumeric, and numeric fields.

 

9.         Write and explain PICTURE clauses for alphabetic, alphanumeric, and numeric data.

 

10.       Explain how to indicate an implied decimal point in a PICTURE clause.

 

11.       Distinguish between variable data and constant data.

 

12.       Identify the three types of constants.

 

13.       Explain the purpose of numeric and nonnumeric literals and the rules for using them.

 

14.       Identify two types of figurative constants and explain the purpose of each.

 

15.       Explain the purpose of the VALUE clause.


LECTURE OUTLINE

 

I.          Systems Design Considerations

 

A.        The Relationship Between a Business Information System and Its Programs

 

1.         Most individual programs are part of a group of programs called a business information system.

 

2.         A systems analyst (or programmer analyst in smaller companies) is responsible for the design of business information systems.

 

B.         Interactive and Batch Processing

 

1.         With interactive processing, data is operated on and output is produced as soon as the input is entered.

 

2.         Batch processing operates on files at periodic intervals.

 

C.        Designing Input for Applications Using Batch Processing

 

1.         A file, which is a major collection of data for a given application, is composed of records.

 

2.         Records for input and output disk files are described on record layout sheets.

3.         Output print files are described on Printer Spacing Charts.

II.         Forming Data-Names

 

A.        Rules

 

1.         Files, records, and fields are categories of data.  They are each assigned a user-defined name called a data-name or identifier.

 

2.         Records are divided into individual fields.

 

3.         The rules for forming user-defined data-names are:

a.         1 to 30 characters.

b.         Letters, digits, and hyphens (-) only.

c.         May not begin or end with a hyphen.

d.         No embedded blanks are permitted.

e.         Must contain at least one alphabetic character.

f.          May not be a COBOL reserved word.


B.         Guidelines

 

1.         Use meaningful data-names that describe the type of data within the field.

 

2.         It is recommended that suffixes or prefixes be attached to data-names so that they can be easily identified as members of a particular group.

 

III.       The FILE SECTION of the DATA DIVISION

 

A.        An Overview

 

1.         The DATA DIVISION defines and describes fields, records, and files in storage.

 

2.         All data items in a COBOL program must be defined in the DATA DIVISION.

 

3.         The DATA DIVISION consists of two main sections:

a.         FILE SECTION

b.         WORKING-STORAGE SECTION

 

4.         The FILE SECTION describes all input and output files.  With most compilers, interactive programs that accept input and display output to the screen do not need SELECT statements or the FILE SECTION.

 

5.         The WORKING-STORAGE SECTION reserves storage for fields that are not part of input or output files.  These fields are normally temporary fields used while the program is executing and are not saved when the program terminates.

 

6.         Within the DATA DIVISION, the FILE SECTION must be described first, followed by the WORKING-STORAGE SECTION.

 

7.         All files must be defined in the FILE SECTION.  In a typical update program, for example, a master file is input to the program along with a transaction file.  The two input files are processed to produce a single new master output file.  Thus, three files would be described in the FILE SECTION of an update program.

 


8.         File description entries describe each file with an FD sentence that consists of a number of clauses and ends with a period.  Each FD will describe a file that was named in a SELECT statement in the ENVIRONMENT DIVISION.

 

B.         File Description Entries

 

1.         Each file is described in the FILE SECTION with an FD statement.  FD is an abbreviation for File Description.

 

2.         Each file defined with an FD statement in the FILE SECTION must also be defined in the ENVIRONMENT DIVISION with a SELECT statement.

 

3.         Additional clauses that describe the file and the format of its records follow the FD sentence.

 

4.         The FD entry is coded in Area A and followed by the file name, which is coded in Area B. These are followed by any necessary clauses.  There is no period until the last clause is completed.

 

5.         LABEL RECORD(S) clause:

a.         This clause was required in COBOL 74, but is optional in COBOL 85.  In COBOL 85, the creating and checking of labels can be performed by the operating system.

b.         This clause may be included to provide identifying information about the first (header label) and last (trailer label) records on a file.

c.         Labels are created on output files and checked on input files.

d.         The information to be included on the label is provided through operating system commands.

e.         LABEL RECORDS ARE STANDARD is permitted only for magnetic media such as disk or tape.

f.          LABEL RECORDS ARE OMITTED must be used for printer and keyboard files since they do not use label records.

g.         The text will not use the clause since it will be eliminated in COBOL 2002+.

 

6.         RECORD CONTAINS clause:

a.         Indicates the number of characters in each record.

b.         The clause is optional but is recommended as it provides a check on the record size prior to execution.

 


7.         BLOCK CONTAINS clause:

a.         Specified only for files in which disk or tape records have been blocked.

b.         Blocking is a technique used to maximize the efficient use of disk and tape by storing several logical records in one physical record.

c.         This clause is optional in COBOL 85 because operating system commands can be used to specify the blocking factor.

 

8.         Rules for coding file description entries:

a.         FD is coded in Area A.

b.         All other clauses are coded in Area B.

c.         No period is coded until the last clause is specified.

d.         Commas are always optional.  If used, they must be followed by at least one blank space.

e.         It is recommended that each clause appear on a separate line for clarity and ease of debugging.

f.          Clauses may appear in any sequence in an FD.

 

9.         In COBOL 85 all of the clauses in the FD entry are optional.

 

C.        Record Description Entries

 

1.         A record is a unit of data consisting of related fields within a file.

 

2.         Fixed-length records are records that all have the same length and format.

 

3.         After a file is identified with the File Description (FD) entries, the record description entries follow.

 

4.         The record description entries specify the format of a record.  Record description entries specify:

a.         The items or fields to appear in the record.

b.         The order in which the fields appear.

c.         How these fields are related to one another.

 

5.         Data is grouped using the concept of a level.  Records are considered the highest level and are coded on the 01 level in Area A.  A field within the record is subordinate to the record and may have any level number between 02 and 49, coded anywhere in Area B.

 

6.         A field is a group of consecutive storage positions reserved for an item of data.


7.         Coding guidelines for record description entries:

a.         Record-names are coded in Area A on the 01 level.

b.         All fields are coded on levels 02-49 in Area B.

c.         Subordinate or elementary entries are indented for clarity.

d.         Level numbers need not be consecutive; most programmers use increments of 05.

 

8.         A field that is further subdivided is called a group item.  A group item ends with a period and does not have a PICTURE clause.

 

9.         A field that is not further subdivided is called an elementary item.  Elementary items must be described with a PICTURE clause that specifies the size and type of the field.

 

10.       The functions of the PICTURE clause are:

a.         To specify the type of data contained within an elementary item.

b.         To indicate the size of the field.

 

11.       Types of data fields:

a.         Alphabetic fields may contain only letters or blanks and are denoted in the PICTURE clause by A.

b.         Alphanumeric fields may contain any characters and are denoted in the PICTURE clause by X.

c.         Numeric fields may contain only numeric digits and are denoted in the PICTURE clause by 9. These fields may be signed or unsigned.

 

12.       The size of the field is denoted by the number of A’s, X's, or 9's used in the PICTURE clause.

 

13.       Most programmers do not use the A designation, but instead use the X designation to represent all nonnumeric fields.

 

14.       The X(n) or 9(n) format is preferred for long fields because it is easier to read.

 

15.       A blank field-name or the word FILLER with an appropriate PICTURE clause designates an area set aside for some part of a record that will not be individually referenced in the PROCEDURE DIVISION.  FILLER may only be used in the DATA DIVISION.  In COBOL 85, the word FILLER may be omitted entirely.

 


16.       The symbol "V" in a PICTURE clause is used to denote an implied decimal point in a numeric field.  The implied decimal point does not occupy a storage position.

 

17.       For interactive processing, the decimal point may be typed, but if there is a V in the PICTURE, it will be treated as an implied decimal point.

 

IV.       Types of Data

 

A.        Variable and Constant Data

 

1.         Variable data is data which changes during program execution.  File Description entries contain variable data because the data changes as different records are processed.

 

2.         Constant data is data that is required for processing but is not dependent on the input to the program.  The value stored as a constant does not change during program execution.

 

3.         A constant may be used directly in the PROCEDURE DIVISION or it may be defined in the WORKING-STORAGE SECTION as a field with a VALUE clause.

 

B.         Types of Constants

 

1.         A numeric literal is a constant used primarily for arithmetic operations.

 

2.         Rules for forming numeric literals:

a.         1 to 18 digits.

b.         A plus (+) or minus (-) sign, if used, must be to the left of the number.

c.         A decimal point is permitted within the literal, but may not be the last character of the literal.

 

3.         A nonnumeric or alphanumeric literal is a constant used in the PROCEDURE DIVISION for non-arithmetic operations.

 

4.         Rules for forming nonnumeric literals:

a.         The literal must be enclosed in quotes.

b.         From 1 to 160 characters, including spaces, may be used. (Only 120 characters are permitted in COBOL 74). Some computer systems allow even longer nonnumeric literals; the VAX, for example, permits 255 characters.

c.         Any character permitted in the COBOL character set may be used except the quotation mark.

 

5.         Figurative constants are COBOL reserved words that have a special significance to the compiler.

a.         The figurative constant ZEROS (ZERO, ZEROES) is a COBOL reserved word meaning all zeros.  ZEROS can be moved to both numeric and alphanumeric fields.

b.         The figurative constant SPACES (SPACE) is a COBOL reserved word meaning all spaces or blanks.  SPACES may be moved only to alphanumeric or alphabetic fields.

 

V.        The WORKING-STORAGE SECTION of the DATA DIVISION

 

A.        Introduction

 

1.         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.  Such a field may also be established with a constant as its value.

 

2.         Explain the rules for using the WORKING-STORAGE SECTION as presented in this section of the text.

 

B.         Uses of WORKING-STORAGE

 

1.         Example 1:  Storing Intermediate Results.

 

2.         Example 2:  Storing Counters.

 

3.         Example 3:  Using an End-of-File Indicator.

 

C.        VALUE Clauses for WORKING-STORAGE Entries

 

1.         Elementary fields in WORKING-STORAGE may be given initial contents by using a VALUE clause.

 

2.         Group fields may also contain a VALUE clause, in which case the elementary fields within the group are initialized with the specified value.

 

3.         Four entries are used to define fields in WORKING-STORAGE:

a.         A level number.

b.         A user-defined data-name or identifier.

c.         The size of the field and its data type as defined in a PICTURE clause.

d.         The initial value of the field as assigned in the VALUE clause.


4.         VALUE clauses for initializing fields may not be used in the FILE SECTION of the DATA DIVISION.

 

5.         The VALUE clause, which is a literal or figurative constant, must be the same data type as the PICTURE clause.

 

6.         As a general rule, any literal that will be used more than once in the PROCEDURE DIVISION should be given an assigned storage area and a data-name in WORKING-STORAGE.

 

7.         Rules for continuation of literals from one line to the next:

a.         Begin the literal in the VALUE clause with a quotation mark.

b.         Continue the literal through position 72.

c.         Place a hyphen in column 7 of the next line.

d.         Continue the literal in any position beginning in Area B of the second line.  Begin with a quotation mark.

e.         End the literal with a quotation mark.

f.          The rules will change with COBOL 2002+.


SOLUTIONS TO REVIEW QUESTIONS

 

I.          True-False Questions

 

1.         T

 

2.         T

 

3.         F          A numeric literal may contain a maximum of 18 digits plus an optional sign

and an optional decimal point.

 

4.         F          Value clauses are only permitted in the WORKING-STORAGE SECTION.

 

5.         T

 

6.         T

 

7.         F          Fields defined in a record description must appear in the same order in

                        which they are sequenced on the actual physical record.

 

8.         F          Valid subordinate level numbers range from 02 through 49.

 

9.         T

 

10.       F          Record names are assigned in the DATA DIVISION.

 

II.        General Questions

 

1.         a.         CUSTOMER-NAME              data-names cannot contain embedded blanks

            b.         AMOUNT                               may not end with a hyphen

            c.         INVOICE-NO                                    may not use a period

            d.         PROCEDURE                         this is a COBOL reserved word

            e.         TAX                                        may not use a special character in a

                                                            data-name

f.          QTY-OF-PRODUCT-ABC-ON-HAND

                                                            too long; data-names may not exceed 30                                                           characters

g.         AMT-OF-SALES                    valid

 


2.         a.         123                  is a valid numeric literal

            b.         123                  cannot end with a period

            c.         123.0               is a valid numeric literal

            d.         100.00             $ not permitted

            e.         1000                comma not permitted

            f.          -100.7              sign must precede number

            g.         +54                  is a valid numeric literal

            h.         -1.3                  is a valid numeric literal

 

3.         a.         valid

            b.         valid

            c.         invalid               quote cannot be used

            d.         invalid               needs quote at beginning

 

4.         FIELDA will contain the nonnumeric literal ABCbbb (the letter b is used throughout this manual to represent a space).

 

5.         FIELDA will contain the same data as field ABC only if the PIC clauses are identical.

 

6.         FIELDA will contain the word SPACES.

 

7.         FIELDA will contain all blanks.

 

8.         a.         Area A

b.         Area A

c.         Area A

d.         Area B

 


9.

 

      *A 1 B       2         3         4         5         6

123456789012345678901234567890123456789012345678901234567890123

 

       01  PURCHASE-ORDER.

           05  ACCT-NO.

               10  CATEGORY      

               10  CREDIT-RATING 

           05  ACTIVITY-CODE     

           05  TRANSACTION-DATA.

              10  VENDOR.

                  15  VENDOR-NAME

                  15  VENDOR-NO

              10  TRANSACTION-STAT.

                  15  DATE-OF-TRANS.

                      20  TRANS-MO

                      20  TRANS-DA

                      20  TRANS-YR

                  15  TRANS-AMT 

 

 


III.       Internet/Critical Thinking Questions

 

1.        

Inventory File:

 

Search Engine:  google.com

Keywords:                   +database +inventory +software

URL:                            http://www.databasecreations.com/

Contents:                      Screen displaying fields stored in an inventory database file

 

 01  INVENTORY-RECORD.

05  ITEM-ID             PIC X(10).

05  DESCRIPTION         PIC X(30).

05  AVERAGE-COST        PIC 9(4)V99.

05  QUANTITY-ON-HAND    PIC 9(4).

05  QUANTITY-ON-ORDER   PIC 9(4).

05  DATE-RECEIVED        PIC 9(8).

05  LAST-COST           PIC 9(4)V99.

05  PREFERRED-VENDOR     PIC X(30).

05  PO-NUMBER            PIC X(11).

05  COLOR-INFO           PIC X(8).

05  STYLE                PIC X(8).

05  WAREHOUSE            PIC X(15).

05  PICKING-ORDER        PIC 9(3).

05  LOCATION-INFO        PIC X(10).

05  BIN                  PIC X(10).


Payroll File:

 

Search Engine:  yahoo.com>Computers & Internet

Keywords:                   +payroll +software

URL:                            http://www.redwingsoftware.com/winpay.htm

Contents:                      Screen displaying fields stored in a payroll database file

 

01  PAYROLL-RECORD.

    05  EMPLOYEE-NAME        PIC X(30).

    05  ADDRESS              PIC X(30).

    05  PHONE                PIC X(10).

    05  SOCIAL-SECURITY-NO   PIC X(9).

    05  EMPLOYEE-CODE        PIC X(10).

    05  PAY-FREQUENCY-CODE   PIC X(1).

    05  PAY-TYPE-CODE        PIC X(1).

    05  PAY-RATE              PIC 9(6)V99.

    05  DEPARTMENT           PIC X(1).

    05  SHIFT                PIC X(1).

    05  GENDER               PIC X(1).

    05  JOB-CLASS            PIC X(1).

    05  TITLE                PIC X(20).

    05  STATUS               PIC X(1).

    05  DATE-OF-BIRTH        PIC 9(8).

    05  HIRE-DATE            PIC 9(8).

    05  DATE-OF-LAST-REVIEW  PIC 9(8).

    05  DATE-OF-NEXT-REVIEW  PIC 9(8).

    05  TERMINATION-DATE          PIC 9(8).

 

2.

 

Search Engine:  google.com

Keywords:                   “variable-length records”

URL:                            http://pds.jpl.nasa.gov/stdref/chap15.htm

Contents:                      StdRef Chapter 15: Record Formats

 

Search Engine:  google.com

Keywords:                   “variable-length records”

URL:                            http://www.csis.ul.ie/Course/SequentialFiles3.htm

Contents:                      Tutorial on variable-length records

 

 


SOLUTIONS TO DEBUGGING EXERCISES

 

1.

 

      *A 1 B       2         3         4         5         6

123456789012345678901234567890123456789012345678901234567890123

 

DATA DIVISION.

FILE SECTION.

FD  SALES-FILE.

01  INPUT-RECORD.

05  TRANS-NO-IN                 PIC 9(4).

05  TRANSACTION-NAME-IN         PIC X(20).

05  ADDRESS-IN.

              10  NUMBER-IN              PIC X(4).

              10  STREET-IN              PIC X(15).

              10  CITY-IN                PIC X(3).

05  CREDIT-RATING-IN.

              10  CREDIT-CODE-IN         PIC X.

              10  LIMIT-OF-PURCHASE-IN        PIC X.

           05  UNIT-PRICE-IN              PIC 99V9.

           05  QTY-PURCHASED-IN           PIC 9(5).

           05  DISCOUNT-PERCENT-IN        PIC V99.

 

2.        

a.         Incorrect.  First, there is a space missing in the picture clause; it should be coded as PIC 9(5).  Second, the statement MOVE SPACES TO WS-TOTAL will cause a compiler error; the figurative constant SPACES is alphanumeric, while WS-TOTAL is a numeric field.  To initialize WS-TOTAL to zero, code

 

MOVE ZERO TO WS-TOTAL

        or

MOVE 0 TO WS-TOTAL.

 

b.         Correct.  The figurative constant ZEROS may be used with both numeric and

            alphanumeric fields.

 

c.         Incorrect.  As the VALUE clause is presently written, the initial value of TAX-

RATE will be 50.00 because the literal 0850 has an implied decimal point after its rightmost position.  Assuming that the intention was to initialize the field to 08.50, then the entry should be coded

 

   05  TAX-RATE    PIC 99V99 VALUE 08.50.