Processing Files and Records
6.1 Defining Files and Records
Figure 6–3 Line Sequential File Organization
End of file
...
ZK−6813A−GE
Beginning of file
RECORD
1
RECORD
2
RECORD
(n−1) n
RECORD
Record Terminators
Line Sequential File Organization
Line sequential file structure is essentially similar to the structure of sequential
files, with the major difference being record length. Figure 6–3 illustrates line
sequential file organization.
A line sequential file consists of records of varying lengths arranged in the order
in which they were written to the file. Each record is terminated with a ‘‘newline’’
character. The newline character is a line feed record terminator (’0A’ hex).
Each record in a line sequential file should contain only printable characters and
should not be written with a WRITE statements that contains either a BEFORE
ADVANCING or AFTER ADVANCING statement.
Record length is determined by the maximum record length in the FD entry in
the FILE-CONTROL section and the number of characters in a line (not including
the record terminator).
When your Compaq COBOL program reads a line from a line sequential file that
is shorter than the record area, it reads up to the record terminator, discards
the record terminator, and pads the rest of the record with a number of spaces
necessary to equal the record’s specified length. When your program reads a line
from a line sequential file that is longer than the record area, it reads the number
of characters necessary to fill the record area. The next READ, if any, will begin
at the next printable character in the file that is not a record terminator.
Line sequential file organization is useful in reading and printing files that were
created by an editor or word processor, which typically do not write fixed-length
records.
Relative File Organization
A relative file consists of fixed-size record cells and uses a key to retrieve its
records. The key, called a relative key, is an integer that specifies the record’s
storage cell or record number within the file. It is analogous to the subscript of a
table. Relative file processing is available only on disk devices.
Any record on a relative file (unlike a sequential file) can be accessed with one
READ operation. Also, relative files allow the program to read forward with
respect to the current relative key. In addition to random access by relative
key, relative files also permit you to delete and update records by relative key.
Relative files are used primarily when records must be accessed in random order
and the records can easily be associated with numbers that give the relative
positions in the file.
Processing Files and Records 6–5