08-23-2007 10:03 AM
Is it possible to Use lock objects to allow only 1 user to insert data into a database table at a time.
I am creating Assets using "BAPI_FIXEDASSET_CREATE1".
To create "n" assets similar to the asset I use a DO loop in my program and call the BAPI. (Please refer number of fixed assets field in AS01).
I need to avoid other users from manually creating assets using AS01 while the BAPI is running so that the range of assets created is consistent ( without gaps )
Thanks and Regards,
Ashwin
08-23-2007 3:41 PM
Simultaneous access to the same transaction is what makes SAP a multi-user environment. No two persons can change the same object at the same time, that is where locking concept comes into picture. You can have locks in creation only if you are using manual number ranges where you determine the number.
One way to achieve may be to lock the transaction AS01 itself when your program is executed and release it once it is completed. To lock the transaction itself, you can probably use SM01. Another way probably is to create a lock object, lock it in your program and in AS01, in some user exit, check for this lock and if it is locked that means your program is running, so issue a message to the user and exit. Do not forget to unlock it at the end of the execution of your program and account for unexpected abends of your program as well.
08-23-2007 3:12 PM
Search for a function module to enqueue the assest, if you cannot find one, then you can try locking to number range table with NUMBER_RANGE_ENQUEUE. This is kind of dirty, but it will prevent users from creating an assest while the BAPI runs.
08-23-2007 3:23 PM
Hi Ashwin,
To create a lock object, Go to SE11 and create a lock object, this should start with E once you create a lock object, it would generate a 2 Functional Modules, you can use this FM to lock the object in your code before calling the BAPI and other FM to unlock the table after exiting from the BAPI.
for more details on creating a lock Object please refer.
<a href="http://help.sap.com/saphelp_erp2005/helpdata//EN/cf/21ea0b446011d189700000e8322d00/frameset.htm">Lock Objects</a>
Thank You.
Award me, if helpful.
Regards
Venkat
08-23-2007 3:25 PM
<b>Lock objects</b> are use in SAP to avoid the inconsistancy at the time of data is being insert/change into database.
SAP Provide three type of Lock objects.
- Read Lock(Shared Locked)
protects read access to an object. The read lock allows other transactions read access but not write access to
the locked area of the table
- Write Lock(exclusive lock)
protects write access to an object. The write lock allows other transactions neither read nor write access to
the locked area of the table.
- Enhanced write lock (exclusive lock without cumulating)
works like a write lock except that the enhanced write lock also protects from further accesses from the
same transaction.
You can create a lock on a object of SAP thorugh transaction SE11 and enter any meaningful name start with EZ Example EZTEST_LOCK.
Use: you can see in almost all transaction when you are open an object in Change mode SAP could not allow to any other user to open the same object in change mode.
Example: in HR when we are enter a personal number in master data maintainance screen SAP can't allow to any other user to use same personal number for changes.
Technicaly:
When you create a lock object System automatically creat two function module.
1. ENQUEUE_<Lockobject name>. to insert the object in a queue.
2. DEQUEUE_<Lockobject name>. To remove the object is being queued through above FM.
regards,
srinivas
<b>*reward for useful answers*</b>
08-23-2007 3:41 PM
Simultaneous access to the same transaction is what makes SAP a multi-user environment. No two persons can change the same object at the same time, that is where locking concept comes into picture. You can have locks in creation only if you are using manual number ranges where you determine the number.
One way to achieve may be to lock the transaction AS01 itself when your program is executed and release it once it is completed. To lock the transaction itself, you can probably use SM01. Another way probably is to create a lock object, lock it in your program and in AS01, in some user exit, check for this lock and if it is locked that means your program is running, so issue a message to the user and exit. Do not forget to unlock it at the end of the execution of your program and account for unexpected abends of your program as well.
08-23-2007 3:45 PM
Hi,
the use of a custom lock object is not useful in your case because the standard transactions never will check it !
You can try to see if exists some user exit in asset creation process and from there you can block the creation of other assets from users other than that is running your custom program.
If you don't want that this test is based on user ID you can make use of a custom lock object that is activated/deactivated in your custom program and it's checked in the user exit.
Bye,
Antonino