Application Development and Automation 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: 
Read only

sample code please

Former Member
0 Likes
866

Hi,

can any one give me sample code for the following

locking table while updating

and unlock after the updation

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
596

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

4 REPLIES 4
Read only

Former Member
0 Likes
597

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

Read only

Manohar2u
Active Contributor
0 Likes
596

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

Read only

Manohar2u
Active Contributor
0 Likes
596

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

Read only

Laxmana_Appana_
Active Contributor
0 Likes
596

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