Example 4: addressed-sequential retrieval (ESDS)

In this example, one GET macro is used to retrieve multiple fixed-length, 20-byte records. The records are moved to a work area (only option).
BLOCK   ACB    DDNAME=INPUT,                                           x
        .      MACRF=(ADR,SEQ,                                         x
        .      IN)
        .
        GENCB  BLK=RPL,                                                x
               COPIES=10,                                              x
               ACB=BLOCK,                                              x
               OPTCD=(ADR,SEQ,                                         x
               SYN,NUP,MVE)
 
        LTR    15,15
        BNZ    CHECK0
        LA     3,10           Number of lists(10).
        LR     2,1            Address of the first list.
 
        LR     1,0            Length of all of the lists.  Registers 0 x
                              and 1 contain length and address of the  x
                              generated control blocks when VSAM       x
                              returns control after GENCB.
 
        SR     0,0            Prepare for following division.
 
        DR     0,3            Divide number of lists into length of    x
                              all the lists.
 
        LR     3,1            Save the resulting length of a single    x
                              list for an offset.
 
        LR     4,2            Save address of the first list.
 
        LA     5,RECAREA      Address of the first work area. Do the   x
        .                     following 6 instructions 10 times to set x
        .                     up all the request parameters lists. The x
                              10th time, register 4 must be set to 0   x
                              to indicate the last request parameter   x
                              list in the chain.
 
        AR     4,3            Address the next list.
 
        MODCB  RPL=(2),       In each request parameter list, indicate x
               NXTRPL=(4),    the address of the next list and the     x
               AREA=(5),      address and length of the work area.     x
               AREALEN=20
        LTR    15,15
        BNZ    CHECK0
        AR     2,3            Address the next list.
        LA     5,20(5)        Address the next work area. Restore      x
        .                     register 2 to address the first list     x
        .                     before continuing to process.
LOOP    GET    RPL=(2)
        LTR    15,15
        BNZ    ERROR          Process the 10 records that have been    x
        .                     retrieved by the GET.
        .
        B      LOOP
CHECK0  ...
ERROR   ...                   Display the feedback field (FIELDS=FDBK) x
                              of each request parameter list to find   x
                              out which one had an error.
 
RECAREA DS     CL200          Space for a work area for each of the    x
                              10 request parameter lists.

The GENCB macro generates 10 request parameter lists; the lists are subsequently chained together by using the MODCB macro to modify the NXTRPL parameter in each copy. Because SEQ is specified in each request parameter list, and no previous request has been issued against the access method control block since it was opened, retrieval begins at the beginning of the data set. Each time the GET macro is executed, VSAM is positioned at the next record in RBA sequence. VSAM moves each record into the work area provided for the request parameter list that identifies the record.

If an error occurs for one of the request parameter lists in the chain and you supply error-analysis routines, VSAM takes a LERAD or SYNAD exit before returning to your program. Register 15 is set to indicate the status of the request. A code of 0 indicates that no error was associated with any of the request parameter lists. Any other code indicates that an error occurred for one of the request parameter lists. You should issue a SHOWCB macro for each request parameter list in the chain to find out which had an error. VSAM does not process any of the request parameter lists except the one with an error.