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

Can ABAP lock objects ONLY lock DB objects?

Former Member
0 Likes
867

Hello there,

I have a question regarding to ABAP lock objects. When creating a lock, it requires a DB table. Also I have searched the internet for this concept but it seems all introductions on ABAP lock objects are for DB access.

However here I want a lock that is used for concurrent process control. For example I have a piece of code that I only wish one process is executing it at one time in the system. So I need a lock to achieve this, but it has nothing to do with database.

Any idea about this?

Like in Windows programming, we can create kernel objects like signal, event objects or critical sections to control multiple threads/processes access.

Edited by: Qianqian Zhu on Nov 11, 2011 9:18 AM

7 REPLIES 7
Read only

kesavadas_thekkillath
Active Contributor
0 Likes
793

Its not the database tables, but it considers the entries in the db table. In your case whenever a program is executed if you need it to be locked and unlocked then use function ENQUEUE_E_DSVAS_TRDIR & DEQUEUE_E_DSVAS_TRDIR. The lockobject E_DSVAS_TRDIR uses the table TRDIR. Please search for more information SCN for how to use this two functions.

Kesav

Read only

0 Likes
793

Hi Kesav,

Thank you a lot for the answer, I will try that! Cheers~

Chris

Read only

SuhaSaha
Product and Topic Expert
Product and Topic Expert
0 Likes
793

When creating a lock, it requires a DB table. Also I have searched the internet for this concept but it seems all introductions on ABAP lock objects are for DB access.

SAP lock objects are not the same as DB locks. They are not physical in nature, but are rather logical.

For example I have a piece of code that I only wish one process is executing it at one time in the system. So I need a lock to achieve this, but it has nothing to do with database.

You can use the lock object ES_PROG to achieve this requirement. Algorithm for this should look something like this:

1. Check if you're able to create a lock argument using the object ENQUEUE_ES_PROG.

2a. If YES(sy-subrc EQ 0), proceed with your program flow.

2b. If NO(sy-subrc NE 0), then throw an error message.

3. Release the lock after the execution of the program in complete using DEQUEUE_ES_PROG.

BR,

Suhas

PS: Step3 might not be required because Locks are automatically released at the end of the transaction.

Read only

Former Member
0 Likes
793

Hi Suhas,

Really appreciate your reply! And I just checked the lock object together with the one Kesav told me, they are using the same table and I guess these lock objects are dedicated to achieve the scenarios I am facing.

Thank you again for the help!.

Chris

Read only

SuhaSaha
Product and Topic Expert
Product and Topic Expert
0 Likes
793

Hello Chris,

I will strongly suggesting reading the online documentation on [SAP Lock Mechanism|http://help.sap.com/saphelp_nw04/helpdata/en/cf/21eed9446011d189700000e8322d00/content.htm].

BR,

Suhas

Read only

Former Member
0 Likes
793

Hi Suhas,

I have read the link you provided, and tried the function modules. However I am not clear what parameters must be provided when call the function. And I just leave everything empty, but a foreign_lock exception is raised.

Also according to the documents, it seems that the lock is used for a data record, does that mean I must import a program name when calling the enqueque function?

Your help is appreciated!

Thanks,

Chris

Read only

Former Member
0 Likes
793

Ok I just tried and it seems that I must pass the name to get it work correctly. Thank you a lot for all the help!