COBOL Manual for TNS and TNS/R Programs

Disk Input and Output
HP COBOL Manual for TNS and TNS/R Programs522555-006
28-27
Repositioning to New Record With Same Alternate
Key
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 useful for servers.
The server need only be implemented with a continuation request and can depend on
the requester to supply LOW-VALUES (or 1) for the prime key in the initial request.
Example 28-12 is a skeleton program for a server. It accepts several types of request,
one of which calls for a list of part records (beginning at a specified part name) to be
returned to the requester. If more than 10 such records must be returned, the requester
must accept 10 at a time and request the next portion by passing back the last part
number it received and the part name. This program is incomplete and is provided only
to illustrate the POSITION phrase of the START statement.
Example 28-12. Use of START With the POSITION Phrase (page1of4)
IDENTIFICATION DIVISION.
PROGRAM-ID. PART-LIST-SERVER.
AUTHOR. KELLY COBOL.
ENVIRONMENT DIVISION.
CONFIGURATION SECTION.
SOURCE-COMPUTER. TXP.
OBJECT-COMPUTER. TXP.