Module 6: CICS File Handling
READNEXT
The READNEXT command reads the next record in a browse sequence, moving forward through the file. It is used together with STARTBR (which positions the browse) and ENDBR (which ends it).
Syntax of the READNEXT command
- FILE - the file name from the File Control Table.
- INTO - the area that will hold the record being read.
- RIDFLD - the field identifying the record. CICS updates this field with the key, RRN or RBA of the record just read.
- RRN - the RIDFLD value is a relative record number.
- RBA - the RIDFLD value is a relative byte address.
- KEYLENGTH - a binary halfword or literal giving the key length, usually used with the GENERIC option of STARTBR.
A typical READNEXT procedure
- When there are no more records in the forward direction, the ENDFILE condition is raised. Test for it and set an EOF switch to end the loop.
- After each successful READNEXT, the RIDFLD field holds the key of the record just read, ready for the next call.
- You can reposition the browse by changing the RIDFLD value before issuing READNEXT; the record with that key is then retrieved.
- Example:-
2100-READ-NEXT-INVOICE. EXEC CICS READNEXT FILE('INVOICE') INTO(INVOICE-RECORD) RIDFLD(INV-INVOICE-NUMBER) RESP(RESPONSE-CODE) END-EXEC. IF RESPONSE-CODE = DFHRESP(ENDFILE) MOVE 'Y' TO INVOICE-EOF-SW ELSE IF RESPONSE-CODE NOT = DFHRESP(NORMAL) PERFORM 9999-TERMINATE-PROGRAM END-IF END-IF.
