Show TOC

Background documentationOptimistic Locks Locate this document in the navigation structure

 

Purpose

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 used to provide 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 was 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.

Lock Mode “O”

Alongside the lock modes S, E, and X, the lock mode O for optimistic locks also exists.

An optimistic lock (mode O) 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). The conversion is implemented using lock mode R. This fails if someone has previously set a non-optimistic lock on the object, or if another O lock has already been promoted. If the promotion succeeds, the other optimistic locks on the object are deleted, and the lock behaves as an E lock.