With Overlapped Operations

To overlap I/O and processor activity, you can start several read or write operations before checking the first for completion. You cannot overlap read and write operations. However, as operations of one type must be checked for completion before operations of the other type are started or resumed. Note that each outstanding read or write operation requires a separate DECB. If a single DECB were used for successive read operations, only the last record read could be updated.

In Figure 1, overlap is achieved by having a read or write request outstanding while each record is being processed.

Figure 1. Updating a Member of a PDS
   //PDSDD  DD      DSNAME=MASTFILE(MEMBERK),DISP=OLD,---
            ...
   UPDATDCB DCB     DSORG=PS,DDNAME=PDSDD,MACRF=(R,W),NCP=2,EODAD=FINISH
            READ    DECBA,SF,UPDATDCB,AREAA,MF=L           Define DECBA
            READ    DECBB,SF,UPDATDCB,AREAB,MF=L           Define DECBB
   AREAA    DS      ---                                    Define buffers
   AREAB    DS      ---
            ...
            OPEN    (UPDATDCB,UPDAT)                 Open for update
            LA      2,DECBA                          Load DECB addresses
            LA      3,DECBB
   READRECD READ    (2),SF,MF=E                      Read a record
   NEXTRECD READ    (3),SF,MF=E                      Read the next record
            CHECK   (2)                              Check previous read operation

(If update is required, branch to R2UPDATE)

         LR      4,3                              If no update is required,
         LR      3,2                              switch DECB addresses in
         LR      2,4                              registers 2 and 3
         B       NEXTRECD                         and loop
In the following statements, 'R2' and 'R3' refer to the records that were read using the DECBs whose addresses are in registers 2 and 3, respectively. Either register can point to either DECBA or DECBB.  
   R2UPDATE CALL    UPDATE,((2))                     Call routine to update R2
 
   * Must issue CHECK for the other outstanding READ before switching to WRITE.
   * Unfortunately this CHECK can send us to EODAD.
 
            CHECK   (3)                              Check read for next record
            WRITE   (2),SF,MF=E                      (R3) Write updated R2

(If R3 requires an update, branch to R3UPDATE)

            CHECK   (2)                              If R3 requires no update,
            B       READRECD                         check write for R2 and loop
   R3UPDATE CALL    UPDATE,((3))                     Call routine to update R3
            WRITE   (3),SF,MF=E                      Write updated R3
            CHECK   (2)                              Check write for R2
            CHECK   (3)                              Check write for R3
            B       READRECD                         Loop
   FINISH   EQU     *                                End-of-Data exit routine
(If R2 was not updated, branch to CLOSEIT)
            WRITE   (2),SF,MF=E                      Write last record read
            CHECK   (2)
   CLOSEIT  CLOSE   (UPDATDCB)

Note the use of the execute and list forms of the READ and WRITE macros, identified by the parameters MF=E and MF=L.