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: 

lock object is not working automatically

Former Member
0 Kudos

Hi experts,

i have a problem , A table is updated by a program which is used by multiple user . I have used lock function module 'ENQUEUE_E_TABLE ' and 'DEQUEUE_E_TABLE' for that . when updation section occurs first user which come first go through it and for rest users amessage cones 'table is locked by XYZ user' . When first completes the updation resr users is not updating automatically they stand at that position where message comes. How to solve this issue?

Avadhesh Chandra

3 REPLIES 3

Former Member
0 Kudos

Hi Avadesh,

You just need to add the Enqueue FM on the table in a do/while loop with an exit condition.

ex:

Do.

call fm "enqueue"

if sy-subrc NE 0.

attempt = attemp + 1.

endif.

if attempt GT 10.

exit.

endif.

ENDDO.

Note: The above is just a pseudo code to give you an idea, in the actual implementation the attempts could be changed to wait upto X seconds etc.

Regards,

Chen

himanshu_gupta2
Participant
0 Kudos

Change the code and Lock the table in Share Mode not on the Exclusive Mode.

Pass 'S' in the Mode.

if you want only exclusive mode ,

then try the infinite loop with condition that sy-subrc <> 0.

for eg .

while ( sy-subrc <> 0).

enque FM

your code.

end while.

Former Member
0 Kudos

Hi,

We can lock the table before updating the entries. Two types of locks are there.

1. To lock the entire table. Here when the table is locked by one program, another program will not be able to modify it.

2. To lock the particular record only. Here when the record is locked by one program, the other program can modify records other than the one locked.

For option 1

Use the FM ENQUEUE_E_TABLEE to lock the table and FM DEQUEUE_E_TABLEE to unlock table.

For option 2

Go to SE11. There enter the name of your lock object and create it. Next screen you have to mention which field you want to lock.

For more info. on LOCK OBJECTS go to

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

If you want to lock the entire table, then use the FM said in option 1 in DO-ENDDO loop.

Run the loop till it gets successful (sy-subrc = 0)

DO.
*Call the FM.
 IF sy-subrc = 0.
    EXIT.
ENDIF.
ENDDO.

If you want to just try some number of times rather than keep on looping then can use for eg: DO 100 TIMES.