A typical way to minimize record locks is to release the record lock. (This technique does not work if LCKLVL(*ALL) has been specified.)
Here is an example of minimize record by releasing the record lock. A single file maintenance application typically follows these steps:
In most cases, the record is locked from the access of the requested record through the update. The record wait time might be exceeded for another job that is waiting for the record. To avoid locking a record while the workstation user is considering a change, release the record after it is retrieved from the database (before the record display appears). You then need to access the record again before updating. If the record was changed between the time it was released and the time it was accessed again, you must inform the workstation user. The program can determine if the record was changed by saving one or more fields of the original record and comparing them to the fields in the same record after it is retrieved as follows:
In both cases above, the sequence of operations prevents the simple use of externally described data in RPG where the same field names are used in the master record and in the display file. Using the same field names (in RPG) does not work because the workstation user's changes are overlaid when the record is retrieved again.You can solve this problem by moving the record data to a data structure. Or, if you use the DDS keyword RTNDTA, you can continue to use externally described data. The RTNDTA keyword allows your program to reread data on the display without the operating system having to move data from the display to the program. This allows the program to do as follows:
If the workstation user changes the record on the display, the program uses the following sequence:
LCKLVL(*CHG) and LCKLVL(*CS) work in this situation. If LCKLVL(*ALL) is used, you must release the record lock by using a commit or rollback operation.