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: 

How to lock at record level

Former Member
0 Kudos

Hi Gurus,

Please teach me on how to lock the table at record level.

Thanks,

David.

4 REPLIES 4

Former Member
0 Kudos

You can use ENQUEUE function module to lock certain record of a table.

Usually for all SAP standard table we have ENQUEUE function module available.

For eg function module ENQUEUE_EMEKKOE is used to lock PO and Item no.

See this for more details -

Lock objects:

http://www.sap-img.com/abap/type-and-uses-of-lock-objects-in-sap.htm

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

ashish

former_member195698
Active Contributor
0 Kudos

Hi ,

To do locking at record level, you have to create a lock objects for the particular table. The lock object will create two function modules. one for enqueue and other for dequeue. These two function modules can be used to Lock and Unlock the at record level in a table.

Regards,

Aj

0 Kudos

You can lock any table at record level using the function module 'ENQUEUE_E_TABLE'. Here is the sample code to lock records in MARA table.

data: varkey like rstable-varkey.

varkey = sy-mandt.

varkey+3(18) = '000000000000001234'.

  • locking the tables............................

call function 'ENQUEUE_E_TABLE'

exporting

  • MODE_RSTABLE = 'E'

tabname = 'MARA'

varkey = varkey

  • X_TABNAME = ' '

  • X_VARKEY = ' '

  • _SCOPE = '2'

  • _WAIT = ' '

  • _COLLECT = 'X'

exceptions

foreign_lock = 1

system_failure = 2

others = 3 .

case sy-subrc.

when 1.

message i184(bctrain) with 'Foreignlock'.

when 2.

message i184(bctrain) with 'system failure'.

when 0.

message i184(bctrain) with 'success'.

when others.

message i184(bctrain) with 'others'.

endcase.

  • unlocking the table...............

call function 'DEQUEUE_E_TABLE'

exporting

  • MODE_RSTABLE = 'E'

tabname = 'MARA'

varkey = varkey

  • X_TABNAME = ' '

  • X_VARKEY = ' '

  • _SCOPE = '3'

  • _SYNCHRON = ' '

  • _COLLECT = ' '

Former Member
0 Kudos

Hi

yes you can lock a record

Locks are of two types... it depends on which lock you have applied.. Table level lock or field level lock.

<b>example</b>

You can make use of the standard lock objects for locking Material Number rather material master

ENQUEUE_EMMARAS to lock Material Master

DEQUEUE_EMMARAS to unlock Material Master

In order to check just execute the ENQUEUE module with one MATNR number and try to open the same MATNR number in MM02, then it says the material is locked by user ____

Then if you execute the DEQUEUE module then you can be able to change the MATNR number in MM02.

Hope this is clear

<b>Reward if usefull</b>