2023 Sep 11 2:01 PM
Hi
How nessesary is using a lock objects in programming with updating/inserting/appending data to transparent tables? And what would happen if not to use it in such cases?
And where using it is nessesary?
Thank you in advance!
2023 Sep 11 2:19 PM
Hello jumabek2707
Lock objects are a must in concurrent programming!
Typically a business object is implemented with several transparent tables e.g. sales order - tables VBAK, VBAP, etc. If you are going to create/update a business object, you need to lock entries in all the relevant tables to make sure no one is going to update them in parallel. That is what enqueue / lock objects do for you.
Best regards
Dominik Tylczynski
2023 Sep 11 2:19 PM
Hello jumabek2707
Lock objects are a must in concurrent programming!
Typically a business object is implemented with several transparent tables e.g. sales order - tables VBAK, VBAP, etc. If you are going to create/update a business object, you need to lock entries in all the relevant tables to make sure no one is going to update them in parallel. That is what enqueue / lock objects do for you.
Best regards
Dominik Tylczynski
2023 Sep 11 2:23 PM
That's not parallel programming. That's concurrent use of an application.
Otherwise, spot on. 😉
2023 Sep 11 2:39 PM
2023 Sep 11 2:37 PM
When you read data, it's not necessary.
But when you add/update/delete data and another process could manipulate the table at the same time, then it's recommended to lock the table beforehand.
2023 Sep 11 7:19 PM
You can find many answers in the SAP forum:
need of lock objects site:sap.com
2023 Sep 12 5:21 PM
Hi Zhumabek,
It is used all the time, but it really depends on the situation. Here is an example.
Let's say you have a program that displays the content of a table in a grid, and allows to change the content, and save it in the database. Now Bob calls this program and displays the content of the first record. A minute later, Jane calls the same program and also displays the content of the first record. Then Bob changes the value of field A on that record and saves it in the database. In SAP this change will not automatically be shown on Jane's screen. It would require the program to reload the data from the database. Jane, not knowing that Bob made a change in field A on the first record, also changes the same field on the same record, puts in a different value and save. Now Bob has lost its changes and will not be notified of the situation.
To prevent this sort of situation, SAP provides Lock Objects. The creation of a Lock Object generates two distinct Function Modules: the Enqueue Function and the Dequeue Function. The first locks an entry, the second unlocks it. If you try to call the first one when it has already been called by someone else (or even by yourself on another session), the Function will return an error. You can see current lock entries by calling transaction SM12.
Now, two things to know about Lock Objects:
I hope this helps.
Patrice Poirier