COBOL Manual for TNS and TNS/R Programs

Disk Input and Output
HP COBOL Manual for TNS and TNS/R Programs522555-006
28-13
Structured Files
The record numbers of a relative file need not be consecutive; Enscribe does not
require that there be a record for each ordinal number between that of the first record
and the highest number associated with any record in the file. If the HP COBOL run-
time routines ask Enscribe for the record associated with a certain number and there is
no such record in the file, Enscribe reports that no such record exists, and the
HP COBOL run-time routine raises the invalid-key condition (and, if you defined a file
status code data item, the run-time routine stores an appropriate value in it).
You can also read the file in record-number order. In this case, Enscribe does not
report absent records—it returns the records that exist. Enscribe can report the record
number of each record as it is read. When you read a relative file this way, the
HP COBOL run-time routines set the relative key data item to reflect the record
number.
Both Enscribe and HP COBOL (as an HP extension) provide two special record
numbers: -1 and -2. If you specify record number -1, a record is written at the end of
the file; if you specify record number -2, a record is written in the next available
position.
Enscribe allocates the same fixed amount of disk storage to each record. Each record
can vary in length from empty to that fixed limit. In HP COBOL terms, you can write
fixed-length records of any length up to the limit, or variable-length records of any
length up to the limit. If HP COBOL creates the file for you, that limit is the larger of:
The length of the longest record description entry for the file
The maximum record length explicitly stated in the RECORD clause of the file
description entry for the file
If a relative file has alternate keys, you can use a START statement not only to specify
the next record to read, but also to change the key of reference.
You can write anywhere in the file, replacing existing records or installing a record at an
ordinal position that had no record associated with it. You can replace an existing
record with a record of a different length. You can delete a record. A deleted record is
not the same as a record of length zero. A read operation with an invalid key leaves
the contents of the record area undefined (that is, unpredictable).
Key-Sequenced (Indexed or Queue) Files
Key-sequenced files contain records that are stored in independent positions on the
disk, but accessed in ascending sequence ordered by the unique value of a field within
each record. Enscribe calls this field the prime record key; HP COBOL calls it the
prime record key. You can read any record by specifying its key value.
A key-sequenced file can be incomplete; Enscribe does not require that there be a
record for each possible key value. If HP COBOL run-time routines ask Enscribe for
the record associated with a certain key value, and there is no such record in the file,
Enscribe reports that no such record exists and the HP COBOL run-time routine raises
the invalid-key condition (and, if you defined a file status code data item, stores an
appropriate value in it).