Compaq COBOL AAQ2G1FTK User Manual
Page 186
Processing Files and Records
6.1 Defining Files and Records
In relative file organization, not every cell must contain a record. Although each
cell occupies one record space, a field preceding the record on the storage medium
indicates whether or not that cell contains a valid record. Thus, a file can contain
fewer records than it has cells, and the empty cells can be anywhere in the file.
The numerical order of the cells remains the same during all operations on a
relative file. However, accessing statements can move a record from one cell to
another, delete a record from a cell, insert new records into empty cells, or rewrite
existing cells.
With relative file processing, the I/O system organizes a file as a series of fixed-
sized record cells. Cell size is based on the size specified as the maximum
permitted length for a record in the file. The I/O system considers these cells
as successively numbered from 1 (the first) to n (the last). A cell’s relative record
number (RRN) represents its location relative to the beginning of the file.
Because cell numbers in a relative file are unique, they can be used to identify
both the cell and the record (if any) occupying that cell. Thus, record number 1
occupies the first cell in the file, record number 21 occupies the twenty-first cell,
and so forth. Figure 6–4 illustrates relative file organization.
Figure 6–4 Relative File Organization
Beginning of file
Cell no.
1
2
3
EMPTY
RECORD
1
RECORD
3
Second record
written
First record
written
999
1000
End of file
RECORD
999
EMPTY
...
ZK−6057−GE
Relative files are used like tables. Their advantage over tables is that their
size is limited to disk space rather than memory space. Also, their information
can be saved from run to run. Relative files are best for records that are easily
associated with ascending, consecutive numbers (so that the program conversion
from data to cell number is easy), such as months (record keys 1 to 12), or the 50
U.S. states (record keys 1 to 50).
Indexed File Organization
An indexed file uses primary and alternate keys in the record to retrieve the
contents of that record. Compaq COBOL allows sequential, random, and dynamic
access to records. You access each record by one of its primary or alternate keys.
Indexed file processing is available only on disk devices.
Unlike the sequential ordering of records in a sequential file or the relative
positioning of records in a relative file, the physical location of records in indexed
file organization is transparent to the program. You can add new records to an
indexed file without recreating the file. You can also delete records, making room
for new records.
6–6 Processing Files and Records