08-01-2010 5:20 PM
Hello,
Am I missing something with FOR UPDATE addition in Open SQL? When I use it I can't get a lock to appear to SM12. For example, if I select a single record for update from table EKKO it's still possible to effect a normal MEPO update of the releavnt purchase order even before a COMMIT WORK command in my code.
Any ideas?
Thanks,
Chris.
08-02-2010 4:28 AM
This phrase from the SAP documentation should answer your query :
An exclusive lock can be set for this line using the FOR UPDATE addition when a single line is being read with SINGLE.
Source: [http://help.sap.com/abapdocu_70/en/ABAPSELECT_CLAUSE_LINES.htm#&ABAP_ALTERNATIVE_1@1@].
This DB lock exists till the end of the current DB LUW & is released at the end.
BR,
Suhas
08-01-2010 8:45 PM
Hello Chris
FOR UPDATE command creates only a database lock,
you can't see database locks in sm12.
You should use related "lock object" to lock entries in table EKKO with sm12
For finding the lock object follow steps below :
- Go to transaction se11
- Write your table EKKO
- Click button : Where Used List
- Choose only "Lock object" in the next popup screen
Every lock object has two function module ENQUEUE_<LOCK OBJ NAME> and DEQUEUE_<LOCK OBJ NAME>
enqueue function creates lock in sm12 and dequeue deletes lock entry from sm12.
And you can display parameters from se37 and use it.
I hope it helps.
08-01-2010 9:28 PM
Hello Bulent,
Thanks for that. I didn't know that SM12 was only for lock object locks and not for d/b locks. However, the FOR UPDATE addition doesn't seem to do anything at all. As I said, other transactions can still update the table even when the d/b lock has been applied using FOR UPDATE. Ca you explain?
Regards,
Chris.
08-01-2010 11:11 PM
They shouldn't be able to update the record if it's locked, but database puts the update (or the select for update) on hold and waits for the record to be unlocked and then update it.
Moreover, the update mark is set only during the time of a database transaction, and is automatically released at the end (i.e. at a database COMMIT or ROLLBACK). SAP does many [implicit commits|http://help.sap.com/abapdocu_70/en/ABENDB_COMMIT.htm] (each time a screen is displayed, or an RFC is executed, etc.), so the database locks are released. It's why SAP introduced the SAP lock concept at the SAP side. SELECT FOR UPDATE is (rarely) used when SAP locks cannot be used because of many concurrent updates like number ranges.
08-02-2010 7:48 AM
Hi Chris
I think Sandra's answer is very explanatory,
Use SAP locks / lock objects for a sturdy mechanism
otherwise a message, any dilaog or simultaneously running RFC etc can release that lock.
Regards .
08-04-2010 3:17 PM
Hi Bulent, Suhas and Sandra,
Thank you all for your advice. As you say, the answer is really to use the SAP locking mechanism, therby gaining better control of the processes.
Regards,
Chris.
08-02-2010 4:28 AM
This phrase from the SAP documentation should answer your query :
An exclusive lock can be set for this line using the FOR UPDATE addition when a single line is being read with SINGLE.
Source: [http://help.sap.com/abapdocu_70/en/ABAPSELECT_CLAUSE_LINES.htm#&ABAP_ALTERNATIVE_1@1@].
This DB lock exists till the end of the current DB LUW & is released at the end.
BR,
Suhas