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

Row level locking - Lock objects

Former Member
0 Likes
1,584

Experts,

I am aware that we can do row level locking by creating a separate lock object for the table. I am calling enqueue_**** FM to call lock object created for my custom table. I am passing lock parameters & see that when a record does not exist in my custom table still SUBRC returned is 0 by lock FM.

As per my understanding, SUBRC should not be 0 as the record does not exist in table to be locked.

Please share your valuable inputs.

BR

Aspire

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
1,169

Note that i have created lock parameters same as key fields for my custom table ideally to lock a particular row by passing the key fields. I am also passing MANDT during my ENQUEUE_**** FM call.


Is it Standard functionality that only if record exists, then it will be checked for locking. If record does not exist, then SAP does not set SUBRC other than 0?

In my case one of the key fields for my custom table is contract account. I am passing junk data as 999999***... for Cont Account in lock parameter along with other fields & still see that SUBRC after FM call is set as 0.

BR,

Aspire

4 REPLIES 4
Read only

Former Member
0 Likes
1,170

Note that i have created lock parameters same as key fields for my custom table ideally to lock a particular row by passing the key fields. I am also passing MANDT during my ENQUEUE_**** FM call.


Is it Standard functionality that only if record exists, then it will be checked for locking. If record does not exist, then SAP does not set SUBRC other than 0?

In my case one of the key fields for my custom table is contract account. I am passing junk data as 999999***... for Cont Account in lock parameter along with other fields & still see that SUBRC after FM call is set as 0.

BR,

Aspire

Read only

0 Likes
1,169

I read many threads where i can see that they are discussing about feasibility to do row level locking in abap. I am getting this logic & interested to only know,


why SUBRC comes as '0' even if the key parameters of the database record don't exist?

Read only

SuhaSaha
Product and Topic Expert
Product and Topic Expert
0 Likes
1,169

Hello Aspire,

The most important thing to know is SAP Locking mechanism doesn't physically lock the record, but does it logically.

It does not matter what values you pass to the ENQUEUE module params, the lock mechanism uses them to build a logical key and stores it in the lock table. Further lock requests are checked against this key.


I am passing junk data as 999999***... for Cont Account in lock parameter along with other fields & still see that SUBRC after FM call is set as 0.

Try doing this -

  • Pass the junk values to the enqueue module & set the lock mode as "write"  - (E)xclusive.
  • After the ENQUEUE module has been executed successfully, go to SM12(trxn). You will see the lock entry.
  • In the sample code, try to set the 'E' lock again using the same params. You'll get an exception now! Why?

The answer to the "why" is the logical lock mechanism used by SAP

BR,

Suhas

Read only

RaymondGiuseppi
Active Contributor
0 Likes
1,169

Yes, for example, this behavior allow to lock an object during creation...

Regards,

Raymond