Application Development Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 

Locking mechanism for a table in functional module

Former Member
0 Kudos

Hi all,

I have a function module which updates custom table, here while going to update i would like to lock the table and after completion of updation I have to unlock the data, have you got my point ... can anybody tell me the procedure of locking mechanism... needed detailed code

Thanks & Regards

Rajesh

1 ACCEPTED SOLUTION

RichHeilman
Developer Advocate
Developer Advocate
0 Kudos

You need to create a lock object for your table via SE11.

The name of the lock object should be your table name with an "E" in front. After creating your lock object, there will be two function modules generated.

ENQUEUE_<Lock Object Name>

DEQUEUE_<Lock Object Name>

You use these function modules in your program to get locks.

Here is a code sample of a custom lock object over a custom table named ZPT_DET, with one key field REQNO.

call function 'ENQUEUE_EZPT_DET'
 EXPORTING
*   MODE_ZPT_DET         = 'E'
   MANDT                = SY-MANDT
   REQNO                = P_REQNO
*   X_REQNO              = ' '
*   _SCOPE               = '2'
*   _WAIT                = ' '
*   _COLLECT             = ' '
 EXCEPTIONS
   FOREIGN_LOCK         = 1
   SYSTEM_FAILURE       = 2
   OTHERS               = 3
          .
if sy-subrc <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
*         WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
endif.

Hope this helps.

Regards,

Rich Heilman

3 REPLIES 3

Former Member
0 Kudos

Use SE11 to create a Lock Object. When you create the lock object, you specify which table it is for, and then in the Lock Parameter tab, you specify the key fields for the lock. Two function modules will be created when you activate the lock object. You can find the function modules by displaying your lock object, and then go to meny path Goto / Lock modules. One FM will start with ENQUEUE. Use this FM to lock the data. The other FM starts with DEQUEUE. Use this FM to unlock the data.

Brian

RichHeilman
Developer Advocate
Developer Advocate
0 Kudos

You need to create a lock object for your table via SE11.

The name of the lock object should be your table name with an "E" in front. After creating your lock object, there will be two function modules generated.

ENQUEUE_<Lock Object Name>

DEQUEUE_<Lock Object Name>

You use these function modules in your program to get locks.

Here is a code sample of a custom lock object over a custom table named ZPT_DET, with one key field REQNO.

call function 'ENQUEUE_EZPT_DET'
 EXPORTING
*   MODE_ZPT_DET         = 'E'
   MANDT                = SY-MANDT
   REQNO                = P_REQNO
*   X_REQNO              = ' '
*   _SCOPE               = '2'
*   _WAIT                = ' '
*   _COLLECT             = ' '
 EXCEPTIONS
   FOREIGN_LOCK         = 1
   SYSTEM_FAILURE       = 2
   OTHERS               = 3
          .
if sy-subrc <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
*         WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
endif.

Hope this helps.

Regards,

Rich Heilman

Former Member
0 Kudos

Thank you my friends Bryan and Rich, your help is appreciatable.... i've solved it

Once again thanks for your nice cooperation

Regards

Rajesh