‎2006 Sep 02 12:11 PM
Hi Experts,
I want to lock a table as per ecord level locking . How to go for it?
Actually the table is being updated with key records simultaneously through different processes.
Regards,
Jyoti Shankar
‎2006 Sep 02 12:27 PM
HI,
SAP provides you with the ability to restrict access to data while the table is being updated. This is fairly
simple to implement via the use of a lock object . Create the Lock Object in SE11 for that table, if that already exist then use that one..
Add the following code in-order to create the table lock. This function module must be called before any
update takes place. If a lock has already been taken out it will display the appropriate message.
CALL FUNCTION 'ENQUEUE_EZ_ZTABLENAME'
EXPORTING
mode_ZTABLENAME = 'E'
mandt = sy-mandt
KEYFIELD1 = "Value
KEYFIELD2 = "Value
KEYFIELD3 = "Value
...
* X_KEYFIELD1 = ' '
* X_KEYFIELD2 = ' '
* X_KEYFIELD3 = ' '
...
* _SCOPE = '2'
* _WAIT = ' '
* _COLLECT = ' '
* If exceptions are not used, message is displayed within FM
EXCEPTIONS
FOREIGN_LOCK = 1
SYSTEM_FAILURE = 2
OTHERS = 3.
IF sy-subrc <> 0.
* Retrieve message displayed within Function Module
message id sy-msgid
type 'I'
number sy-msgno
with sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
EXIT.
ENDIF.The following code will remove the lock for the specific table entries.
CALL FUNCTION 'DEQUEUE_EZ_ZTABLENAME'
EXPORTING
MODE_ZTABLENAME = 'E'
MANDT = SY-MANDT
mandt = sy-mandt
KEYFIELD1 = "Value
KEYFIELD2 = "Value
KEYFIELD3 = "Value
...
X_KEYFIELD1 = ' '
X_KEYFIELD2 = ' '
X_KEYFIELD3 = ' '
...
_SCOPE = '3'
_SYNCHRON = ' '
_COLLECT = ' '
.
releasing the lock is mandatory,
See the link for more info.
http://help.sap.com/saphelp_nw2004s/helpdata/en/41/7af4c8a79e11d1950f0000e82de14a/content.htm
Regards
Sudheer.
‎2006 Sep 02 12:38 PM
But i need only record level locking . Does this serve my purpose ?
‎2006 Sep 02 1:31 PM
In Sudhir's code the following should be replaced by your primary keys
<b>
KEYFIELD1 = "Value
KEYFIELD2 = "Value
KEYFIELD3 = "Value</b>
Use the pattern to insert your function call and enter eqnueuetblname to get select your table. The subrc of the function module will tell you if it was able to lock the record or not.
hith
Sunil Achyut