The READPREV command retrieves records in the reverse order as set by the STARTBR command.
The file position can be changed by moving the new key value to the contents of RIDFLD before READNEXT or READPREV command.
Below is the syntax for READPREV command.
EXEC CICS READPREV FILE(file-name) RIDFLD(data-area) INTO(data-area) LENGTH(WS-LENGTH) KEYLENGTH(data-value) REQID(data-value) SYSID(system-name) END-EXEC.
READNEXT is used to read the records in the forward direction from the position established by STARTBR. READPREV is used to read the records in the reverse direction. READPREV followed by READNEXT retrieves the same record once again.
During the browse, if you want to skip set of records, then move the key of the next record you intended to read to RIDFLD and then issue READNEXT. This is called skip sequential read. Thus RIDFLD can be used as both input as well as output field.
As VSAM files are variable length in most of the cases, WS-LENGTH should be populated with maximum record length before issuing READ command. KEYLENGTH(0) will position the cursor at the beginning of the file.
If you specify READPREV immediately after STARTBR, then you should code key of a record that exists on the dataset. Otherwise NOTFND condition occurs on READPREV.
Let us see the parameters used in the READPREV command.
Specifies the name of the file to be accessed.
Specifies the record identification field.
It has the name of the data area containing the key of the record which we want to read.
Specifies the data area into which the record retrieved from the data set is to be written.
When INTO is specified, LENGTH must either be specified explicitly or must be capable of being defaulted from the INTO option using the length attribute reference in assembler language
It specifies the maximum number of characters that may be read into the data area specified. It must be a halfword binary value (PIC S9(4) COMP). After the READ command is completed, CICS replaces the maximum value we specify with the true length of the record. For this reason, we must specify LENGTH as the name of a data area rather than a literal and must re-initialize this data area if we use it for LENGTH more than once in the program. An longer record will raise an error condition.
Specifies the length (halfword binary) of the key that has been specified in the RIDFLD option, except when RBA or RRN is specified, in which case KEYLENGTH is not valid.
This option must be specified if GENERIC is specified, and it can be specified whenever a key is specified. If the length specified is different from the length defined for the data set and the operation is not generic, the INVREQ condition occurs.
Specifies as a halfword binary value a unique request identifier for a browse, used to control multiple browse operations on a file. If this option is not specified, a default value of zero is assumed.
Specifies the name of the system to which the request is directed.
If you have any doubts or queries related to this chapter, get them clarified from our Mainframe experts on ibmmainframer Community!