一、确认权限对象,和关联字段:
Tcode:SU21 维护权限对象
例如"M_MSEG_WMB",它关联字段为'WERKS'
M_MSEG_WMB 物料凭证:工厂
二、在ABAP代码中添加权限检查代码:
PROGRAM YTEST_13_001. 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 'ACTVT' FIELD '01' ID 'WERKS' FIELD wa_check_au-WERKS. IF SY-SUBRC <> 0. * Implement a suitable exception handling here MESSAGE E000 WITH '您没有工厂' LW_MARC-WERKS '的权限'. ENDIF. CLEAR wa_check_au. ENDLOOP.
AUTHORITY-CHECK OBJECT 'M_MSEG_WMB' ID 'ACTVT' FIELD '01' ID 'WERKS' FIELD wa_check_au-WERKS. IF SY-SUBRC <> 0. * Implement a suitable exception handling here MESSAGE E000 WITH '您没有工厂' LW_MARC-WERKS '的权限'. ENDIF.
sy-subrc 一些重要返回值如下:
0: 用户权限检查通过.
4: 用户权限不足.
8: 参数的数量不正确.
12: 权限对象不存在.
三、创建ABAP代码关联的TCode:
TCode: SE93
:YTEST_13_001
四、把ABAP代码关联的TCode与权限对象进行关联,
!TCode: SU22、SU24
SU22
应用程序类型:1事物
事物代码: YTEST_13_001
F8后
进入修改模式;
菜单:对象->对象->添加权限对象
M_MSEG_WMB
可以定义权限对象的活动类型:
!记得保存