Example 1: keyed-sequential insertion (KSDS, variable-length RRDS)

In this example, a PUT macro is used to perform keyed-sequential insertion in a key-sequenced data set or variable-length RRDS. Variable-length records with a key length of 15 bytes are moved from a work area. Some records are inserted between existing records; other records are added at the end of the data set.
BLOCK    ACB   DDNAME=OUTPUT,                                          x
               MACRF=(KEY,SEQ,OUT)
 
LIST     RPL   ACB=BLOCK,                                              x
               AREA=BUILDRCD,                                          x
               AREALEN=250,                                            x
         .     OPTCD=(KEY,SEQ,                                         x
         .     SYN,NUP,MVE)
         .
LOOP     L     2,source          Put length of record to be inserted   x
                                 into register.
 
         MODCB RPL=LIST,         Indicate record length in request     x
               RECLEN=(2)        parameter list.
 
         LTR   15,15
         BNZ   CHECKO
         PUT   RPL=LIST
         LTR   15,15
         BNZ   ERROR
         B     LOOP
CHECKO   ...                     Modification failed.
ERROR    ...                     Request was not accepted, or failed.
BUILDRCD DS    CL250             Work area for building records.

The request parameter list, LIST, is associated with the access method control block, BLOCK. The length of each record to be inserted is put into register 2, which is subsequently used by MODCB to change the record length in the request parameter list. The record length is, therefore, correctly indicated in the request parameter list before the PUT macro is issued. The execution of the PUT macro causes VSAM to skip ahead (never back) to the next record.