COBOL Manual for TNS and TNS/R Programs
Disk Input and Output
HP COBOL Manual for TNS and TNS/R Programs—522555-006
28-24
Positioning
Approximate Positioning
With approximate positioning, you execute the START statement with a starting key,
and the next READ statement retrieves the next record in the access path that
contains a value in the corresponding data item that bears the stated relationship
(equal to, greater than, or not less than) to the starting key. Subsequent READ
statements receive the records that follow in the access path. An EOF condition arises
when the actual end of the file is reached.
Approximate positioning is the default, but you can include an APPROXIMATE phrase
in the START statement for documentation purposes if necessary.
Generic Positioning
Generic positioning is like approximate positioning except that you specify a starting
key that (usually) has a shorter length than the key data item in the record. Also, the
only relation permitted with the key is the equal relation. Subsequent READ statements
retrieve the records in the access path whose key values match the starting key for as
many characters as the start key has.
Suppose you want to read only the Adamses in the personnel file described in Key of
Reference. With the GENERIC phrase of the START statement (an HP extension to
COBOL), you specify that when a READ NEXT statement obtains a record with a
LAST-NAME value that does not begin with the five characters “Adams,” the statement
must raise the EOF condition and not deliver that record to the program.
You usually use generic positioning with partial keys. Using key values that include
trailing spaces, you can achieve an effect similar (but not identical) to exact positioning.
Consider the case of “Adams.” If you want to find only the Adamses (but not any
Adamsons), you can use a complete key of “Adams” plus enough spaces to fill out the
key.
Suppose that an HP COBOL program includes the code in Example 28-11
.
Table 28-5. Enscribe File Positioning Modes
Positioning
Mode
Starting
Position Defined
by End of File Is Signaled
Available in
HP COBOL?
Exact
Positioning
Whole key value When key no longer identical
to start key
No
Approximate
Positioning
Whole or partial
key value
At physical end of file Yes
Generic
Positioning
Whole or partial
key value
When key or partial key no
longer identical to start key
Yes