Preventing update problems with VSAM files in RLS mode
When you open a VSAM data set in RLS
mode
for I-O
(updates), the first READ
causes
an exclusive lock of the record regardless of the value of RLS
(RLS=CR
or RLS=NRI
)
that you specify.
About this task
If the COBOL file is defined as ACCESS RANDOM
,
VSAM releases the exclusive lock on the record after a WRITE
or REWRITE
statement
is executed or a READ
statement is executed for another
record. When a WRITE
or REWRITE
is
done, VSAM writes the record immediately.
However,
if the COBOL file is defined as ACCESS DYNAMIC
, VSAM
does not release the exclusive lock on the record after a WRITE
or REWRITE
statement,
nor after a READ
statement, unless the I-O statement
causes VSAM to move to another control interval (CI). As a result,
if a WRITE
or REWRITE
was done,
VSAM does not write the record until processing is moved to another
CI and the lock is released. When you use ACCESS DYNAMIC
,
one way to cause the record to be written immediately, to release
the exclusive lock immediately, or both, is to define the VSAM data
set to allow only one record per CI.
Specifying RLS=CR
locks
a record and prevents an update to it until another READ
is
requested for another record. While a lock on the record being read
is in effect, other users can request a READ
for
the same record, but they cannot update the record until the read
lock is released. When you specify RLS=NRI
, no lock
will be in effect when a READ
for input is executed.
Another user might update the record.
The locking rules for RLS=CR
can
cause the application to wait for availability of a record lock. This
wait might slow down the READ
for input. You might
need to modify your application logic to use RLS=CR
.
Do not use the RLS
parameter for batch jobs that
update nonrecoverable spheres until you are sure that the application
functions correctly in a multiple-updater environment.
When
you open a VSAM data set in RLS
mode for INPUT
or I-O
processing,
it is good to issue an OPEN
or START
immediately before
a READ
. If there is a delay between the OPEN
or START
and
the READ
, another user might add records before the
record on which the application is positioned after the OPEN
or START
.
The COBOL run time points explicitly to the beginning of the VSAM
data set at the time when OPEN
was requested, but
another user might add records that would alter the true beginning
of the VSAM data set if the READ
is delayed.