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: 

Use of SELECT SINGLE FOR UPDATE

Former Member
0 Kudos

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.

1 ACCEPTED SOLUTION

SuhaSaha
Advisor
Advisor
0 Kudos

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

6 REPLIES 6

bbalci
Contributor
0 Kudos

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.

Former Member
0 Kudos

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.

Sandra_Rossi
Active Contributor
0 Kudos

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.

0 Kudos

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 .

Former Member
0 Kudos

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.

SuhaSaha
Advisor
Advisor
0 Kudos

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