COBOL Manual for TNS and TNS/R Programs

Disk Input and Output
HP COBOL Manual for TNS and TNS/R Programs522555-006
28-26
Repositioning to New Record With Same Alternate
Key
Suppose that NAME-FILE contains these records:
00005 ADAMS
00010 ADAMSKI
00121 JOHNSON
01010 ADAMS
12532 REITWIESNER
43132 SMITH
52353 ROTH
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.