Application Development and Automation 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: 
Read only

locking the database tables

Former Member
0 Likes
3,218

How to lock a database table. I assume that standard SAP tables have ENQUEUE fm.. I need to do for custom tables.

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
1,622

hi,

You can create a lock on a object of SAP thorugh transaction SE11 and enter any meaningful name start with EZ Example EZTEST_LOCK.

<b>This will autogenerate two function modules,Enqueue < lock object > and Dequeue < lock object ></b>

Example: in HR when we are enter a personal number in master data maintainance screen SAP can't allow to any other user to use same personal number for changes.

Technicaly:

When you create a lock object System automatically creat two function module.

1. ENQUEUE_<Lockobject name>. to insert the object in a queue.

2. DEQUEUE_<Lockobject name>. To remove the object is being queued through above FM.

You have to use these function module in your program.

Eg:

tables:vbak.

call function 'ENQUEUE_EZLOCK3'

exporting

mode_vbak = 'E'

mandt = sy-mandt

vbeln = vbak-vbeln

  • X_VBELN = ' '

  • _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.

<b>TO LOCK</b>

Execute CALL FUNCTION statement

CALL FUNCTION " ENQUEUE <lock object ">

EXPORTING . . .

EXCEPTIONS . . .

CASE SY-SUBRC.

.

ENDCASE.

<b>TO UNLOCK</b>

Execute the CALL FUNCTION statement

CALL FUNCTION 'DEQUEUE <lock object >'

EXPORTING . .

It is important to unlock the entry so others can update it.

rewards if useful,

regards,

nazeer

7 REPLIES 7
Read only

Former Member
0 Likes
1,622

YOU CREATE LOCK OBJECTS FOR THE CUSTOM TABLES.

Read only

Former Member
0 Likes
1,622

hi...

Good ... check out the following documentation

Lock objects are used to lock the database table while making the modifications on the database table.

you can create your own lock objects using SE11.

if you create lock objects on any table system will create two function modules.

1.ENQUEUE....

2.DEQUEUE.....

first one is used to lock the table

second one used to removing lock on the table.

*----


lock Table

CALL FUNCTION 'ENQUEUE_E_TABLE'

EXPORTING

tabname = table_name

EXCEPTIONS

foreign_lock = 1

system_failure = 2

OTHERS = 3.

*----


Unlock Table

CALL FUNCTION 'DEQUEUE_E_TABLE'

EXPORTING

tabname = table_name

check this link :

http://help.sap.com/saphelp_40b/helpdata/en/cf/21eea5446011d189700000e8322d00/content.htm

_SCOPE = 1: The lock is not sent to the update program. The lock is removed when the transaction is ended.

_SCOPE = 2: The lock is sent to the update program. The update program is responsible for removing the lock. The dialog program which requested the lock no longer has an influence on the lock behavior. This is the standard setting for the ENQUEUE function module.

_SCOPE = 3: The lock

Managingin lock entries

http://help.sap.com/saphelp_nw04/helpdata/en/37/a2e3ae344411d3acb00000e83539c3/frameset.htm

http://help.sap.com/saphelp_nw04/helpdata/en/7b/f9813712f7434be10000009b38f8cf/frameset.htm

http://help.sap.com/saphelp_nw04/helpdata/en/cb/168237d30d974be10000009b38f8cf/frameset.htm

<b>Reward points if useful</b>

Regards

Ashu

Read only

Former Member
0 Likes
1,622

hi,

You can use ENQUEUE for custom tables also.

Read only

Former Member
0 Likes
1,622
FORM LOCK_ZFISVTAX_GPA_VOL.
  CLEAR : V_FLAG.
* Lock database table ZFISVTAX_GPA_VOL
  CALL FUNCTION 'ENQUEUE_E_TABLE'
       EXPORTING
            MODE_RSTABLE   = C_E
            TABNAME        = C_GPA_VOL
       EXCEPTIONS
            FOREIGN_LOCK   = 1
            SYSTEM_FAILURE = 2
            OTHERS         = 3.
  IF SY-SUBRC = 0.
    V_FLAG = 'X'.
  ELSEIF SY-SUBRC = 1.
    MESSAGE E000 WITH TEXT-026 C_GPA_VOL
                      TEXT-027.
  ELSEIF SY-SUBRC = 2.
    MESSAGE E000 WITH TEXT-026 C_GPA_VOL
                      TEXT-028.
  ELSEIF SY-SUBRC = 3.
    MESSAGE E000 WITH TEXT-026 C_GPA_VOL
                      TEXT-029.
  ENDIF.
ENDFORM.                    " LOCK_ZFISVTAX_GPA_VOL


FORM UNLOCK_ZFISVTAX_GPA_VOL.

* Unlock database table ZFISVTAX_GPA_VOL
  CALL FUNCTION 'DEQUEUE_E_TABLE'
       EXPORTING
            MODE_RSTABLE = C_E
            TABNAME      = C_GPA_VOL.
ENDFORM.                    " UNLOCK_ZFISVTAX_GPA_VOL


Message was edited by:

Santosh Kumar Patha

Read only

Former Member
0 Likes
1,623

hi,

You can create a lock on a object of SAP thorugh transaction SE11 and enter any meaningful name start with EZ Example EZTEST_LOCK.

<b>This will autogenerate two function modules,Enqueue < lock object > and Dequeue < lock object ></b>

Example: in HR when we are enter a personal number in master data maintainance screen SAP can't allow to any other user to use same personal number for changes.

Technicaly:

When you create a lock object System automatically creat two function module.

1. ENQUEUE_<Lockobject name>. to insert the object in a queue.

2. DEQUEUE_<Lockobject name>. To remove the object is being queued through above FM.

You have to use these function module in your program.

Eg:

tables:vbak.

call function 'ENQUEUE_EZLOCK3'

exporting

mode_vbak = 'E'

mandt = sy-mandt

vbeln = vbak-vbeln

  • X_VBELN = ' '

  • _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.

<b>TO LOCK</b>

Execute CALL FUNCTION statement

CALL FUNCTION " ENQUEUE <lock object ">

EXPORTING . . .

EXCEPTIONS . . .

CASE SY-SUBRC.

.

ENDCASE.

<b>TO UNLOCK</b>

Execute the CALL FUNCTION statement

CALL FUNCTION 'DEQUEUE <lock object >'

EXPORTING . .

It is important to unlock the entry so others can update it.

rewards if useful,

regards,

nazeer

Read only

gopi_narendra
Active Contributor
0 Likes
1,622

You can create lock objects for your custom table using SE11. Make sure the following thigs

the lock object name should start with E.

Once you create the lock object, you will be created two FM's ENQUEUE<Lock Object Name>

and DEQUEUE<Lock Object Name>

You can use those FM's to lock and unlock your custom tables.

Regards

Gopi

Read only

Former Member
0 Likes
1,622

Hi,

*----


lock Table

CALL FUNCTION 'ENQUEUE_E_TABLE'

EXPORTING

tabname = table_name

EXCEPTIONS

foreign_lock = 1

system_failure = 2

OTHERS = 3.

*----


Unlock Table

CALL FUNCTION 'DEQUEUE_E_TABLE'

EXPORTING

tabname = table_name

Refer below link:

https://forums.sdn.sap.com/click.jspa?searchID=3716278&messageID=2354907

<b>Reward points</b>

Regards