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: 

Database table lock/unlock

Former Member
0 Kudos

Hi.

Can anyone tell me the function modules used to lock and unlock database table.

Rgds,

Simran

1 ACCEPTED SOLUTION

Former Member
0 Kudos

Hi,

Lock:

CALL FUNCTION 'ENQUEUE_E_TABLE'

EXPORTING

tabname = 'ZTABLE'

EXCEPTIONS

foreign_lock = 1

system_failure = 2

OTHERS = 3.

Unlock:

CALL FUNCTION 'DEQUEUE_E_TABLE'

EXPORTING

tabname = 'ZTABLE'.

Rgds,

Prakash

8 REPLIES 8

RichHeilman
Developer Advocate
Developer Advocate
0 Kudos

The function modules start with ENQUEUE_ and DEQUEUE_, the rest of the name depends on the lock object name. You create lock objects for your tables via SE11, doing so will automatically create these function modules.

Regards,

Rich Heilman

Former Member
0 Kudos

Hi,

Lock:

CALL FUNCTION 'ENQUEUE_E_TABLE'

EXPORTING

tabname = 'ZTABLE'

EXCEPTIONS

foreign_lock = 1

system_failure = 2

OTHERS = 3.

Unlock:

CALL FUNCTION 'DEQUEUE_E_TABLE'

EXPORTING

tabname = 'ZTABLE'.

Rgds,

Prakash

0 Kudos

Check FM <b>'ENQUEUE_E_TABLE'/ 'DEQUEUE_E_TABLE'</b>

Check this link out

http://www.google.co.in/url?sa=U&start=1&q=http://searchsap.techtarget.com/tip/1,289483,sid21_gci858...

We can use the function modules ENQUEUE_E_TABLE for locking tables and the function module DEQUEUE_E_TABLE for unlocking tables. With this method, we don't need to lock objects in order to lock the tables. In other words, any table can be locked/unlocked using these function modules.

Regards,

Santosh

Message was edited by: Santosh Kumar P

Former Member
0 Kudos

Hello Simran,

Do U want to lock which table.

If u want lock ur Ztables then create the lock objects for the same using Tcode SE11. The Lock Object name should start with EZ or EY.

Once u activated the Lock Object which u have created a Fm will be created automatically with the name ENQUEUE_EZ(name) for locking and DEQUEUE_EZ(NAME).

Use these FM for locking and unloking.

same procedure can be followed for the Std. Tables also.

If useful reward points.

Regards,

Vasanth

andreas_mann3
Active Contributor
0 Kudos

hi,

look here:

A.

Former Member
0 Kudos

Hi Simran,

You can create Lock Objects in SE11.

1) Goto SE11

2) In Lock Objects give name starting with <b>E</b>

3) Give Table Name in TABLE TAB and Lock Mode

4) Activate it.

After activation two FM's will be created.

<b>DEQUEUE_EZZTEST</b>                Release lock on object EZZTEST
<b>ENQUEUE_EZZTEST</b>                Request lock for object EZZTEST

Where EZZTEST is your Lock Object Name.

You can then use these Fm's for Locking(<b>ENQUEUE_EZZTEST</b>) the DB table and unlocking(<b>DEQUEUE_EZZTEST</b>) them.

Consider this sample code.


REPORT  zzabap_advusers                                             .


DATA : t_ydvp_user_master  TYPE STANDARD TABLE OF ydvp_user_master,
       wa_ydvp_user_master TYPE ydvp_user_master,
       userid              TYPE ydvp_user_master-userid.


DATA : int(4) TYPE c VALUE '8240'.


CONSTANTS : ssn(3) TYPE c VALUE 'SSN'.

START-OF-SELECTION.

*Lock the table

  CALL FUNCTION 'ENQUEUE_EZZTEST'
    EXPORTING
      mode_ydvp_user_master = 'E'
      mandt                 = sy-mandt
      userid                = userid        "Primary Key
      x_userid              = ' '
      _scope                = '1'
      _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.


*Perform SQL operations on it .
  REFRESH t_ydvp_user_master.
  CLEAR wa_ydvp_user_master.

  wa_ydvp_user_master-userid = 'ADMIN'.
  APPEND wa_ydvp_user_master TO t_ydvp_user_master.
  CLEAR wa_ydvp_user_master.



  DO 15 TIMES.

    CONCATENATE ssn int INTO wa_ydvp_user_master-userid.
    CONDENSE wa_ydvp_user_master-userid NO-GAPS.

    APPEND wa_ydvp_user_master TO t_ydvp_user_master.
    CLEAR wa_ydvp_user_master.
    int = int + 1.

  ENDDO.


  MODIFY  ydvp_user_master      FROM TABLE t_ydvp_user_master.

  IF sy-subrc EQ 0.

    MESSAGE 'Update Successful' TYPE 'S'.
  ELSE.

    MESSAGE 'Update Unsuccessful' TYPE 'E'.
  ENDIF.


*Release the Lock
  CALL FUNCTION 'DEQUEUE_EZZTEST'
    EXPORTING
      mode_ydvp_user_master = 'E'
      mandt                 = sy-mandt
      userid                = userid         "Primary Key
      x_userid              = ' '
      _scope                = '3'
      _synchron             = ' '
      _collect              = ' '.
      

Using <b>SM12</b> transaction you can view DB tables presently Locked.

Refer to this Link for further Info.

<a href="http://help.sap.com/saphelp_di471/helpdata/EN/cf/21ea0b446011d189700000e8322d00/frameset.htm">http://help.sap.com/saphelp_di471/helpdata/EN/cf/21ea0b446011d189700000e8322d00/frameset.htm</a>

Regards,

Arun Samabrgi

Message was edited by: Arun Sambargi

Former Member
0 Kudos

Hi Simran,

If you want to lock your Ztables then create the lock objects using TXN SE11. The Lock Object name should start with EZ or EY. when you will activate the Lock Object which you created a FM will be created automatically with the name ENQUEUE_(name of lock object) for locking and DEQUEUE_(name of lock object) for unlocking.

Hope this helps You.

Regards,

Seema.

Former Member
0 Kudos

Hi, I want to rock some records in the Ztabs

specifyig the fields those are not primary key.

for example,the Pkey of ZTAB is MANDT and BUKRS.

However, I want to rock some records specifying

MANDT, BUKRS, and ZFIELD1, ZFIELD2...

DOES "ENQUEUE_E_TABLES" works?

DOES ANYBODY know another solution?

Thanks.