z/OS DFSMS Macro Instructions for Data Sets
Previous topic | Next topic | Contents | Contact z/OS | Library | PDF


Example 8: switch from direct to sequential retrieval

z/OS DFSMS Macro Instructions for Data Sets
SC23-6852-02

In this example, GET macros are used to retrieve fixed-length, 100-byte records. The retrieval is by means of an alternate index path defined with the non-unique key option. Every time a non-unique key is retrieved, the program switches to sequential processing to retrieve the other records with the same key. The control blocks were generated at assembly, but the MODCB macro is used to modify the request parameter list to permit switching from keyed-direct to keyed-sequential retrieval. For the direct request preceding sequential requests, the search argument is an 8-byte, generic key, compared equal. Positioning is requested for direct requests.
INPUT   ACB    MACRF=(KEY,DIR,   Both direct and sequential access     x
               SEQ,IN)           specified.
 
RETRVE  RPL    ACB=INPUT,        NSP specifies that VSAM is to         x
               AREA=IN,          remember its position.                x
               AREALEN=100,                                            x
               OPTCD=(KEY,DIR,                                         x
               SYN,NSP,KEQ,                                            x
               GEN,MVE),                                               x
               ARG=KEYAREA,                                            x
        .      KEYLEN=8
        .
LOOP    MVC    KEYAREA,source    Search argument for direct retrieval; x
                                 moved in from a table or a            x
                                 transaction.
LOOP1   GET    RPL=RETRVE
        LTR    15,15
        BNZ    ERROR
        .
        SHOWCB RPL=RETRVE,       Extract feedback information.         x
               AREA=FDBAREA,                                           x
               FIELDS=FDBK
        LTR    15,15
        BNZ    ERROR
        CLI    ERRCD,8           Does a duplicate key follow?
 
        BE     SEQ               Yes; retrieve duplicates              x
                                 sequentially.
 
        B      LOOP              No; retrieve next record in direct    x
                                 mode.
SEQ     MODCB  RPL=RETRVE,       Alter request parameter list for      x
               OPTCD=SEQ         sequential access.
        LTR    15,15
        BNZ    CHECKO
SEQGET  GET    RPL=RETRVE        Do sequential retrieval.
        LTR    15,15             Test for error.
        BNZ    ERROR
        .
        SHOWCB RPL=RETRVE,       Extract feedback information.         x
               AREA=FDBAREA,                                           x
               FIELDS=FDBK
        LTR    15,15
        BNZ    ERROR
        CLI    ERRCD,8           Does a duplicate key follow?
        BE     SEQGET            Yes; retrieve sequentially.
DIR     MODCB  RPL=RETRVE,       Alter request parameter list for      x
               OPTCD=DIR         direct access.
        LTR    15,15
        BNZ    CHECKO
        B      LOOP              Prepare new search argument.
ERROR   ...                      Request was not accepted, or failed.
CHECKO  ...                      Modification failed.
        .
IN      DS     CL100             VSAM puts retrieved records here.
 
KEYAREA DS     CL8               Specify the generic key for a direct  x
                                 request here.
FDBAREA DS     OF                Feedback area for SHOWCB.
        DS     1C                Reserved.
TYPECD  DS     1C                Error type code.
CMPCD   DS     1C                Component code.
ERRCD   DS     1C                Reason code.

Positioning is associated with a request parameter list; the MODCB macro modifies a single request parameter list that alternately defines requests for both types of access rather than using a different request parameter list for each type.

With direct retrieval, VSAM does not remember its position for subsequent sequential retrieval unless you explicitly request it (OPTCD=NSP or UPD). After a direct GET for update, VSAM is positioned for a subsequent PUT, ERASE, or sequential GET. If you modify OPTCD=(DIR,NUP) to OPTCD=SEQ, you must issue POINT to get VSAM positioned for sequential retrieval, as NUP indicates that no positioning is desired with a direct GET.

If you have chained many request parameter lists together, one position is remembered for the whole chain. For example, if you issue a GET that gives the address of the first request parameter list in the chain, the position of VSAM when the GET request is complete is at the record following the record defined by the last request parameter list in the chain. Therefore, modifying OPTCD=(DIR,NSP) in each request parameter list in a chain to OPTCD=SEQ implies continuing with sequential access relative to the last of the direct request parameter lists.

Go to the previous page Go to the next page




Copyright IBM Corporation 1990, 2014