In business applications an increasing number of dialogs are offered, in which data is displayed in change mode, but the likelihood that this data will be changed is not high. If data is accessed simultaneously by different users, a locking procedure must guarantee consistent data changes.
The SAP Lock Concept (enqueue) used for locking in ABAP programs up to now has offered only pessimistic locking. This works well when the likelihood is high that data will be changed, but as described above, it does have limitations when data is accessed simultaneously. At any given point of time data can be displayed as changeable only in one of several parallel dialogs.
For this reason there is a need for an optimistic locking procedure in ABAP programs. Optimistic locking enables data to be changed in all parallel dialogs. The business application, however, must be aware that the data originally displayed may already have changed before the user’s own changes take effect. The locking procedure must be able to detect this case, so that the business application has the possibility to pursue a conflict solution strategy.
Now, the lock mode O is offered, in addition to the familiar lock modes S, E and X.
An optimistic lock (mode 0) is set, if the user displays data in change mode. Optimistic locks on the same object cannot collide. If the user wants to save the (changed) data, the optimistic lock has to be converted into an exclusive lock (mode E). (This does not work, if beforehand another user has set a non-optimistic lock on the object). This procedure deletes other optimistic locks on the object.
For more information on optimistic locks see: