*&---------------------------------------------------------------------* *& Report Z_USER_ROLES_IMPORT *&---------------------------------------------------------------------* *& *&---------------------------------------------------------------------* REPORT Z_USER_ROLES_IMPORT. TYPE-POOLS:truxs. DATA:BEGIN OF ws_list, username TYPE bapibname-bapibname, agr_name TYPE bapiagr-agr_name, from_dat TYPE bapiagr-from_dat, to_dat TYPE bapiagr-to_dat, END OF ws_list, it_list LIKE TABLE OF ws_list. DATA: BEGIN OF wa_user, uname TYPE sy-uname, END OF wa_user, it_user LIKE TABLE OF wa_user WITH KEY uname. DATA:it_role LIKE bapiagr OCCURS 0 WITH HEADER LINE, it_return LIKE bapiret2 OCCURS 0 WITH HEADER LINE. TYPES: BEGIN OF ty_log, username TYPE bapibname-bapibname, " 账号 message TYPE char70, " 消息 END OF ty_log. DATA: g_name TYPE bapibname-bapibname, gw_namein TYPE bapibname, gw_data TYPE bapilogond, gw_pwd TYPE bapipwd, gw_df TYPE bapidefaul, gw_add TYPE bapiaddr3, gt_re TYPE STANDARD TABLE OF bapiret2, gw_re TYPE bapiret2. *----------------------------------------------------------------------* * 数据定义 *----------------------------------------------------------------------* DATA git_excel TYPE kcde_intern_struc OCCURS 0 WITH HEADER LINE. DATA: gt_upload LIKE TABLE OF ws_list WITH HEADER LINE, gw_upload LIKE ws_list. DATA: success_rec TYPE i, error_rec TYPE i. *———————————————————————-* * Selection Screen *———————————————————————-* SELECTION-SCREEN BEGIN OF BLOCK bl02 WITH FRAME TITLE TEXT-002. PARAMETERS : p_file LIKE rlgrap-filename OBLIGATORY. SELECTION-SCREEN END OF BLOCK bl02. ********************************************************************* * AT SELECTION-SCREEN ********************************************************************* AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_file. PERFORM frm_open_file. START-OF-SELECTION. WRITE:/ '开始执行....'. PERFORM prm_upload. END-OF-SELECTION. WRITE:/ '执行完成...'. *&---------------------------------------------------------------------* *& Form FRM_OPEN_FILE *&---------------------------------------------------------------------* * text *----------------------------------------------------------------------* * --> p1 text * <-- p2 text *----------------------------------------------------------------------* FORM frm_open_file . CALL FUNCTION 'WS_FILENAME_GET' EXPORTING def_filename = space def_path = p_file mask = TEXT-001 mode = 'O' IMPORTING filename = p_file EXCEPTIONS selection_cancel = 0. ENDFORM. " FRM_OPEN_FILE *&---------------------------------------------------------------------* *& Form PRM_UPLOAD *&---------------------------------------------------------------------* * text *----------------------------------------------------------------------* * --> p1 text * <-- p2 text *----------------------------------------------------------------------* FORM prm_upload . *从已知文件名读入内表 CALL FUNCTION 'KCD_EXCEL_OLE_TO_INT_CONVERT' EXPORTING filename = p_file i_begin_col = 1 i_begin_row = 2 i_end_col = 4 i_end_row = 65535 TABLES intern = git_excel[] EXCEPTIONS inconsistent_parameters = 1 upload_ole = 2 OTHERS = 3. IF sy-subrc <> 0. MESSAGE '打开文件错误,请检查文件,确保关闭文件!' TYPE 'E'. STOP. ENDIF. REFRESH gt_upload. CLEAR gt_upload. LOOP AT git_excel . CASE git_excel-col. WHEN '001'."账号 MOVE git_excel-value TO ws_list-username. WHEN '002'."角色 MOVE git_excel-value TO ws_list-agr_name. WHEN '003'."有效期开始 MOVE git_excel-value TO ws_list-from_dat. WHEN '004'."有效期截止 MOVE git_excel-value TO ws_list-to_dat. ENDCASE. AT END OF row. APPEND ws_list TO it_list. CLEAR ws_list. ENDAT. ENDLOOP. CHECK it_list IS NOT INITIAL. LOOP AT it_list INTO ws_list. wa_user-uname = ws_list-username. APPEND wa_user TO it_user. CLEAR:ws_list,wa_user. ENDLOOP. SORT it_user BY uname. DELETE ADJACENT DUPLICATES FROM it_user. SORT it_list BY username. LOOP AT it_user INTO wa_user. CLEAR:it_role[],it_return[]. LOOP AT it_list INTO ws_list WHERE username EQ wa_user-uname. MOVE-CORRESPONDING ws_list TO it_role. APPEND it_role. CLEAR ws_list. ENDLOOP. PERFORM pro_get_user_role USING wa_user-uname. CHECK it_role[] IS NOT INITIAL. CALL FUNCTION 'BAPI_USER_ACTGROUPS_ASSIGN' EXPORTING username = wa_user-uname TABLES activitygroups = it_role[] return = it_return[]. LOOP AT it_return WHERE type EQ 'E' OR type EQ 'A'. EXIT. ENDLOOP. IF sy-subrc <> 0. WRITE:/ '用户:',wa_user-uname,'->角色分配成功...'. ELSE. FORMAT COLOR COL_NEGATIVE. WRITE:/ '用户:',wa_user-uname,'->角色分配失败...'. FORMAT COLOR OFF. ENDIF. CLEAR wa_user. ENDLOOP. ENDFORM. FORM pro_get_user_role USING VALUE(g_uname). DATA:lt_return LIKE bapiret2 OCCURS 0 WITH HEADER LINE, lt_groups LIKE bapiagr OCCURS 0 WITH HEADER LINE. CLEAR:lt_return[],lt_groups[]. CALL FUNCTION 'BAPI_USER_GET_DETAIL' EXPORTING username = g_uname * CACHE_RESULTS = 'X' * IMPORTING * LOGONDATA = * DEFAULTS = * ADDRESS = * COMPANY = * SNC = * REF_USER = * ALIAS = * UCLASS = * LASTMODIFIED = * ISLOCKED = * IDENTITY = * ADMINDATA = * DESCRIPTION = TABLES * PARAMETER = * PROFILES = activitygroups = lt_groups return = lt_return * ADDTEL = * ADDFAX = * ADDTTX = * ADDTLX = * ADDSMTP = * ADDRML = * ADDX400 = * ADDRFC = * ADDPRT = * ADDSSF = * ADDURI = * ADDPAG = * ADDCOMREM = * PARAMETER1 = * GROUPS = * UCLASSSYS = * EXTIDHEAD = * EXTIDPART = * SYSTEMS = . CHECK lt_groups[] IS NOT INITIAL. LOOP AT lt_groups. LOOP AT it_role WHERE agr_name EQ lt_groups-agr_name AND to_dat EQ lt_groups-to_dat. EXIT. ENDLOOP. IF sy-subrc <> 0. MOVE-CORRESPONDING lt_groups TO it_role. APPEND it_role. ENDIF. CLEAR:lt_groups,it_role. ENDLOOP. ENDFORM.
标签:wa,角色,list,uname,ABAP,导入,ws,user,TYPE From: https://www.cnblogs.com/ZJY-1314/p/17439846.html