Example 2: addressed-sequential deletion (ESDS, KSDS)

In this example, the ERASE macro is used to delete records from a key-sequenced data set. Not every record retrieved for deletion is deleted. The POINT macro is used to skip records.
DELETE   ACB   MACRF=(ADR,SEQ,                                          x
               OUT)
 
REQUEST  RPL   ACB=DELETE,                                              x
               AREA=WORK,                                               x
               AREALEN=100,                                             x
               ARG=ADDR,                                                x
               OPTCD=(ADR,SEQ,                                          x
               ASY,UPD,MVE)          UPD indicates deletion.
               .
LOOP           ...                   Decide whether you need to skip    x
                                     to another position (forward or    x
                                     backward).
 
         B     RETRIEVE              No; bypass the POINT.
 
         MVC   ADDR,source           Yes; move search argument for      x
                                     POINT into search-argument field.
 
         POINT RPL=REQUEST           Position VSAM to the record to     x
                                     be retrieved next.
         LTR   15,15
         BNZ   ERROR
         CHECK RPL=REQUEST
         LTR   15,15
         BNZ   ERROR
RETRIEVE GET   RPL=REQUEST
         LTR   15,15
         BNZ   ERROR
         CHECK RPL=REQUEST
         LTR   15,15
         BNZ   ERROR
Decide whether to delete the record.
         BE    LOOP                 No; skip ERASE and CHECK.
         ERASE RPL=REQUEST          Yes; delete the record.
         LTR   15,15
         BNZ   ERROR
         CHECK RPL=REQUEST
         LTR   15,15
         BNZ   ERROR
         B     LOOP
ERROR    ...                         Request not accepted, or failed.
         .
ADDR     DS    F                     RBA search argument for POINT.
WORK     DS    CL100                 Work area.

Addressed deletion is allowed only for a key-sequenced data set. The records of an entry-sequenced data set are fixed. When records are deleted from a key-sequenced data set using addressed deletion, the index is not updated.