HP RPG/XL Programmer's Guide (30318-90001)

3-: 24
in your program. When you close the file, or when your program
finishes, the file is available to others. For example, entering
this FILE command before running a program gives the program
exclusive access to the file, MASTER:
:FILE MASTER;EXC
* Semi-exclusive
Semi-Exclusive access lets others read a file but prevents them
from updating it. When you close the file, or when your program
finishes, the file is available to others. For example, entering
this FILE command before running a program gives the program
semi-exclusive access to the file, MASTER:
:FILE MASTER;SEMI
* Shared
Shared access lets others read and write records in the same file
simultaneously. Different records can be accessed independently.
Each user has separate buffers, record pointers and file control
information. For example, entering this FILE command before
running a program gives the program shared access to the file,
MASTER:
:FILE MASTER;SHR
There are two ways to process shared files in an RPG program. You
can have RPG keep track of the records that are being accessed and
lock and unlock the file automatically. Alternatively, you can
control the locking process, yourself. If you do this, you must be
careful to lock the file before updating it and unlock it when
you're finished. The next two sections discuss automatic and
manual locking in detail.
__________________________________________________________________
NOTE All RPG programs processing the same file concurrently must
either use manual or automatic locking or must not use
locking at all.
__________________________________________________________________
Both automatic and manual locking enable the MPE Dynamic Locking
Facility. RPG programs that use automatic or manual locking for a
file cannot run concurrently with programs that do not have it
enabled. For non-RPG programs, enable the MPE Dynamic Locking
Facility by entering a FILE command similar to FILE MASTER;LOCK.
Automatically Locking and Unlocking Shared KSAM Files. Using LOCK in the
File Description Continuation Specification enables RPG automatic
looking. When you read or write a record, RPG locks and unlocks the file
for you. Figure 3-20 shows how to use LOCK in a program that adds
records to the KSAM disc file, MASTFL.
Each user, before running a program that accesses a KSAM file
concurrently with another user, must enter a file equation similar to the
following:
:FILE MASTFL;SHR