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

Procedure Division Verbs
HP COBOL Manual for TNS/E Programs520347-003
9-237
START
Example 9-64 reads all records for employees whose last names start with G.
Example 9-65, fragments of a server program, shows the use of a START statement
with a POSITION phrase. The query the server gets through $RECEIVE includes a
department number and a unique employee number. The server is to return an array
containing information about all employees in the specified department.
At the first call, the requester sends the chosen department number but an employee
number of zero. If there are more than ten employees in a department, the server
reports only the first ten it found. The requester can then send another query, but this
time it includes the employee number of the last array entry of the previous reply. By
using this technique, the server remains context-free, able to serve another requester.
When the server executes the START statement, the key of reference used with the
GENERIC phrase is still the department number, but the presence of a unique record
key value of EMP-NO in the AFTER POSITION phrase says to resume reading along
the DEPT-NO path after the record for the specified employee.
Example 9-64. START Statement With GENERIC Phrase for Sequential File
SELECT INPUT-FILE ASSIGN TO "INFILE"
ORGANIZATION IS SEQUENTIAL
ACCESS MODE IS SEQUENTIAL
ALTERNATE RECORD KEY IS EMP-NAME
WITH DUPLICATES.
...
FD INPUT-FILE
LABEL RECORDS ARE OMITTED
RECORD CONTAINS 95 CHARACTERS
DATA RECORD IS PERSONNEL-DATA.
01 PERSONNEL-DATA.
05 DEPT-NO PIC 9(5).
05 EMPLOYEE-NO PIC 9(7).
05 EMP-NAME.
10 LAST-NAME.
15 FIRST-LETTER PIC X.
15 FILLER PIC X(14).
10 FIRST-NAME PIC X(9).
...
PROCEDURE DIVISION.
...
OPEN I-O INPUT-FILE
...
MOVE "G" TO FIRST-LETTER
START INPUT-FILE KEY = FIRST-LETTER GENERIC
INVALID KEY GO TO START-ERROR-ROUTINE
END-START
READ INPUT-FILE
AT END