在日常维护中常常需要用户的组织结构层面的权限列表,在SAP里我们就需要到角色里去查看,比较不方便,因此做下面的一个用户组织结构权限的列表程序,代码如下(供大家参考使用)
代码语言:javascript复制 *&---------------------------------------------------------------------*
*& Report ZORG_LEVELS_AU *
*& *
*&---------------------------------------------------------------------*
*&---------------------------------------------------------------------*
REPORT ZORG_LEVELS_AU MESSAGE-ID dev.
TYPE-POOLS: slis.
TABLES: usr02.
DATA: BEGIN OF gt_1252 OCCURS 100,
agr_name LIKE agr_1251-agr_name.
INCLUDE STRUCTURE pt1252.
DATA: END OF gt_1252 .
DATA db_1252 LIKE gt_1252 OCCURS 100 WITH HEADER LINE. DATA: BEGIN OF
gt_au_fld OCCURS 100.
INCLUDE STRUCTURE pt1251.
DATA: END OF gt_au_fld.
*Organization Level Authorization Field Text
DATA: BEGIN OF orgebenen OCCURS 30.
INCLUDE STRUCTURE usorg_db.
DATA: END OF orgebenen,
*Organization Level Authorization Field Text
BEGIN OF orgtext OCCURS 30.
INCLUDE STRUCTURE usorg_db.
DATA: END OF orgtext.
DATA: g_var LIKE orgebenen-varbl,
g_ret LIKE sy-subrc,
g_old_field LIKE pt1251-field.
DATA: BEGIN OF gt_result OCCURS 100,
agr_name LIKE agr_1251-agr_name.
INCLUDE STRUCTURE tprorg1.
DATA: END OF gt_result.
DATA: gt_field TYPE slis_t_fieldcat_alv.
*Define Selection Screen
PARAMETERS p_user LIKE usr02-bname OBLIGATORY.
PARAMETERS p_date LIKE sy-datum OBLIGATORY DEFAULT sy-datum . RANGES
r_group FOR agr_define-agr_name. END-OF-SELECTION.
REFRESH: db_1252, r_group .
r_group-sign = 'I'.
r_group-option = 'EQ'.
* Get User's roles
SELECT agr_name INTO (r_group-low) FROM agr_users WHERE uname = p_user AND
to_dat > p_date.
APPEND r_group.
ENDSELECT. *Get value of roles' Organizational levels
SELECT * FROM agr_1252 INTO CORRESPONDING FIELDS OF TABLE db_1252
WHERE agr_name IN r_group
ORDER BY counter.
IF sy-subrc NE 0.
MESSAGE i036. "没有符合条件的数据,则提示信息退出
EXIT.
ENDIF.
DELETE db_1252 WHERE varbl = space.
*CALL FUNCTION 'PRGN_1252_READ_ORG_LEVELS'
* EXPORTING
* ACTIVITY_GROUP = S_STAT-OBJID
* TABLES
* ORG_LEVELS = DB_STORG
* EXCEPTIONS
* NO_DATA_AVAILABLE = 1
* OTHERS = 2.
SORT db_1252.
*Auth. Object in User Master Maintenance
SELECT * FROM agr_1251 INTO CORRESPONDING FIELDS OF TABLE gt_au_fld
WHERE agr_name IN r_group
ORDER BY field.
PERFORM init_orgs.
LOOP AT gt_au_fld.
IF gt_au_fld-field NE g_old_field.
g_old_field = gt_au_fld-field.
PERFORM is_org USING g_old_field g_var g_ret.
IF g_ret EQ 0.
READ TABLE db_1252 WITH KEY varbl = g_var.
IF sy-subrc = 0.
LOOP AT db_1252 WHERE varbl = g_var.
APPEND db_1252 TO gt_1252.
ENDLOOP.
IF sy-subrc NE 0.
CLEAR gt_1252.
gt_1252-varbl = g_var.
APPEND gt_1252.
ENDIF.
ELSE.
ENDIF.
ENDIF.
ENDIF.
ENDLOOP.
SORT gt_1252.
LOOP AT gt_1252.
MOVE-CORRESPONDING gt_1252 TO gt_result.
PERFORM read_org_text USING gt_1252-varbl gt_result-text.
READ TABLE orgebenen WITH KEY varbl = gt_1252-varbl.
IF sy-subrc = 0.
gt_result-fieldname = orgebenen-field.
ENDIF.
APPEND gt_result.
ENDLOOP.
DESCRIBE TABLE gt_result LINES sy-subrc.
IF sy-subrc = 0.
MESSAGE i036. "没有符合条件的数据,则提示信息退出
EXIT.
ELSE.
PERFORM sub_create_field_cat.
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
EXPORTING
it_fieldcat = gt_field[]
TABLES
t_outtab = gt_result
EXCEPTIONS
program_error = 1
OTHERS = 2.
ENDIF.
*&---------------------------------------------------------------------*
*& Form sub_create_field_cat
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
FORM sub_create_field_cat.
REFRESH gt_field.
PERFORM sub_field_des USING :
'' '' 'AGR_NAME' '' 'X' '' '' 'Role Name' '20' '' '' gt_field[],
'' '' 'VARBL' '' 'X' '' '' 'Org. Level' '10' '' '' gt_field[],
'' '' 'TEXT' '' '' '' '' 'Org. Des.' '40' '' '' gt_field[],
'' '' 'LOW' '' '' '' '' 'Low Value' '40' '' '' gt_field[],
'' '' 'HIGH' '' '' '' '' 'High Vlaue' '40' '' '' gt_field[].
ENDFORM. " SUB_CREATE_FIELD_CAT
*----------------------------------------------------------------------*
* Form : SUB_FIELD_DES
*----------------------------------------------------------------------*
* Description: Set the fields which will be displayed
*----------------------------------------------------------------------*
*参数说明 *
*---------------------------------------------------------------------*
* im_ref_FIELD---must upper case *
* im_ref_TABLE---internal table name *
* im_FIELDname---must upper case *
* im_TABname ---internal table name *
* im_KEY ---column with key-color AND frozen *
* im_CHECKBOX ---the column is checkbox *
* im_dosum ---total,if total, the field must be sumed *
* im_SELTEX_L ---column Long description of title *
&nbs, p; * im_outputlen---column output length
* re_field : 字段格式定义内表
*----------------------------------------------------------------------*
* Modification Log: *
* Date Programmer Correction Number *
*2006-08-10 dev01 增加控制零值是否显示控制参数
*2006-08-12 dev01 增加控制是否显示控制参数
*----------------------------------------------------------------------*
FORM sub_field_des USING im_ref_field TYPE c
im_ref_table TYPE c
im_fieldname TYPE c
im_tabname TYPE c
im_key TYPE c
im_checkbox TYPE c
im_dosum TYPE c
im_seltex_l TYPE c
im_outputlen TYPE i
im_zero TYPE c
im_out TYPE c
re_field TYPE slis_t_fieldcat_alv.
DATA: wa_fieldcat TYPE slis_fieldcat_alv.
CLEAR wa_fieldcat.
wa_fieldcat-ref_fieldname = im_ref_field.
wa_fieldcat-ref_tabname = im_ref_table.
wa_fieldcat-fieldname = im_fieldname.
wa_fieldcat-tabname = im_tabname.
wa_fieldcat-key = im_key.
wa_fieldcat-checkbox = im_checkbox.
wa_fieldcat-do_sum = im_dosum.
wa_fieldcat-no_zero = im_zero.
wa_fieldcat-no_out = im_out.
wa_fieldcat-seltext_l = im_seltex_l.
wa_fieldcat-seltext_m = im_seltex_l.
wa_fieldcat-seltext_s = im_seltex_l.
wa_fieldcat-outputlen = im_outputlen.
* wa_fieldcat-col_pos = IM_colpos.
APPEND wa_fieldcat TO re_field.
ENDFORM. "SUB_FIELD_DES
*&---------------------------------------------------------------------*
*& Form INIT_ORGS
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
FORM init_orgs.
STATICS: org_init.
IF org_init = space.
org_init = 'X'.
SELECT * FROM usorg_db INTO TABLE orgebenen.
SORT orgebenen.
orgtext[] = orgebenen[].
SORT orgtext BY langu varbl.
ENDIF.
ENDFORM. " INIT_org
*&---------------------------------------------------------------------*
*& Form IS_ORG
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* -->FIELD text
* -->VAR text
* -->RET text
*----------------------------------------------------------------------*
FORM is_org USING field var ret.
READ TABLE orgebenen WITH KEY field = field BINARY SEARCH.
IF sy-subrc = 0.
ret = 0.
var = orgebenen-varbl.
ELSE.
ret = 4.
CLEAR var.
ENDIF.
ENDFORM. "IS_ORG
* Text zu einer Variablen (Orgebene) liefern
FORM read_org_text USING name LIKE usvart-varbl
text.
READ TABLE orgtext WITH KEY langu = sy-langu varbl = name
BINARY SEARCH.
IF sy-subrc = 0.
text = orgtext-vtext.
ELSE.
READ TABLE orgtext WITH KEY langu = 'D' varbl = name
BINARY SEARCH.
IF sy-subrc = 0.
text = orgtext-vtext.
ELSE.
text = name.
ENDIF.
ENDIF.
ENDFORM. "read_org_text