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: 

SAP ABAP Lock object

deve_123
Discoverer
0 Kudos
269

I tried creating a lock object for particular table in SAP ABAP, Is it possible to create entries in that table. If yes then what is the function of lock object. Already existing entries also taking except ID. Then what will be the special thing in lock object?

1 ACCEPTED SOLUTION

Patrice
Participant
0 Kudos
223

Hi,

When you create a Lock Object, it generates two Function Modules. If for instance your lock object is called EZTEST, you will have Function Modules ENQUEUE_EZTEST and DEQUEUE_EZTEST. You will need to call the first one to lock the table and the second one to unlock it. When you call ENQUEUE, a lock entry is created, which you can see in transaction SM12. If another program tries to do the ENQUEUE for the same key, it will return an error. This is a tool you can use to prevent two processes from doing simultaneous conflicting operations.

Do note though that this is not an actual lock on the database. If you don't check if there is a lock, it will not prevent you from doing database changes. Also, a lock for an entire table and a lock for a specific key of this table are two different lock entries that do not see each other. So you can lock the entire table in one program, but only lock a specific key in another and both will be allowed. You need to take this into account when using lock objects.

I hope this helps.

Patrice Poirier

2 REPLIES 2

VXLozano
Active Contributor
223

This is a basic question. Use the search button or even the SAP documentation about it. You've created an object that allows programs to lock a table, not locked the table.

Patrice
Participant
0 Kudos
224

Hi,

When you create a Lock Object, it generates two Function Modules. If for instance your lock object is called EZTEST, you will have Function Modules ENQUEUE_EZTEST and DEQUEUE_EZTEST. You will need to call the first one to lock the table and the second one to unlock it. When you call ENQUEUE, a lock entry is created, which you can see in transaction SM12. If another program tries to do the ENQUEUE for the same key, it will return an error. This is a tool you can use to prevent two processes from doing simultaneous conflicting operations.

Do note though that this is not an actual lock on the database. If you don't check if there is a lock, it will not prevent you from doing database changes. Also, a lock for an entire table and a lock for a specific key of this table are two different lock entries that do not see each other. So you can lock the entire table in one program, but only lock a specific key in another and both will be allowed. You need to take this into account when using lock objects.

I hope this helps.

Patrice Poirier