COBOL Manual for TNS/E Programs (H06.03+)

Procedure Division Verbs
HP COBOL Manual for TNS/E Programs520347-003
9-235
START
°
GENERIC Positioning Mode and the POSITION Phrase
The choice of APPROXIMATE or GENERIC positioning mode, coupled with
the KEY clause, govern where the next READ statement starts reading and
what constitutes the end of the file (or the beginning of the file, if the file is
being read in reverse). A common use of GENERIC involves reading all
records that have a common value in the leftmost subordinate of a given
alternate key; for example, all records that have a 10-character alternate key,
where the first five characters of that key have the value “A5R32.” Under the
GENERIC mode, the program reads records until it encounters one that has
something different in the first five characters for that alternate key, then the
program receives an end-of-file condition instead of a new record value.
Only if the file contains multiple records that have the same value for the
complete alternate key (not just the leftmost subordinate) can the POSITION
phrase be used as outlined in the general discussion earlier to process groups
of records.
°
BEFORE and AFTER Phrases
If neither the BEFORE phrase nor the AFTER phrase is included, the
execution of the START statement sets the file position indicator to point to the
record uniquely identified by the two key values.
If the BEFORE phrase is included, the execution of the START statement sets
the file position indicator to point to the record preceding the one that the two
key values uniquely identify.
If the AFTER phrase is included, the execution of the START statement sets
the file position indicator to point to the record following the one that the two
key values uniquely identify.
INSERTIONORDER Attribute Incompatible with POSITION Phrase
The POSITION phrase can be used only if the file on which the START statement
is operating has the NO INSERTIONORDER attribute; that is, records with
duplicate values of an alternate key are delivered in principal key order.
Next READ After a START with POSITION Might Fail
When you use the POSITION phrase, there is no guarantee that the record you
specify actually exists. In this aspect, the start-with-position operation differs from
the ordinary COBOL start operation. The positioning operation merely sets the file
position indicator to the file location where the record can be found if it exists;
therefore, the invalid-key condition does not occur when the record does not exist.
Instead, the first subsequent sequential READ statement encounters the at-end
condition (if the physical end of the file has been reached, or if the logical end of
file associated with the generic positioning mode has been reached).