Example 6: keyed-direct retrieval (KSDS, RRDS)

In this example, a GET macro is used to retrieve fixed-length, 100-byte records directly by key. The key length is 15 bytes; the search argument is a 5-byte generic key, compared equal. The control blocks are generated at assembly.
INPUT   ACB    MACRF=(KEY,                                             x
               DIR,IN)
 
RETRVE  RPL    ACB=INPUT,       Specify all parameters for the request x
               AREA=IN,         in the RPL macro.                      x
               AREALEN=4,                                              x
               OPTCD=(KEY,                                             x
               DIR,SYN,NUP,                                            x
               KEQ,GEN,LOC),                                           x
               ARG=KEYAREA,                                            x
        .      KEYLEN=5
        .
LOOP    MVC    KEYAREA,SOURCE   Search argument for retrieval, moved   x
                                in from a table or a transaction       x
                                record.
 
        GET    RPL=RETRVE       This GET or identical GETs can be      x
                                issued with no change in the RPL:      x
                                specify each new search argument in    x
                                the field KEYAREA.
        LTR    15,15
        BNZ    ERROR
        .                       Process the record.
        .
        B      LOOP
ERROR   ...                     Request was not accepted, or failed.
        .
IN      DS     CL4              VSAM puts here the address of the      x
                                record within the I/O buffer.
KEYAREA DS     CL5              You specify the search argument here.

The generic key specifies a class of records. For example, if you search on the first third of employee number, VSAM positions at and retrieves the first of several records starting with the specified characters. To retrieve all the records in that class, either switch to sequential access or to a full-key search with a greater-than-or-equal comparison.

The search argument can be a key or relative record number. If the data set is a variable-length RRDS, supply the record length in the RECLEN field in the RPL.