加锁时,有时候需要判断谁占用了该表
call function
'ENQUEUE_READ'
exporting
gclient
=
gclient
gname
= 'EWUARCHIV'
garg
= garg
guname
= space
importing
number
= number
subrc
= subrc
tables
enq
= enq
exceptions
communication_failure =
1
system_failure
= 2
others
= 3.
if
subrc = 0 and number ne 0.
read table enq index 1.
if sy-subrc = 0.
message i510(eu) with
enq-guname 'EWUARCHIV'.
else.
message i521(eu) with
'EWUARCHIV'.
endif.
else.
message i521(eu) with 'EWUARCHIV'.
endif.
aendern = space.
when others.
message s010(ad) with 'Nur Anzeige m?glich.'(011).
aendern = space.
例:
FORM zform_lock_data USING u_matnr TYPE
matnr
u_lgpla
TYPE lgpla
CHANGING lock_name TYPE
string.
CLEAR
g_it_lock_name.
CLEAR
g_wa_lock_name.
CLEAR lock_name.
CALL FUNCTION
'ENQUEUE_EZ_STOCK_MOVE'
EXPORTING
mode_zstock_view
= 'X'
matnr
=
u_matnr
lgpla
=
u_lgpla
*
X_MATNR
= ' '
*
X_LGPLA
= ' '
*
_SCOPE
=
'2'
*
_WAIT
= ' '
*
_COLLECT
= ' '
EXCEPTIONS
foreign_lock
= 1
system_failure
= 2
OTHERS
= 3
.
IF sy-subrc <>
0.
CALL
FUNCTION 'ENQUEUE_READ'
EXPORTING
gclient = sy-mandt
gname =
'ZSTOCK_VIEW'
garg
= ' '
guname =
''
TABLES
enq
= g_it_lock_name.
LOOP
AT g_it_lock_name INTO g_wa_lock_name.
IF g_wa_lock_name-garg(18) = u_matnr AND
g_wa_lock_name-garg+18 = u_lgpla.
CONCATENATE lock_name
g_wa_lock_name-guname ':' INTO
lock_name.
ENDIF.
ENDLOOP.
ENDIF.
ENDFORM.
另外SM12是查看表被锁情况的一个tcode,可以进去看看