Lock Object in ABAP
Lock Object in ABAP
Synchronization :-
If multiple users want to change the same data at the same time, then at a time only one
user can change the data. This concept is called as Synchronization.
Suppose, in a custom table multiple users are changing the data at the same time and
there is no synchronization among them, then in that scenario there will be
inconsistency of data as system will be confused whose data to save, i.e. why
Synchronization is essential in real world.
Note :-
At a time only one user can change the same records.
Note :-
The records that you are going to see in the Lock Entries, it comes from Enqueue Server.
Lock Entries are temporary entries and they never gets stored into any database tables, and it
comes from Enqueue Server.
When we want to create customized lock objects, the name must start with EZ or EY.
4. Lock Modes
There are three lock modes :-
1. Read Lock :-
Read Lock is also called as shared lock.
2. Write Lock :-
Write lock is also called as exclusive lock.
In case of write lock - other users can not display and change the data.
Write lock can be requested several times from the same transaction and are processed
successively.
In case of enhanced write lock - other users can not display and change the data.
Additionally, it protects the further access of the same transaction.
Enhanced Write lock can be requested only once from the same transaction and can not
be processed successively.
Implementation :-
Step 1 :- Go to SE11 transaction code and select lock object radio button.
Step 4 :- In the tables section, give the name of your Employee Table.
Step 5 :- Click on the Lock mode drop down menu and you will see a lot of lock modes will
be there, out of which first three lock modes are only important for customer perspective.
Note :-
If we want to lock any tables, we will always have to lock the primary key of table.
E.g.
Enqueue function modules are used for locking and dequeue function module is used
for unlocking.
*&-----------------------------------------------------
*&Calling Enqueue Function module
CALL FUNCTION 'ENQUEUE_EZ_DEPARTMENT'
EXPORTING
mode_zar_emp_tab = 'E'
mandt = sy-mandt
IF sy-subrc <> 0.
MESSAGE 'Table is not locked' TYPE 'E'.
ELSE.
UPDATE zar_emp_tab SET department = p_depart WHERE emp_id =
IF sy-subrc EQ 0.
MESSAGE 'Table has been successfully updated' TYPE 'S'.
ELSE.
MESSAGE 'Table has been not updated' TYPE 'E'.
ENDIF.
CALL FUNCTION 'DEQUEUE_EZ_DEPARTMENT'
EXPORTING
mode_zar_emp_tab = 'E'
mandt = sy-mandt
emp_id = p_emp_id
x_emp_id = ' '
_scope = '3'
_synchron = ' '
_collect = ' '.
ENDIF.
System will automatically stop on the line on which you put the debugger.