*&---------------------------------------------------------------------* *& REPORT ZUSER *&---------------------------------------------------------------------* *& *&---------------------------------------------------------------------* REPORT zuser LINE-SIZE 400. *&--------------------------------------------------------------------* *& TABLE WORK AREAS * *&--------------------------------------------------------------------* TABLES:agr_users,agr_tcodes,tstct,usr02,agr_agrs2,usr21. *&---------------------------------------------------------------------* * GLOBAL INTERNAL TABLES ALV 使用 *&---------------------------------------------------------------------* DATA: gs_layout TYPE lvc_s_layo, gt_events TYPE slis_t_event, gs_events LIKE LINE OF gt_events. DATA: g_grid TYPE REF TO cl_gui_alv_grid. DATA:gt_fieldcat TYPE TABLE OF lvc_s_fcat, gs_fieldcat TYPE lvc_s_fcat. DATA: is_variant LIKE disvariant. *&---------------------------------------------------------------------* * GLOBAL MACROS ALV 使用 *&---------------------------------------------------------------------* DEFINE fill_field. "宏定义 CLEAR gs_fieldcat. gs_fieldcat-fieldname = &1."ALV 控制: 内部表字段的字段名称 gs_fieldcat-scrtext_l = &2."长字段标签 gs_fieldcat-cfieldname = &3."ALV 控制: 参考的当前单位的字段名称 gs_fieldcat-outputlen = &4."ALV 控制: 列的字符宽度 gs_fieldcat-edit = &5."ALV 控制: 准备输入(可编辑字段) gs_fieldcat-emphasize = &6."ALV 控制: 带有颜色的高亮列 gs_fieldcat-decimals_o = &7."ALV 控制: 输出小数位的编号 gs_fieldcat-ref_table = &8. "参考表 gs_fieldcat-ref_field = &9."参考字段 * GS_FIELDCAT-CHECKBOX = &9. * GS_FIELDCAT-NO_ZERO = 'X'."ALV 控制: 为输出隐藏零 gs_fieldcat-just = 'X'. * GS_FIELDCAT-COLDDICTXT = 'L'. * GS_FIELDCAT-ICON = 'X'. "图标功能 APPEND gs_fieldcat TO gt_fieldcat. END-OF-DEFINITION. DATA:BEGIN OF gs00 , bname LIKE usr02-bname, ustyp LIKE usr02-ustyp, END OF gs00. DATA:BEGIN OF gs10 , uname LIKE agr_users-uname, "R/3 系统, 用户登录名 agr_name LIKE agr_users-agr_name, "角色名称 text LIKE agr_texts-text, " 用于层次菜单的文件结构-客户 parent_agr LIKE agr_users-agr_name, "根角色名称 tcode LIKE agr_tcodes-tcode, "扩展的程序名 END OF gs10. DATA:BEGIN OF gs11, uname LIKE agr_users-uname, "R/3 系统, 用户登录名 name_first LIKE adrp-name_first, "名 name_last LIKE adrp-name_last, "姓 department LIKE adcp-department, "部门 roomnumber LIKE adcp-roomnumber, "房间或公寓号 END OF gs11. DATA:BEGIN OF gs12, uname LIKE agr_users-uname, "R/3 系统, 用户登录名 name_first LIKE adrp-name_first, "名 name_last LIKE adrp-name_last, "姓 department LIKE adcp-department, "部门 roomnumber LIKE adcp-roomnumber, "房间或公寓号 agr_name LIKE agr_users-agr_name, "角色名称 text LIKE agr_texts-text, " 角色描述 parent_agr LIKE agr_users-agr_name, "根角色名称 texta LIKE agr_texts-text, " 角色描述 tcode LIKE agr_tcodes-tcode, "扩展的程序名 ttext LIKE tstct-ttext, "事务说明 ustyp LIKE user02-ustyp, ustyptxt TYPE char100, END OF gs12. DATA:t00 LIKE TABLE OF gs00, t10 LIKE TABLE OF gs10, t11 LIKE TABLE OF gs11, t12 LIKE TABLE OF gs12. *DATA:BEGIN OF T13 OCCURS 0, * UNAME LIKE AGR_USERS-UNAME, "R/3 系统, 用户登录名 * AGR_NAME LIKE AGR_USERS-AGR_NAME, "角色名称 * END OF T13. DATA:BEGIN OF t14 OCCURS 0, agr_name LIKE agr_agrs2-agr_name, "角色名称 child_agr LIKE agr_agrs2-child_agr, END OF t14. SELECTION-SCREEN BEGIN OF BLOCK cond WITH FRAME TITLE TEXT-002. SELECT-OPTIONS: g_uname FOR usr02-bname. SELECT-OPTIONS: agr_name FOR agr_tcodes-agr_name. SELECT-OPTIONS: g_tcode FOR tstct-tcode. PARAMETERS: P_CK AS CHECKBOX. SELECTION-SCREEN END OF BLOCK cond. *&--------------------------------------------------------------------* * EVENT OCCURS AFTER THE SELECTION SCREEN HAS BEEN PROCESSED *&--------------------------------------------------------------------* START-OF-SELECTION. PERFORM frm_select_data. *ALV PERFORM frm_display_data . END-OF-SELECTION. *&---------------------------------------------------------------------* *& FORM FRM_DISPLAY_DATA *&---------------------------------------------------------------------* * ALV 展示 *----------------------------------------------------------------------* * --> P1 TEXT * <-- P2 TEXT *----------------------------------------------------------------------* FORM frm_display_data . IF P_CK is INITIAL. PERFORM frm_fill_field. ELSE. PERFORM frm_fill_field2. * DELETE t12 where TTEXT is not INITIAL or TCODE is not INITIAL. LOOP AT t12 ASSIGNING FIELD-SYMBOL(<ls_t12>). <ls_t12>-TCODE = ''. <ls_t12>-TTEXT = ''. ENDLOOP. sort t12 by UNAME . delete adjacent duplicates from t12 comparing ALL FIELDS. ENDIF. PERFORM frm_layout. PERFORM frm_alv_display. ENDFORM. "FRM_DISPLAY_DATA *&---------------------------------------------------------------------* *& FORM FRM_LAYOUT *&---------------------------------------------------------------------* * TEXT *----------------------------------------------------------------------* * --> P1 TEXT * <-- P2 TEXT *----------------------------------------------------------------------* FORM frm_layout . CLEAR: gs_layout."它用来定义ALV报表的整体属性 gs_layout-zebra = 'X' ."ZBBRA * GS_LAYOUT-DETAILINIT = 'X' . "INITIAL VALUES ON DETAIL SCREEN gs_layout-cwidth_opt = 'X'."优化列宽选项是否设置 * GS_LAYOUT-DETAILTITL = 'DETAIL INFORMATION' ."设置弹出窗口的标题栏 " GS_LAYOUT-BOX_FNAME = 'SEL'. * GS_LAYOUT-INFO_FNAME = 'ROWCOLOR'. * GS_LAYOUT-GRID_TITLE = 'ALV GRID TITLE TEST'. * GS_LAYOUT-STYLEFNAME = 'STYLE'."单元格可编辑 ENDFORM. "FRM_LAYOUT *&---------------------------------------------------------------------* *& FORM FRM_FILL_FIELD *&---------------------------------------------------------------------* * TEXT *----------------------------------------------------------------------* * --> P1 TEXT * <-- P2 TEXT *----------------------------------------------------------------------* FORM frm_fill_field . REFRESH gt_fieldcat. fill_field: 'UNAME' '用户主记录中的用户名称' '' '' '' '' '' 'AGR_USERS' 'UNAME', 'NAME_FIRST' '姓 ' '' '' '' '' '' 'ADRP' 'NAME_FIRST', 'NAME_LAST' '名 ' '' '' '' '' '' 'ADRP' 'NAME_LAST', 'DEPARTMENT' '部门' '' '' '' '' '' 'ADCP' 'DEPARTMENT', 'ROOMNUMBER' '房间或公寓号' '' '' '' '' '' 'ADCP' 'ROOMNUMBER', 'AGR_NAME' '本地角色名称' '' '' '' '' '' 'AGR_USERS' 'AGR_NAME', 'TEXT' '本地角色描述' '' '' '' '' '' 'AGR_TEXTS' 'TEXT', 'PARENT_AGR' '根角色' '' '' '' '' '' 'AGR_USERS' 'AGR_NAME', 'TEXTA' '根角色描述' '' '' '' '' '' 'AGR_TEXTS' 'TEXT', 'TCODE' '扩展的程序名' '' '' '' '' '' 'AGR_TCODES' 'TCODE', 'TTEXT' '事务说明' '' '' '' '' '' 'TSTCT' 'TTEXT' , 'USTYP' '用户类型' '' '' '' '' '' 'USER02' 'USTYP', 'USTYPTXT' '用户类型文本' '' '' '' '' '' '' ''. ENDFORM. "FRM_FILL_FIELD FORM frm_fill_field2 . REFRESH gt_fieldcat. fill_field: 'UNAME' '用户主记录中的用户名称' '' '' '' '' '' 'AGR_USERS' 'UNAME', 'NAME_FIRST' '姓 ' '' '' '' '' '' 'ADRP' 'NAME_FIRST', 'NAME_LAST' '名 ' '' '' '' '' '' 'ADRP' 'NAME_LAST', 'DEPARTMENT' '部门' '' '' '' '' '' 'ADCP' 'DEPARTMENT', 'ROOMNUMBER' '房间或公寓号' '' '' '' '' '' 'ADCP' 'ROOMNUMBER', 'AGR_NAME' '本地角色名称' '' '' '' '' '' 'AGR_USERS' 'AGR_NAME', 'TEXT' '本地角色描述' '' '' '' '' '' 'AGR_TEXTS' 'TEXT', 'PARENT_AGR' '根角色' '' '' '' '' '' 'AGR_USERS' 'AGR_NAME', * 'TEXTA' '根角色描述' '' '' '' '' '' 'AGR_TEXTS' 'TEXT', * 'TCODE' '扩展的程序名' '' '' '' '' '' 'AGR_TCODES' 'TCODE', 'TTEXT' '事务说明' '' '' '' '' '' 'TSTCT' 'TTEXT' , 'USTYP' '用户类型' '' '' '' '' '' 'USER02' 'USTYP', 'USTYPTXT' '用户类型文本' '' '' '' '' '' '' ''. ENDFORM. *&---------------------------------------------------------------------* *& FORM FRM_ALV_DISPLAY *&---------------------------------------------------------------------* * TEXT *----------------------------------------------------------------------* * --> P1 IT_INBOM *----------------------------------------------------------------------* FORM frm_alv_display. DATA: i_grid_settings TYPE lvc_s_glay. * IS_VARIANT-REPORT = 'ZMMU0025'. * IS_VARIANT-HANDLE = '1'. CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY_LVC' EXPORTING i_callback_program = sy-repid "SY-REPID 当前程序名 IS_LAYOUT_LVC = GS_LAYOUT it_fieldcat_lvc = gt_fieldcat i_save = 'A' * IT_EVENTS = GT_EVENTS TABLES t_outtab = t12 EXCEPTIONS program_error = 1 OTHERS = 2. IF sy-subrc <> 0. * MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO * WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4. ENDIF. ENDFORM. "FRM_ALV_DISPLAY * * LOOP AT T00. * REFRESH: T10,T11,T13,T14. * SELECT * FROM AGR_USERS INTO CORRESPONDING FIELDS OF TABLE T10 * WHERE UNAME = T00-BNAME AND AGR_NAME IN AGR_NAME. **IF SY-SUBRC <> 0. **PERFORM MESSAGE USING 'E' '你所输入的用户不存在或还未分配权限' '' **'' **'' **. **ENDIF. * * * LOOP AT T10. * SELECT * FROM AGR_TCODES APPENDING CORRESPONDING FIELDS OF TABLE * T11 * WHERE AGR_NAME = T10-AGR_NAME * AND TCODE IN G_TCODE. * ENDLOOP. * * LOOP AT T11. * READ TABLE T10 INTO T10 WITH KEY AGR_NAME = T11-AGR_NAME. * IF SY-SUBRC = 0. * T11-UNAME = T10-UNAME. * ENDIF. * * SELECT SINGLE TTEXT FROM TSTCT INTO T11-TTEXT * WHERE TCODE = T11-TCODE AND SPRSL = '1'. * SELECT SINGLE TEXT FROM AGR_TEXTS INTO T11-TEXT * WHERE AGR_NAME = T11-AGR_NAME. * SELECT SINGLE PERSNUMBER FROM USR21 INTO USR21-PERSNUMBER * WHERE BNAME = T00-BNAME. * SELECT SINGLE DEPARTMENT FROM ADCP INTO T11-DEPARTMENT * WHERE PERSNUMBER = USR21-PERSNUMBER. * SELECT SINGLE ROOMNUMBER FROM ADCP INTO T11-ROOMNUMBER * WHERE PERSNUMBER = USR21-PERSNUMBER. * SELECT SINGLE NAME_FIRST FROM ADRP INTO T11-NAME_FIRST * WHERE PERSNUMBER = USR21-PERSNUMBER. * SELECT SINGLE NAME_LAST FROM ADRP INTO T11-NAME_LAST * WHERE PERSNUMBER = USR21-PERSNUMBER. * MODIFY T11. * ENDLOOP. * * LOOP AT T11. * MOVE-CORRESPONDING T11 TO T13. * APPEND T13. * ENDLOOP. * SORT T13 BY UNAME. * DELETE ADJACENT DUPLICATES FROM T13. * SORT T11 BY UNAME AGR_NAME . * DATA:TEMP. * * LOOP AT T11. * CLEAR T14. * CLEAR T13. * TEMP = 0. * * SELECT * FROM AGR_AGRS2 INTO CORRESPONDING FIELDS OF TABLE T14 * WHERE CHILD_AGR = T11-AGR_NAME. * IF SY-SUBRC = 0. * SELECT * FROM AGR_USERS INTO CORRESPONDING FIELDS OF TABLE T13 * WHERE UNAME = T11-UNAME. * * LOOP AT T14. * READ TABLE T13 INTO T13 WITH KEY AGR_NAME = T14-AGR_NAME. * IF SY-SUBRC = 0 . * TEMP = 1. * ENDIF. * ENDLOOP. * IF TEMP = 0. * MOVE-CORRESPONDING T11 TO T12. * ENDIF. * ELSE. * MOVE-CORRESPONDING T11 TO T12. * ENDIF. * SELECT SINGLE USTYP INTO T12-USTYP FROM USR02 WHERE BNAME = T12-UNAME. * CASE T12-USTYP. * WHEN 'A'. * T12-USTYPTXT = '对话'. * WHEN 'B'. * T12-USTYPTXT = '系统用户(内部RFC和后台处理)'. * WHEN 'C'. * T12-USTYPTXT = '通讯用户'. * WHEN 'L'. * T12-USTYPTXT = '参考用户'. * WHEN 'S'. * T12-USTYPTXT = '服务用户'. * WHEN OTHERS. * ENDCASE. * APPEND T12. * ENDLOOP. * SORT T12 BY UNAME AGR_NAME TCODE. *NEW-LINE. *LOOP AT T12. *WRITE:T12-UNAME,T12-NAME_LAST,T12-NAME_FIRST,T12-DEPARTMENT, *T12-ROOMNUMBER,T12-AGR_NAME, *T12-TEXT,T12-TCODE,T12-TTEXT. *NEW-LINE. *ENDLOOP. * ENDLOOP. * * CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY' * EXPORTING * IT_FIELDCAT = L_ALV_FIELDCAT * I_STRUCTURE_NAME = 'ZBASIS_USER' ** IT_SORT = SORTCAT * I_CALLBACK_PROGRAM = 'ZALV_MAT' ** I_CALLBACK_USER_COMMAND = 'USER_COMMAND' * TABLES * T_OUTTAB = T12. *&--------------------------------------------------------------------* *& FORM MESSAGE *&--------------------------------------------------------------------* * TEXT *---------------------------------------------------------------------* * -->VALUE(MESSATEXTYPE) * -->VALUE(MESSATEXTONTENT1) * -->VALUE(MESSATEXTONTENT2) * -->VALUE(MESSATEXTONTENT3) * -->VALUE(MESSATEXTONTENT4) *---------------------------------------------------------------------* *FORM MESSAGE USING VALUE(MESSAGE_TYPE) * VALUE(MESSAGE_CONTENT1) * VALUE(MESSAGE_CONTENT2) * VALUE(MESSAGE_CONTENT3) * VALUE(MESSAGE_CONTENT4). * MESSAGE ID '000' TYPE MESSAGE_TYPE NUMBER '000' * WITH MESSAGE_CONTENT1 * MESSAGE_CONTENT2 * MESSAGE_CONTENT3 * MESSAGE_CONTENT4. *ENDFORM. " MESSAGE *&---------------------------------------------------------------------* *& FORM FRM_SELECT_DATA *&---------------------------------------------------------------------* *& 数据处理 *&---------------------------------------------------------------------* *& --> P1 TEXT *& <-- P2 TEXT *&---------------------------------------------------------------------* FORM frm_select_data . *查询账号 SELECT bname ustyp INTO CORRESPONDING FIELDS OF TABLE t00 FROM usr02 WHERE bname IN g_uname. SORT t00 BY bname. *查询角色和对应的事物代码 SELECT u~uname u~agr_name te~text d~parent_agr t~tcode INTO CORRESPONDING FIELDS OF TABLE t10 FROM agr_users AS u INNER JOIN agr_define AS d ON u~agr_name = d~agr_name INNER JOIN agr_texts AS te ON d~AGR_NAME = te~agr_name AND te~spras = sy-langu LEFT JOIN agr_tcodes AS t ON d~parent_agr = t~agr_name FOR ALL ENTRIES IN t00 WHERE u~uname = t00-bname AND u~agr_name IN agr_name AND u~from_dat <= sy-datum AND u~to_dat >= sy-datum. DELETE t10 WHERE tcode NOT IN g_tcode. *查询角色属性 SELECT * INTO CORRESPONDING FIELDS OF TABLE t14 FROM agr_agrs2 FOR ALL ENTRIES IN t10 WHERE child_agr = t10-agr_name. *用户基本信息 SELECT u~bname AS uname r~name_first r~name_last c~department c~roomnumber INTO CORRESPONDING FIELDS OF TABLE t11 FROM usr21 AS u INNER JOIN adrp AS r ON u~persnumber = r~persnumber INNER JOIN adcp AS c ON c~persnumber = u~persnumber AND c~addrnumber = u~addrnumber FOR ALL ENTRIES IN t00 WHERE r~date_from <= sy-datum AND c~date_from <= sy-datum AND u~bname = t00-bname. LOOP AT t10 INTO gs10. READ TABLE t14 WITH KEY agr_name = gs10-agr_name. IF sy-subrc NE 0. MOVE-CORRESPONDING gs10 TO gs12. READ TABLE t11 INTO gs11 WITH KEY uname = gs10-uname. IF sy-subrc EQ 0. MOVE-CORRESPONDING gs11 TO gs12. ENDIF. READ TABLE t00 INTO gs00 WITH KEY bname = gs10-uname. IF sy-subrc EQ 0. gs12-ustyp = gs00-ustyp. CASE gs00-ustyp. WHEN 'A'. gs12-ustyptxt = '对话'. WHEN 'B'. gs12-ustyptxt = '系统用户(内部RFC和后台处理)'. WHEN 'C'. gs12-ustyptxt = '通讯用户'. WHEN 'L'. gs12-ustyptxt = '参考用户'. WHEN 'S'. gs12-ustyptxt = '服务用户'. WHEN OTHERS. ENDCASE. ENDIF. SELECT SINGLE ttext FROM tstct INTO gs12-ttext WHERE tcode = gs10-tcode AND sprsl = '1'. SELECT SINGLE text FROM agr_texts INTO gs12-texta WHERE agr_name = gs10-parent_agr. APPEND gs12 TO t12. ENDIF. ENDLOOP. * DATA:BEGIN OF T12 OCCURS 0, * LIKE AGR_USERS-UNAME, "R/3 系统, 用户登录名 * LIKE ADRP-NAME_FIRST, "名 * LIKE ADRP-NAME_LAST, "姓 * LIKE ADCP-DEPARTMENT, "部门 * LIKE ADCP-ROOMNUMBER, "房间或公寓号 * AGR_NAME LIKE AGR_USERS-AGR_NAME, "角色名称 * TCODE LIKE AGR_TCODES-TCODE, "扩展的程序名 * TTEXT LIKE TSTCT-TTEXT, "事务说明 * TEXT LIKE AGR_TEXTS-TEXT, " 用于层次菜单的文件结构-客户 * USTYP LIKE USER02-USTYP, * USTYPTXT TYPE CHAR100, * END OF T12. ENDFORM.
标签:报表,NAME,agr,ABAP,T11,T12,权限,AGR,LIKE From: https://www.cnblogs.com/ZJY-1314/p/17439838.html