Lock Objects in SAP
Posted by Admin, under ABAP, Abap Objects, DDIC, Function Modules, Module Pool, Quick Reference, Sample Code, SAP, TutorialLock objects are use in SAP to avoid the inconsistancy at the time of data is being insert/change into database.
SAP Provide three type of Lock objects.
- Read Lock(Shared Locked)
protects read access to an object. The read lock allows other transactions read access but not write access to the locked area of the table
- Write Lock(exclusive lock)
protects write access to an object. The write lock allows other transactions neither read nor write access to the locked area of the table.
- Enhanced write lock (exclusive lock without cumulating)
works like a write lock except that the enhanced write lock also protects from further accesses from the same transaction.

Type of Locks
Steps:
Go to SE11 transaction and create a lock object for the table .Custom lock object
name should be start with EY or EZ.

Lock Object - Initial Screen
After activating lock object Function Module will be generated automatically.
Function Modules name will be like ENQUEUE_<LOCK_OBJECT_NAME> and DEQUEUE_<LOCK_OBJECT_NAME>.

Lock Modules
Foe Example:
For example you have created a lock object EZSFLIGHT for the SFLIGHT table .
So first lock the table , then update then release the lock.
Check this code —
DATA : t_itab like table of SFLIGHT,
fs_itab like SFLIGHT.
fs_itab-carrid = ‘AA’.
fs_itab-connid = ’0017′.
.
.
.
APPEND fs_itab TO t_itab.
.
.
.
CALL FUNCTION ‘ENQUE_EZSFLIGHT’ ” SET lock to the table
EXPORTING
CARRID = ….
CONNID = ….
.
.
IF sy-subrc eq 0.
INSERT sflight from table t_itab. ” Update the DB table
ENDIF.
CALL FUNCTION ‘ENQUE_EZSFLIGHT’ ” Unlock the table
EXPORTING
CARRID = ….
CONNID = ….
.
You might also be interested in these posts:

Post a Comment