EXCLUSIVE Statement [ HP COBOL II/XL Reference Manual ] MPE/iX 5.0 Documentation
HP COBOL II/XL Reference Manual
EXCLUSIVE Statement
The EXCLUSIVE statement is an HP extension to the ANSI COBOL standard.
The EXCLUSIVE statement provides you with a method for locking a file
that has been opened for shared access.
NOTE Use of EXCLUSIVE within a program causes any OPEN of the associated
file to enable the dynamic locking facility.
This "locking" does not stop anyone from accessing the file. Locking and
unlocking files must be done on a cooperative basis. That is, if all
users who intend to access a shared file agree to attempt to lock the
file before accessing its records, then no problems arise. However,
since this form of "locking" only sets a flag on the file, if other users
do not check to see if the flag is set (by attempting to lock it
themselves), then they can do anything with the file that other file
security mechanisms allow.
A locked file remains locked until an UN-EXCLUSIVE statement is issued
for that file.
Syntax
EXCLUSIVE file-name [CONDITIONALLY]
Parameters
file-name the name of the file you want to lock. It must be
opened before the EXCLUSIVE statement is executed.
Also, the file may have a USE procedure associated
with it in case an error occurs during execution of
the EXCLUSIVE statement. If an error does occur,
the USE procedure is executed.
Description
If used without the CONDITIONALLY option, the EXCLUSIVE statement
continues to try to lock the file until it succeeds. If the file is
already locked (for example, by another user), this means your program
will pause until the lock succeeds.
To prevent the above from occurring, you can use the CONDITIONALLY
option. This option attempts to lock the file and, if unsuccessful,
returns immediately to your COBOL program.
The FILE STATUS data item, if any, associated with the file named in the
EXCLUSIVE statement is updated to indicate whether or not the attempt to
lock the file was successful. If the lock was successful, the
STATUS-KEYS are set to "00". If the file is in use by another process
and the lock condition is FALSE, or file options do not specify dynamic
locking, or the calling process does not have multiple RIN capability,
STATUS-KEY-1 is set to "9" and STATUS-KEY-2 contains the binary error
code.[REV BEG] For more information on handling I/O errors, see
"Input-Output Error Handling Procedures" .[REV END]
Programs that are to access an indexed file concurrently, within an
environment that includes modification of the file, must include
EXCLUSIVE/UN-EXCLUSIVE statements to maintain data integrity.
Refer to "MPE XL System Dependencies" in Appendix H for more
information.
Example
The following example shows the EXCLUSIVE statement:
ENVIRONMENT DIVISION.
FILE-CONTROL.
SELECT CUSTFILE ASSIGN TO "CUSTDATA" FILE STATUS IS CHECKER.
:
PROCEDURE DIVISION.
:
OPEN I-O CUSTFILE.
EXCLUSIVE CUSTFILE CONDITIONALLY.
IF CHECKER IS EQUAL TO "00" PERFORM CUSTOMER-UPDATE
ELSE PERFORM FIND-WHY.
MPE/iX 5.0 Documentation