0% found this document useful (0 votes)
14 views

Lock Object in ABAP

Uploaded by

aaamir khan
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
14 views

Lock Object in ABAP

Uploaded by

aaamir khan
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 11

4️⃣

Lock Objects in ABAP


1. Introduction to Lock Objects
The purpose of Lock Objects is to achieve synchronization.

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.

2. How to see lock Entries ?


We have a dedicated transaction code to see lock entries.

Lock Objects in ABAP 1


Mob No :- 6261538504
The transaction code to see lock entries is SM12.

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.

3. Pre-requisites for Lock Objects


Lock Objects name starts with prefix ‘E’.

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.

The default value of Read lock is ‘S’.

Lock Objects in ABAP 2


Mob No :- 6261538504
In case of read lock, others users can display the data, but they can not change the data

2. Write Lock :-
Write lock is also called as exclusive lock.

The default value of write lock is ‘E’.

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.

3. Enhanced Write Lock :-


Enhanced Write lock is also called as exclusive lock without cumulation.

The default value of Enhanced write lock is ‘X’.

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.

5. Lock Object Creation


Requirement :-
We will develop a program using which we will change the contents of column Department
of Employee Table in such a way that if I am changing the contents of column Department
for a particular Employee Id, no other user can change it.

Implementation :-
Step 1 :- Go to SE11 transaction code and select lock object radio button.

Step 2 :- Give a name to your lock object starting with EZ or EY.

Lock Objects in ABAP 3


Mob No :- 6261538504
Step 3 :- Click on create button and pass the short description.

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.

Lock Objects in ABAP 4


Mob No :- 6261538504
Step 6 :- Select write lock.

Lock Objects in ABAP 5


Mob No :- 6261538504
Step 7 :- Click on Tab lock parameter and you will see the primary key of Employee Table
will be automatically coming there.

Note :-
If we want to lock any tables, we will always have to lock the primary key of table.

Step 8 :- Activate the table.

6. Lock Object function Module


Whenever we activate a lock object, SAP automatically generates 2 function modules, One
with ENQUEUE_LOCK object name and another with DEQUEUE_LOCK object name.

E.g.

Lock Objects in ABAP 6


Mob No :- 6261538504
Suppose, lock object name is EZ_DEPARTMENT, then the 2 generated function
modules are - ENQUEUE_EZ_DEPARTMENT and DEQUEUE_EZ_DEPARTMENT.

Enqueue function modules are used for locking and dequeue function module is used
for unlocking.

Checking the Created function Modules.


The dedicated transaction code for function modules is SE37.

Always open any database object in display mode only.

Lock Objects in ABAP 7


Mob No :- 6261538504
7. Use of Lock Object in a Program
Step 1 :- Go to SE38 transaction code and create a ABAP program.

*&Creating parameters to take user inputs


PARAMETERS : p_emp_id TYPE zar_emp_id,
p_depart TYPE zar_department.

*&-----------------------------------------------------
*&Calling Enqueue Function module
CALL FUNCTION 'ENQUEUE_EZ_DEPARTMENT'
EXPORTING
mode_zar_emp_tab = 'E'
mandt = sy-mandt

Lock Objects in ABAP 8


Mob No :- 6261538504
emp_id = p_emp_id
x_emp_id = ' '
_scope = '2'
_wait = ' '
_collect = ' '
EXCEPTIONS
foreign_lock = 1
system_failure = 2
OTHERS = 3.

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.

Step 2 :- Activate the program and put a break point.

Lock Objects in ABAP 9


Mob No :- 6261538504
Step 3 :- Now execute the program ( Press F8 ).

Step 4 :- Press F8.

System will automatically stop on the line on which you put the debugger.

Lock Objects in ABAP 10


Mob No :- 6261538504
Conclusion :-
As long as you have not dequeue your table name, other users will not be able to make any
changes.

Lock Objects in ABAP 11


Mob No :- 6261538504

You might also like