TSO-ISPF JCL COBOL VSAM DB2 CICS Tools Articles Job Portal Forum Quiz Interview Q&A

CICS READNEXT Command


The READNEXT command retrieves the records sequentially in the order set by the STARTBR command. The RIDFLD is automatically updated by CICS for the next READ; application programs NEED NOT update this. RIDFLD can be set to a value greater than the present RIDFLD that is fetched. If a READNEXT is performed in this manner, it is called ‘skip sequential processing’.

Syntax:

Below is the syntax for READNEXT command.

EXEC CICS READNEXT
          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.


Let us see the parameters used in the READNEXT command.

  • FILE(file-name)

    Specifies the name of the file to be accessed.

  • RIDFLD(data-area)

    Specifies the record identification field.

    It has the name of the data area containing the key of the record which we want to read.

  • INTO(data-area)

    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

  • LENGTH(WS-LENGTH)

    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.

  • KEYLENGTH(data-value)

    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.

  • REQID(data-value)

    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.

  • SYSID(system-name)

    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!

Are you looking for Job Change? Job Portal