COBOL Manual for TNS/E Programs (H06.08+, J06.03+)
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
Example 136, 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 136 START Statement With POSITION Phrase
SELECT EMP-FILE ASSIGN TO "EMPL1093"
ORGANIZATION IS INDEXED
ACCESS MODE IS DYNAMIC
RECORD KEY IS EMP-NO
ALTERNATE RECORD KEY IS DEPT-NO WITH DUPLICATES
ALTERNATE RECORD KEY IS EMP-NAME WITH DUPLICATES
FILE STATUS IS EMP-STATUS.
...
DATA DIVISION.
FILE SECTION.
...
FD EMP-FILE.
01 EMP-DATA.
05 EMP-NO PIC 9(6).
05 EMP-NAME PIC X(45).
05 EMP-DEPT PIC 9(7).
...
PROCEDURE DIVISION.
...
OPEN INPUT EMP-FILE
...
* Read $RECEIVE to get the query
READ REC-IN ...
* If this is an initial request, do a nonposition start
IF DEPT-NO OF EMP-LIST-REQUEST = ZEROS
START EMP-FILE KEY = DEPT-NO OF EMP-DATA
GENERIC
* Otherwise, resume after record last reply array ended with
START 459










