Rational Developer for System z
Enterprise PL/I for z/OS, Version 3.8, Programming Guide

Accessing and updating a REGIONAL(1) data set

Once you create a REGIONAL(1) data set, you can open the file that accesses it for SEQUENTIAL INPUT or UPDATE, or for DIRECT INPUT or UPDATE. You can open it for OUTPUT only if the existing data set is to be overwritten. Table 21 shows the statements and options for accessing a regional data set.

Sequential access

To open a SEQUENTIAL file that is used to process a REGIONAL(1) data set, use either the INPUT or UPDATE attribute. You must not include the KEY option in data transmission statements, but the file can have the KEYED attribute, since you can use the KEYTO option. If the target character string referenced in the KEYTO option has more than 8 characters, the value returned (the 8-character region number) is padded on the left with blanks. If the target string has fewer than 8 characters, the value returned is truncated on the left.

Sequential access is in the order of ascending region numbers. All records are retrieved, whether dummy or actual, and you must ensure that your PL/I program recognizes dummy records.

Using sequential input with a REGIONAL(1) data set, you can read all the records in ascending region-number sequence, and in sequential update you can read and rewrite each record in turn.

The rules governing the relationship between READ and REWRITE statements for a SEQUENTIAL UPDATE file that accesses a REGIONAL(1) data set are identical to those for a consecutive data set. Consecutive data sets are discussed in detail in Defining and using consecutive data sets.

Direct access

To open a DIRECT file that is used to process a REGIONAL(1) data set you can use either the INPUT or the UPDATE attribute. All data transmission statements must include source keys; the DIRECT attribute implies the KEYED attribute.

Use DIRECT UPDATE files to retrieve, add, delete, or replace records in a REGIONAL(1) data set according to the following conventions:

Retrieval
All records, whether dummy or actual, are retrieved. Your program must recognize dummy records.
Addition
A WRITE statement substitutes a new record for the existing record (actual or dummy) in the region specified by the source key.
Deletion
The record you specify by the source key in a DELETE statement is converted to a dummy record.
Replacement
The record you specify by the source key in a REWRITE statement, whether dummy or actual, is replaced.

Example

Updating a REGIONAL(1) data set is illustrated in Figure 33. This program updates the data set and lists its contents. Before each new or updated record is written, the existing record in the region is tested to ensure that it is a dummy; this is necessary because a WRITE statement can overwrite an existing record in a REGIONAL(1) data set even if it is not a dummy. Similarly, during the sequential reading and printing of the contents of the data set, each record is tested and dummy records are not printed.

Figure 33. Updating a REGIONAL(1) data set
 //EX10    JOB
 //STEP2   EXEC  IBMZCBG,PARM.PLI='NOP,MAR(1,72)',PARM.BIND='LIST'
 //PLI.SYSIN  DD  *
  ACR1: PROC OPTIONS(MAIN);
    /*  UPDATING A REGIONAL(1) DATA SET  -  PHONE DIRECTORY      */
     DCL NOS FILE RECORD  KEYED ENV(REGIONAL(1));
     DCL  SYSIN FILE INPUT RECORD;
     DCL  (SYSIN_REC,NOS_REC) BIT(1) INIT('1'B);
     DCL 1   CARD,
          2   NAME   CHAR(20),
          2   (NEWNO,OLDNO)  CHAR( 2),
          2   CARD_1 CHAR( 1),
          2   CODE   CHAR( 1),
          2   CARD_2 CHAR(54);
     DCL IOFIELD CHAR(20);
     DCL BYTE    CHAR(1) DEF IOFIELD;

    ON ENDFILE(SYSIN) SYSIN_REC = '0'B;
    OPEN FILE (NOS) DIRECT UPDATE;
    READ FILE(SYSIN) INTO(CARD);

    DO WHILE(SYSIN_REC);
       SELECT(CODE);
          WHEN('A','C') DO;
              IF CODE = 'C' THEN
                 DELETE FILE(NOS) KEY(OLDNO);
              READ FILE(NOS) KEY(NEWNO) INTO(IOFIELD);
              IF UNSPEC(BYTE) = (8)'1'B
                 THEN WRITE FILE(NOS) KEYFROM(NEWNO) FROM(NAME);
              ELSE PUT FILE(SYSPRINT) SKIP LIST ('DUPLICATE:',NAME);
          END;
          WHEN('D') DELETE FILE(NOS) KEY(OLDNO);
       OTHERWISE PUT FILE(SYSPRINT) SKIP LIST ('INVALID CODE:',NAME);
       END;
       READ FILE(SYSIN) INTO(CARD);
    END;

    CLOSE FILE(SYSIN),FILE(NOS);
    PUT FILE(SYSPRINT) PAGE;
    OPEN FILE(NOS) SEQUENTIAL INPUT;
    ON ENDFILE(NOS) NOS_REC = '0'B;
    READ FILE(NOS) INTO(IOFIELD) KEYTO(NEWNO);
    DO WHILE(NOS_REC);
       IF UNSPEC(BYTE) ¬= (8)'1'B
          THEN PUT FILE(SYSPRINT) SKIP EDIT (NEWNO,IOFIELD)(A(2),X(3),A);
       PUT FILE(SYSPRINT) SKIP EDIT (IOFIELD) (A);
       READ FILE(NOS) INTO(IOFIELD) KEYTO(NEWNO);
    END;
   CLOSE FILE(NOS);
   END ACR1;
 /*
 //GO.NOS   DD DSN=J44PLI.NOS,DISP=(OLD,DELETE),UNIT=SYSDA,VOL=SER=nnnnnn
 //GO.SYSIN DD *
 NEWMAN,M.W.         5640 C
 GOODFELLOW,D.T.     89   A
 MILES,R.              23 D
 HARVEY,C.D.W.       29   A
 BARTLETT,S.G.       13   A
 CORY,G.               36 D
 READ,K.M.           01   A
 PITT,W.H.             55
 ROLF,D.F.             14 D
 ELLIOTT,D.          4285 C
 HASTINGS,G.M.         31 D
 BRAMLEY,O.H.        4928 C
 /*

Terms of use | Feedback

This information center is powered by Eclipse technology. (http://www.eclipse.org)