如何为ABAP程序添加权限检查
一、确认权限对象,及其关联字段:
TCode: SU21
例如权限对象"M_MSEG_WMB",它关联字段为"WERKS",详见下图:
二、在ABAP代码中添加权限检查代码:
TCode:SE38
TYPES: BEGIN OF ty_check_au,
werks TYPE mseg-werks,
END OF ty_check_au.
DATA: wa_check_au TYPE ty_check_au,
it_check_au TYPE TABLE OF ty_check_au.
AT SELECTION-SCREEN.
* 在此进行权限对象的检查
SELECT
werks
FROM mseg
INTO TABLE it_check_au
WHERE mblnr IN s_mblnr AND
werks = p_werks
AND mseg~bwart IN ('101','102','105','106')
.
LOOP AT it_check_au INTO wa_check_au.
AUTHORITY-CHECK OBJECT 'M_MSEG_WMB'
ID 'WERKS' FIELD wa_check_au-werks.
IF sy-subrc <> 0.
MESSAGE e030(zmm_dev) WITH wa_check_au-werks.
ENDIF.
CLEAR wa_check_au.
ENDLOOP.
三、创建ABAP代码关联的TCode:
TCode: SE93
四、把ABAP代码关联的TCode与权限对象进行关联
TCode: SU22、SU24
注:SU24操作同SU22.