Module 6: CICS File Handling
READPREV
The READPREV command reads the previous record in a browse sequence, moving backward through the file. It uses the same options as READNEXT and is the tool for reverse browsing, for example scrolling up through a list of customers.
Syntax of the READPREV 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 it 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.
- READPREV cannot be used with a STARTBR that includes the GENERIC option.
Browsing backwards and changing direction
- To browse backwards from the end of the file, move HIGH-VALUE to the RIDFLD field before STARTBR, then issue READPREV calls.
- When there are no more records in the backward direction, the ENDFILE condition is raised - just like with READNEXT.
- Changing direction takes an extra read: to get the previous record after a READNEXT, code two READPREV commands. To get the next record after a READPREV, code two READNEXT commands.
- If you STARTBR with a value other than HIGH-VALUE and want the record before it, issue one READNEXT followed by two READPREVs.
- Example:-
* Browse backwards from the end of the file 2100-START-CUSTOMER-BACKWARD. MOVE HIGH-VALUE TO CM-CUSTOMER-NUMBER. EXEC CICS STARTBR FILE('CUSTMAS') RIDFLD(CM-CUSTOMER-NUMBER) RESP(RESPONSE-CODE) END-EXEC. 2200-READ-PREV-CUSTOMER. EXEC CICS READPREV FILE('CUSTMAS') INTO(CUSTOMER-MASTER-RECORD) RIDFLD(CM-CUSTOMER-NUMBER) RESP(RESPONSE-CODE) END-EXEC. IF RESPONSE-CODE = DFHRESP(ENDFILE) MOVE 'Y' TO CUSTOMER-BOF-SW ELSE IF RESPONSE-CODE NOT = DFHRESP(NORMAL) PERFORM 9999-TERMINATE-PROGRAM END-IF.
