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

positioning and to establish the key of reference and the comparison length (for partial keys)
accompanies the request.
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).
Determining Key Value of Last Record of an Indexed or Queue File
To determine the key value of the last record of an indexed or queue file, which is especially
important when using the READ REVERSED statement, move HIGH-VALUES to the key and then
use the START statement with the relationship LESS THAN. START LESS THAN positions the
indexed file so that a READ NEXT or READ REVERSED statement accesses the last record in the
file.
Table 69 Using the POSITION and KEY Phrases
EffectLength Used and RestrictionKeyPosition-Key
Full value of alternate AND
of relative used
length (entire alternate) + 4
< 254
Alternate or alternate (1:n )
Relative key
Relative key
(ORGANIZATION RELATIVE)
START 457