Automatic Record Locking

From BR Wiki
Jump to navigation Jump to search

When a file number is locked in the current program, other workstations and other file numbers are unable to either read or write to a record. Business Rules locks records read from within a file opened for SHR, OUTIN. Records can also be locked by other I/O statements, including Protect, by using the RESERVE keyword.

When locked, opening files for INPUT can only be done READ only. A consequence of this is the undetectability of multiple opens with INPUT NOSHR. But it poses no jeopardy to data. Any open requesting write permissions will not be allowed while the file is opened input noshr, and no input noshr will be allowed while the file is opened for writing, but two opens input noshr MAY be allowed on the same file at the same time. Under some circumstances, two attempts to open a file input noshr will fail and sometimes they won't. This is dependent on the operating system and what files are already opened. But, while restrictions have been loosened, they require no changes to your applications to assure data integrity.

Record locking protects a record from being read or changed by a second workstation while the first workstation is still accessing it. This allows multiple users to access the same file without the threat of damaging records that others are updating or changing. By default, Business Rules waits fifteen seconds for a locked record to become available before it returns a locked-record error (error code 0061) to the user requesting the second READ. The time to wait for a locked record can be defined in the OPEN statement using the WAIT= parameter.

The following table summarizes the default action, and the action when RESERVE and RELEASE are coded for each of the six I/O statements used with internal files. All except the DELETE statement may also be used with external files.

Record locking and unlocking does add to system overhead, so if it is not necessary, you may wish to avoid it. The statement READ #1,RELEASE: may be used to read a record without locking it when the record will not be rewritten. You may also specify REREAD #1,RELEASE: or RESTORE #1: to release locked records which will not be updated.

Similarly, system overhead can be minimized for all records processed by avoiding the use of SHR, OUTIN files. Changing to SHRI, OUTIN or SHR, INPUT will reduce system overhead.

While it is beneficial to avoid unnecessary overhead with file locking and unlocking, you should be careful to utilize this feature of Business Rules when it is needed. The system overhead created is not so great that you should entirely avoid the use of files opened SHR.