‎2006 Jul 09 11:13 AM
Hi,
can any one give me sample code for the following
locking table while updating
and unlock after the updation
‎2006 Jul 09 11:21 AM
Hi zakir,
*...locking the table Mbew.
CALL FUNCTION 'ENQUEUE_E_TABLE'
EXPORTING
TABNAME = 'MBEW'
VARKEY = V_KEY
EXCEPTIONS
FOREIGN_LOCK = 1
SYSTEM_FAILURE = 2
OTHERS = 3.
IF SY-SUBRC = 1.
CLEAR V_KEY.
MESSAGE S999(ZSD) WITH
'MBEW Table being processed by another User'.
ENDIF.
*....Modifying table Mbew
LOOP AT IT_TABLE.
UPDATE MBEW SET LAEPR = IT_TABLE-LAEPR
WHERE MATNR = IT_TABLE-MATNR
AND BWKEY = IT_TABLE-BWKEY.
ENDLOOP.
*... Unlocking the table Mbew.
CHECK V_KEY EQ SPACE.
CALL FUNCTION 'DEQUEUE_E_TABLE'
EXPORTING
TABNAME = 'MBEW'
VARKEY = V_KEY
EXCEPTIONS
SYSTEM_FAILURE = 2
OTHERS = 3.
IF SY-SUBRC = 1.
CLEAR V_KEY.
ENDIF.
Thanks
zakir
‎2006 Jul 09 11:21 AM
Hi zakir,
*...locking the table Mbew.
CALL FUNCTION 'ENQUEUE_E_TABLE'
EXPORTING
TABNAME = 'MBEW'
VARKEY = V_KEY
EXCEPTIONS
FOREIGN_LOCK = 1
SYSTEM_FAILURE = 2
OTHERS = 3.
IF SY-SUBRC = 1.
CLEAR V_KEY.
MESSAGE S999(ZSD) WITH
'MBEW Table being processed by another User'.
ENDIF.
*....Modifying table Mbew
LOOP AT IT_TABLE.
UPDATE MBEW SET LAEPR = IT_TABLE-LAEPR
WHERE MATNR = IT_TABLE-MATNR
AND BWKEY = IT_TABLE-BWKEY.
ENDLOOP.
*... Unlocking the table Mbew.
CHECK V_KEY EQ SPACE.
CALL FUNCTION 'DEQUEUE_E_TABLE'
EXPORTING
TABNAME = 'MBEW'
VARKEY = V_KEY
EXCEPTIONS
SYSTEM_FAILURE = 2
OTHERS = 3.
IF SY-SUBRC = 1.
CLEAR V_KEY.
ENDIF.
Thanks
zakir
‎2006 Jul 09 11:25 AM
Example code for
lock the table
CALL FUNCTION 'ENQUEUE_EVVBAKE'
EXPORTING
MODE_VBAK = 'E'
MANDT = SY-MANDT
VBELN = VBAK-VBELN
X_VBELN = ' '
_SCOPE = '2'
_WAIT = ' '
_COLLECT = ' '
EXCEPTIONS
FOREIGN_LOCK = 1
SYSTEM_FAILURE = 2
OTHERS = 3
.
IF SY-SUBRC <> 0.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
Update/insert into your dbase
Then unlock the table
CALL FUNCTION 'DEQUEUE_EVVBAKE'
EXPORTING
MODE_VBAK = 'E'
MANDT = SY-MANDT
VBELN = VBAK-VBELN
X_VBELN = ' '
_SCOPE = '2'
_WAIT = ' '
_COLLECT = ' '
EXCEPTIONS
FOREIGN_LOCK = 1
SYSTEM_FAILURE = 2
OTHERS = 3
.
IF SY-SUBRC <> 0.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
Regds
Manohar
‎2006 Jul 09 11:28 AM
If you are looking for locking Z table, then you should create lock objects from SE11.
Then use FM's ENQUEUE_<TABNAME> and DEQUEUE_<TABNAME> for locking and unlocking.
Refer to this link for further details
http://help.sap.com/saphelp_47x200/helpdata/en/af/22ab01dd0b11d1952000a0c929b3c3/frameset.htm
Regds
Manohar
‎2006 Jul 09 11:29 AM
Hi Zakir,
Go to SE11 and create lock object on the table with specified fields , system will generate 'ENQUEUE... ' and 'DEQUEUE.....' FM's , call those FM's like below :
(with these FM's you can specify row level locking also, which normal system Enqueue/Dequeue FM's will not give)
call function 'ENQUEUE....'
insert or modify table statements
call function 'DEQUEUE....'
Regards
Appana