Data inconsistency occurs when two or more users are editing/changing the same record on the same table at exactly the same time. To avoid this, we use Lock Objects.
Lock Objects enables the user to request a lock on a specific record before accessing it. In this way, changing/editing of records is only possible one at a time, thus avoiding data inconsistency.
There are three different lock modes:
exclusive lock/Write Lock (Mode ‘E’)
allow you to prevent data from being changed while you are changing it yourself. An exclusive lock, as its name suggests, locks an application object for exclusive use by the program that sets it. No other program can then set either a shared lock or an exclusive lock for the same application object.
Shared Lock/Read Lock (Mode ‘S’)
allow you to prevent data from being changed while you are reading it. They prevent other programs from setting an exclusive lock (write lock) to change the object. It does not, however, prevent other programs from setting further read locks.
Enhanced write lock (Mode ‘X’)
works like a write lock but are not accumulated while a program is being executed. It protects from further accesses within the same transaction.
To create a Lock Object, got to transaction SE11, click on Lock Object radio button and enter any name that starts with EZ or EY. (Example EZSAMPLE_LOCK)
When you activate a lock object, the system generates an ENQUEUE_ and a DEQUEUE_ function module that you can use on your ABAP programs.
ENQUEUE_<lockobject name> - adds the requested object in a queue(lock)
DEQUEUE_<lockobject name> - remove the requested object from being queued(unlock).
The basic procedure on requesting a lock:
1. Enqueue and lock the object for editing.
2. Read/write the data from the database.
4. dequeue and release the object.
To implement Lock Objects in ABAP programs, please refer to this post.





















0 Responses to “SAP: Basic of Lock Objects”
Leave a Reply