HP 3000 Manuals

Records [ HP COBOL II/XL Reference Manual ] MPE/iX 5.0 Documentation


HP COBOL II/XL Reference Manual

Records 

Each logical record constitutes a group of related information, uniquely
identifiable and treated as a unit.  A record is actually the most
inclusive data item in a file.  Each input-output statement in the
PROCEDURE DIVISION accesses one logical record, although it can also
extract subordinate data items from that record.

Logical Versus Physical Records 

A physical record is one or more logical records and is commonly called a
block.  A block is the physical unit used by the operating system to read
data from a file, or write data to it; it is the basic unit transferred
between the device on which the file resides and main memory each time a
program executes an input or output operation.

You can use the BLOCK CONTAINS clause to specify the size of (that is,
the number of logical records contained in) a physical record.  For files
on magnetic tape or disk, a block consists of either one logical record
or a group of several logical records.  For instance, 2, 16, or 256
logical records could be grouped into one block.  For tape files,
blocking is normally done to improve execution time or to conserve file
space by reducing the number of gaps on the tape.  For files on card
readers and punches, line printers, and terminals, each block is
identical to each logical record, and its length is determined by the
type of device.  Thus, each block/logical record read from a card reader
consists of one 80-character punched card; each block/logical record
written to a line printer consists of one line of print; typically 132
characters.  The size of a block has no relation to the size of the data
file contained on the device to or from which the block is transferred.

A single storage device can hold one or more logical records.


NOTE In this manual, the term record refers to logical records unless the term block or physical record is specifically used. COBOL allows you to define logical records in main memory as well as in files stored on peripheral devices. This definition is done through the WORKING-STORAGE SECTION of the DATA DIVISION (refer to Chapter 7 ).
Record Descriptions Each record in a file is defined by a record description entry in the DATA DIVISION. This entry, in turn, consists of one or more data description entries that collectively define the characteristics of the record. Each data description entry consists of the following elements in the order listed: * Level number that indicates a subdivision or portion of the logical record. * Data name that allows you to identify and reference the data item. * Independent clauses that describe the attributes of the data item. To reference portions of the information in a logical record, you must subdivide the record into corresponding data items. You must also identify each data item that you wish to reference with a name. Once you specify any data item, you can further subdivide it into subordinate data items to permit more detailed data reference. You can also reference data using reference modification (described later in this chapter). The level number indicates the hierarchical order of a data item within the record structure. Figure 4-1 contains some examples. Since a record is the most inclusive data item your program can reference, it is assigned the level number 01. Less inclusive data items are assigned numerically higher level numbers, ranging from 02 through 49. These numbers need not be successive. The most basic subdivisions of a record (those data items that have no further subdivisions) are called elementary items. Items with subdivisions are called group items, or simply groups. Within the record description entry, each group includes all following group and elementary items until an item with a level number greater than or equal to the level number of that group is encountered. A record is considered a single elementary item if it is not subdivided; otherwise, it is regarded as a sequence of elementary items that may or may not be organized into groups. Because of the hierarchical structure of the record, a basic element can belong to its immediate group and higher level groups that contain that group. In the PROCEDURE DIVISION, your program can refer to the entire record, to any group of any level within that record, or to an elementary item. In Figure 4-1 , a record named PERSONNEL-RECORD (line 11) is defined in the DATA DIVISION. This record is divided into the various group items: * Two main group items, named EMPLOYEE-ID (line 12) and ADDRESS (line 15). * The EMPLOYEE-ID group item is subdivided into two elementary items: EMPLOYEE-NUMBER (line 13) and SOCIAL-SECURITY-NUMBER (line 14). The ADDRESS group item is subdivided into three items: STREET (line 16), LOCATION (line 17), and ZIP (line 20). * The LOCATION group item is further subdivided into two elementary items: CITY (line 18) and STATE (line 19). In this example, the following data items are all elementary items: EMPLOYEE-NUMBER, SOCIAL-SECURITY-NUMBER, STREET, CITY, STATE, and ZIP. If your program accesses the group item ADDRESS, it implicitly accesses STREET, LOCATION, CITY, STATE, and ZIP. Notice that the level numbers used in this example are not successive, and that the descriptions of all elementary items include PICTURE clauses. The first entry in this example begins with the word FD, which is a level indicator that indicates the entire file; this entry is a file description entry, which must always precede any group of record description entries in the FILE SECTION. File description entries are described completely in Chapter 7 . ______________________________________________________________________ | | | : | | 0010 FD PAYROLL-FILE. | | 0011 01 PERSONNEL-RECORD. | | 0012 03 EMPLOYEE-ID. | | 0013 05 EMPLOYEE-NUMBER PIC 9(5). | | 0014 05 SOCIAL-SECURITY-NUMBER PIC 9(9). | | 0015 03 ADDRESS. | | 0016 05 STREET PIC X(20).| | 0017 05 LOCATION. | | 0018 07 CITY PIC X(20).| | 0019 07 STATE PIC X(20).| | 0020 05 ZIP PIC 9(5). | | : | ______________________________________________________________________ Figure 4-1. Record Desctiption Entry Level 66, 77, and 88 Items. Programs can contain special level numbers that do not actually apply to hierarchical levels. Instead, they indicate special properties of entries in the DATA DIVISION. These level numbers are described below: Level Number Purpose 66 specifies group or elementary items introduced by a RENAMES clause. This clause permits the regrouping of data. 77 specifies noncontiguous data items that are not subdivisions of other items and are not themselves subdivided. These items are defined in the WORKING-STORAGE SECTION and typically reference internal counters and accumulators. 88 specifies condition names associated with particular values of a conditional variable. Refer to the description of the DATA DIVISION in Chapter 7 for specific rules on coding the above entries.


MPE/iX 5.0 Documentation