Previous Page | Next Page

Processing VSAM Data Sets in SAS Programs

Updating Records in VSAM Data Sets


Introduction to Updating Records

Performing an update operation involves both input access (because the record must be read first) and output access (because you update by writing to the data set). Input access for an update can be either sequential or direct. Output access is sequential unless one of the direct access variables (KEY=, RRN=, or RBA=) is specified. When you update an existing record in a VSAM data set, you must use the following options and statements:

  1. specify the VSAMUPDATE system option.

  2. include both an INFILE and a FILE statement with the same fileref and the VSAM option in the DATA step. Specify all other options in the INFILE statement, which must precede the FILE statement.

  3. use an INPUT statement to read the record that is being modified.

  4. use the PUT statement to write the complete record. An INPUT statement brings the record into the INPUT buffer but does not copy it to the PUT buffer. This method enables you to change the record easily.

There are two common ways of writing the record with the PUT statement:

The latter method is the easiest for most applications. The following statement copies the last record read into the PUT buffer and overlays the information starting in columns 10 and 30 with the values in NEWDATA1 and NEWDATA2:

   PUT @ 1  _INFILE_
       @ 10 NEWDATA1
       @ 30 NEWDATA2;


Limitations on Updating Records

To maintain data integrity in multiple update situations, VSAM uses operating system facilities to protect the data. However, when either SHROPTIONS(3 X) or (4 X) is specified (full sharing by any number of users) and records in the same control area are updated simultaneously, some of the updates might be lost (X is any value). When SHROPTIONS(3 X) is used, each user is responsible for maintaining both Read and Write integrity for the data the program accesses. SHROPTIONS(4 X) requires your program to use the ENQ and DEQ macros to maintain data integrity while sharing the data set. For more information on using ENQ and DEQ, see IBM documentation.


Using the UPDATE= Option

Sometimes a program accessing a VSAM data set reads many records but updates only a few of the records. When a record is retrieved for update, no other user, including you, can access that particular record or any other records in the same control interval until you release the record by executing another PUT or an INPUT statement for the data set. (This is significant when a VSAM data set is simultaneously accessed by other users or by an online system, such as CICS.) Use the UPDATE= option in the INFILE statement to avoid user lockout when only a few of the records that are retrieved need to be updated.

The UPDATE= option specifies a numeric SAS variable that indicates whether a record is to be read only or updated.

If you retrieve a record with the UPDATE= variable set to 0 (that is, the record is not retrieved for update) and then decide that you do want to update the record, reset the UPDATE= variable to 1, retrieve the record again, and then update the record. This is possible only with direct access. If you are reading the data set sequentially, you must keep track of the records that you want to update (use a SAS data set for this) and read them for update in a subsequent DATA step.

Previous Page | Next Page | Top of Page