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

54116 ADAMS-JONES
54396 ADAMSSOHN
Without the GENERIC phrase, if the first key is “ADAMS” followed by 30 spaces, the program
displays:
00005---ADAMS
01010---ADAMS
54116---ADAMS-JONES
00010---ADAMSKI
54396---ADAMSSOHN
00121---JOHNSON
12532---REITWIESNER
52353---ROTH
43132---SMITH
99999-----EOF
With the GENERIC phrase, if the first key specifies that its first five characters must be “ADAMS,
the program displays:
00005---ADAMS
01010---ADAMS
54116---ADAMS-JONES
00010---ADAMSKI
54396---ADAMSSOHN
99999-----EOF
Repositioning to New Record With Same Alternate Key
COBOL provides no mechanism for repositioning to one of several records having the same
alternate key. HP COBOL provides a mechanism: the POSITION phrase of the START statement.
The POSITION phrase enables you to write context-free servers that must return large sets of records
to their requesters. Suppose you want your server to return one record for each product that includes
part number 1345-55433. To keep message length and buffer space to a reasonable size, the
server can return only 10 records. A server should not retain a context from a requester. Each
server should be able to serve any requester.
The POSITION phrase can specify the prime key, a leftmost subordinate of the prime key, an
alternate key, or a leftmost subordinate of an alternate key in the KEY phrase. The prime-key value
is in a separate data item; it need not be inserted in the record area of the file.
The POSITION phrase enables a server to pass the value of the prime key of the most recently
processed record back to a requester. The requester can then send the prime-key value to a server
with its next request, and the server can use that value in a POSITION phrase of the START statement
(and also as the alternate key in the KEY phrase) to uniquely specify a record at which to resume
processing.
The POSITION phrase includes the optional keyword, AFTER. Without AFTER, the START statement
establishes the current file position at the same record specified by the prime-key value. With
AFTER, the START statement establishes the current file position at the next record (if any) after the
record specified by the prime-key value in the POSITION phrase.
The role of the POSITION phrase is to reestablish the environment after the last read using a partial
key. The execution of a START statement with a POSITION phrase does not report an invalid-key
condition—the next READ statement executed could report an EOF condition.
To resume processing a file after an interruption, take the same START statement that you used to
initiate processing and add a POSITION phrase, specifying the key relation EQUAL.
It might be possible to collapse the initial START statement and the repositioning START statement
into a single statement when it is not important for the initial positioning operation to detect an
invalid-key condition if no record matches the key relation in a normal initial start operation. If this
is acceptable, write the program for just the continuation repositioning case and use LOW-VALUES
for the prime record key (or 1 for the relative key) in the initial case. This strategy is especially
Establishing Starting Points in Files 873