Creating Lock Objects in SAP

Creating a using lock objects with open SQL statements in SAP ABAP, lock objects in SAP ABAP

+ -

Lock Objects are the part of data dictionary objects, lock objects can be created in SE11 T-code, lock objects always starts with E, (these are the only custom objects that dosen`t start with Z in SAP).

Creating a lock object in SAP

Lock objects are data dictionary objects, can be created in SE11, follow below steps to create lock object.

Example: Here I am creating a lock object to insert, delete, update for table ZSTUDENT table in SAP.

Go to SE11, provide lock object name as EZSTUDENT, create.

Creating lock objects in SAP

Provide short description, select tables tab, provide table name and lock mode, save and activate.

Create Lock Object in SAP

When ever we create a lock object two function modules will be created, go to SE37, check FM`s DEQUEUE_EZSTUDENT and ENQUEUE_EZSTUDENT.

Using the lock object to update/insert table

When ever we create a lock object, two function modules(ENQUEUE and DEQUEUE) will be created, we have to call those function modules before and after open SQL statements, refer program below.

REPORT ZSAN_LOCKOBJECT.

DATA : IT_STUDENT TYPE TABLE OF ZSTUDENT,
       WA_STUDENT TYPE ZSTUDENT.

WA_STUDENT-STUDENTID = '09'.
WA_STUDENT-NAME = 'SAPNuts'.
WA_STUDENT-LASTNAME = 'SAPNuts'.
WA_STUDENT-FATHER = 'SAP'.
WA_STUDENT-DOB = '25/09/2013'.
WA_STUDENT-GENDER = 'Male'.
WA_STUDENT-COURSE = 'SAP ABAP'.
WA_STUDENT-EMAIL = 'admin@sapnuts.com'.
WA_STUDENT-FEE = '0000'.

CALL FUNCTION 'ENQUEUE_EZSTUDENT' "add lock
  EXPORTING
    MODE_ZSTUDENT = 'E'
   MANDT         = SY-MANDT
   STUDENTID     = WA_STUDENT-STUDENTID  "record to lock, optional parameter
*   X_STUDENTID   = ' '
*   _SCOPE        = '2'
*   _WAIT         = ' '
*   _COLLECT      = ' '
* EXCEPTIONS
*   FOREIGN_LOCK  = 1
*   SYSTEM_FAILURE       = 2
*   OTHERS        = 3
  .
IF SY-SUBRC = 0.
  MODIFY ZSTUDENT FROM WA_STUDENT.
ENDIF.

CALL FUNCTION 'DEQUEUE_EZSTUDENT' "release lock
  EXPORTING
    MODE_ZSTUDENT = 'E'
   MANDT         = SY-MANDT
   STUDENTID     = WA_STUDENT-STUDENTID "record to release lock, optional parameter
*   X_STUDENTID   = ' '
*   _SCOPE        = '3'
*   _SYNCHRON     = ' '
*   _COLLECT      = ' '
  .

Learner Questions


No Questions by learners, be first one to ask ..!!

    Please Sign in to ask a question

    Was this lesson helpful to you? Yes No 26 People out of 28 think this lesson helpful


    Lesson Navigation

    ←Previous Chapter
    Next Chapter →