How to create Lock Objects in SAP ABAP
Lock Mechanism
Following are the two main functions accomplished with the lock mechanism −
A program can communicate with other programs about data records that it is just reading or changing.
A program can prevent itself from reading data that has just been changed by another program.
A lock request is first generated by the program. Then this request goes to the Enqueue server and the lock is created in the lock table. The Enqueue server sets the lock and the program is finally ready to access data.
Types of locks
You can use different types of locks.
The lock mode describes what type of lock it is. The lock modes are listed in the table below.
Shared lock
S (Shared)
Several users (transactions) can access locked data at the same time in display mode. A request for another shared lock is accepted, even if it comes from another user. An exclusive lock set on an object that already has a shared lock will be rejected.
Exclusive lock
E (Exclusive)
An exclusive lock protects the locked object against all types of locks from other transactions. Only the same lock owner can reset the lock (accumulate).
Exclusive but not cumulative lock
X (eXclusive non-cumulative)
Exclusive locks can be requested several times from the same transaction and are processed successively. In contrast, exclusive but not cumulative locks can be called only once from the same transaction. Each further lock request will be rejected.
Optimistic lock
O (Optimistic)
Optimistic locks initially behave like shared locks and can be converted into exclusive locks. See Optimistic Locks.
A lock remains set until you either call the corresponding DEQUEUE function module, or close the transaction with an implicit DEQUEUE_ALL.
Saved locks inherited by the update task are loaded back into the lock table when the system is started up.
Following are the two main functions accomplished with the lock mechanism −
A program can communicate with other programs about data records that it is just reading or changing.
A program can prevent itself from reading data that has just been changed by another program.
A lock request is first generated by the program. Then this request goes to the Enqueue server and the lock is created in the lock table. The Enqueue server sets the lock and the program is finally ready to access data.
Types of locks
You can use different types of locks.
The lock mode describes what type of lock it is. The lock modes are listed in the table below.
Shared lock
S (Shared)
Several users (transactions) can access locked data at the same time in display mode. A request for another shared lock is accepted, even if it comes from another user. An exclusive lock set on an object that already has a shared lock will be rejected.
Exclusive lock
E (Exclusive)
An exclusive lock protects the locked object against all types of locks from other transactions. Only the same lock owner can reset the lock (accumulate).
Exclusive but not cumulative lock
X (eXclusive non-cumulative)
Exclusive locks can be requested several times from the same transaction and are processed successively. In contrast, exclusive but not cumulative locks can be called only once from the same transaction. Each further lock request will be rejected.
Optimistic lock
O (Optimistic)
Optimistic locks initially behave like shared locks and can be converted into exclusive locks. See Optimistic Locks.
Life-Span of SAP Locks
A lock remains set until you either call the corresponding DEQUEUE function module, or close the transaction with an implicit DEQUEUE_ALL.
Saved locks inherited by the update task are loaded back into the lock table when the system is started up.
Creating Lock Object in SAP ABAP
Go to SE11 and Select Lock Object and enter the name of Lock object .Every custom Lock name Object Name Must be start with EZ----.
Give the Description
Go to the Tables Tab and Table name and Lock mode.
Now click on the Lock parameter button and enter the fields in the lock parameter section
Now save and activate it.
Lock object has been created successfully, no from the menu bar Click on Go to and select the Lock modules.
Now we can see the created Enque and deque Function modules which we can call in program