批量导入角色,并在EXECL中的事务码中导入角色并管理事务码。
导入后结果如图
导入EXECL数据模板如图,
批量导入用户权限角色及事务码的ABAP代码
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 |
*&---------------------------------------------------------------------* *& Report ZBC_C002 *& *&---------------------------------------------------------------------* *& *& *&---------------------------------------------------------------------* REPORT ZBC_C002. INCLUDE <ICON>. TABLES:RLGRAP,SSCRFIELDS . DATA: FUNCTXT TYPE SMP_DYNTXT . DATA: BEGIN OF LT_AGRS OCCURS 0, AGR_NAME TYPE AGR_NAME, " 角色ID TEXTS TYPE AGR_TITLE," 角色名称 TCODE TYPE TCODE, " 事务代码 END OF LT_AGRS. DATA: GT_TCODES LIKE TABLE OF SSM_TCODES , GS_TCODES LIKE SSM_TCODES . PARAMETERS: PA_PATH TYPE LOCALFILE MODIF ID C . SELECTION-SCREEN FUNCTION KEY 1. AT SELECTION-SCREEN ON VALUE-REQUEST FOR PA_PATH. PERFORM FRM_GET_FILENAME CHANGING PA_PATH. INITIALIZATION . FUNCTXT-ICON_ID = ICON_EXPORT . FUNCTXT-ICON_TEXT = '下载模板' . SSCRFIELDS-FUNCTXT_01 = FUNCTXT . AT SELECTION-SCREEN. CASE SY-UCOMM. WHEN 'FC01'. PERFORM FRM_DOWNLOAD_EXECL USING 'ZBC_C001' 'xlsx' ''. WHEN OTHERS. "PERFORM FRM_CHECK. ENDCASE. START-OF-SELECTION. IF PA_PATH IS NOT INITIAL. PERFORM UPLOAD_DATA USING PA_PATH . ENDIF. PERFORM FRM_BULID_ROLES . *&---------------------------------------------------------------------* *& Form FRM_GET_FILENAME *&---------------------------------------------------------------------* *& text *&---------------------------------------------------------------------* * <--P_PA_PATH text *&---------------------------------------------------------------------* FORM FRM_GET_FILENAME CHANGING PV_FNAME TYPE LOCALFILE . DATA : LT_FILETABLE TYPE FILETABLE, LS_FILETABLE LIKE LINE OF LT_FILETABLE, LV_FILENAME TYPE STRING, LV_CURRENT_DIRECTORY TYPE STRING, LV_FILE_FILTER TYPE STRING, LV_RC TYPE I. IF PV_FNAME IS NOT INITIAL. LV_FILENAME = PV_FNAME. ENDIF. * Get user's current directory CALL METHOD CL_GUI_FRONTEND_SERVICES=>DIRECTORY_GET_CURRENT CHANGING CURRENT_DIRECTORY = LV_CURRENT_DIRECTORY EXCEPTIONS DIRECTORY_GET_CURRENT_FAILED = 1 CNTL_ERROR = 2 ERROR_NO_GUI = 3 NOT_SUPPORTED_BY_GUI = 4 OTHERS = 5. IF SY-SUBRC <> 0. LV_CURRENT_DIRECTORY = '%USERPROFILE%\DESKTOP\'. ENDIF. LV_FILE_FILTER = CL_GUI_FRONTEND_SERVICES=>FILETYPE_EXCEL. * Get user's filename CALL METHOD CL_GUI_FRONTEND_SERVICES=>FILE_OPEN_DIALOG EXPORTING DEFAULT_FILENAME = LV_FILENAME DEFAULT_EXTENSION = CL_GUI_FRONTEND_SERVICES=>FILETYPE_EXCEL FILE_FILTER = CL_GUI_FRONTEND_SERVICES=>FILETYPE_EXCEL * DEFAULT_EXTENSION = 'Excel Files|*.xls|*.xlsx' INITIAL_DIRECTORY = LV_CURRENT_DIRECTORY MULTISELECTION = ABAP_FALSE CHANGING FILE_TABLE = LT_FILETABLE RC = LV_RC EXCEPTIONS FILE_OPEN_DIALOG_FAILED = 1 CNTL_ERROR = 2 ERROR_NO_GUI = 3 NOT_SUPPORTED_BY_GUI = 4 OTHERS = 5. IF ( SY-SUBRC <> 0 ) OR ( LT_FILETABLE[] IS INITIAL ). MESSAGE S013(ZCM01). EXIT. ELSE. READ TABLE LT_FILETABLE INTO LS_FILETABLE INDEX 1. PV_FNAME = LS_FILETABLE-FILENAME. ENDIF. ENDFORM. "frm_get_filename *&---------------------------------------------------------------------* *& Form download_execl *&---------------------------------------------------------------------* * text *----------------------------------------------------------------------* * -->UNAME text *----------------------------------------------------------------------* FORM FRM_DOWNLOAD_EXECL USING P_OBJID LIKE WWWDATATAB-OBJID "下载模板 P_EXTENSION TYPE STRING "扩展名 P_FIELDNAME TYPE STRING. "模板名称 CALL FUNCTION 'ZFM_DOWNLOAD_FROM_SMW0' EXPORTING IV_OBJID = P_OBJID IV_EXTENSION = P_EXTENSION "'xlsx' IV_FIELDNAME = P_FIELDNAME * IMPORTING * ES_RETURN = . ENDFORM. " DOWNLOAD_EXECL *&---------------------------------------------------------------------* *& Form upload_data *&---------------------------------------------------------------------* * 将上传的Excel的内容转换到内表中 *----------------------------------------------------------------------* FORM UPLOAD_DATA USING FILENAME. DATA: CNS_BEGIN_COL TYPE I VALUE 1 , "upload的Excel的起始列 CNS_BEGIN_ROW TYPE I VALUE 2 , "upload的Excel的起始行 CNS_END_COL TYPE I VALUE 5 , "upload的Excel的终止列 CNS_END_ROW TYPE I VALUE 65535 . "upload的Excel的终止行 DATA : L_INTERN TYPE KCDE_CELLS OCCURS 0 WITH HEADER LINE. DATA: TMP_ROW TYPE I VALUE 1 . DATA : L_INDEX TYPE I. FIELD-SYMBOLS : <FS>. * 将 Excel 的数据转化到内表 CALL FUNCTION 'KCD_EXCEL_OLE_TO_INT_CONVERT' EXPORTING FILENAME = FILENAME I_BEGIN_COL = CNS_BEGIN_COL I_BEGIN_ROW = CNS_BEGIN_ROW I_END_COL = CNS_END_COL I_END_ROW = CNS_END_ROW TABLES INTERN = L_INTERN EXCEPTIONS INCONSISTENT_PARAMETERS = 1 UPLOAD_OLE = 2 OTHERS = 3. SORT L_INTERN BY ROW COL. * 将导入的Excel的数据 循环到指定的内表中 LOOP AT L_INTERN. IF TMP_ROW <> L_INTERN-ROW . APPEND LT_AGRS . CLEAR LT_AGRS. TMP_ROW = L_INTERN-ROW. ENDIF. CASE L_INTERN-COL. WHEN 1. LT_AGRS-AGR_NAME = L_INTERN-VALUE . WHEN 2. LT_AGRS-TEXTS = L_INTERN-VALUE . WHEN 3. LT_AGRS-TCODE = L_INTERN-VALUE . TRANSLATE LT_AGRS-TCODE TO UPPER CASE. ENDCASE. ENDLOOP. APPEND LT_AGRS . CLEAR LT_AGRS. SORT LT_AGRS BY AGR_NAME . ENDFORM. " upload_data *&---------------------------------------------------------------------* *& Form FRM_BULID_ROLES *&---------------------------------------------------------------------* * text *----------------------------------------------------------------------* * --> p1 text * <-- p2 text *----------------------------------------------------------------------* FORM FRM_BULID_ROLES . DATA: LL_AGR_NAME TYPE AGR_NAME. " 角色ID DATA: LV_AGR_NAME TYPE AGR_NAME, " 角色ID LV_TEXTS TYPE AGR_TITLE. " 角色名称 DATA: LT_TSTC TYPE TABLE OF TSTC WITH HEADER LINE . IF LT_AGRS[] IS NOT INITIAL. SELECT * INTO CORRESPONDING FIELDS OF TABLE LT_TSTC FROM TSTC FOR ALL ENTRIES IN LT_AGRS WHERE TCODE = LT_AGRS-TCODE . IF SY-SUBRC EQ 0. SORT LT_TSTC BY TCODE ASCENDING . ENDIF. ENDIF. LOOP AT LT_AGRS. LV_AGR_NAME = LT_AGRS-AGR_NAME . LV_TEXTS = LT_AGRS-TEXTS . READ TABLE LT_TSTC WITH KEY TCODE = LT_AGRS-TCODE BINARY SEARCH . IF SY-SUBRC EQ 0. CLEAR GS_TCODES . GS_TCODES-TCODE = LT_AGRS-TCODE . APPEND GS_TCODES TO GT_TCODES . ENDIF. AT END OF AGR_NAME . SELECT SINGLE AGR_NAME INTO LL_AGR_NAME FROM AGR_DEFINE "筛选角色主数据 WHERE AGR_NAME = LV_AGR_NAME. IF SY-SUBRC NE 0. ENDIF. PERFORM FRM_CREATE_MODIFY_ROLES USING LV_AGR_NAME LV_TEXTS . REFRESH GT_TCODES . ENDAT . ENDLOOP. ENDFORM. " FRM_BULID_ROLES *&---------------------------------------------------------------------* *& Form FRM_CREATE_MODIFY_ROLES *&---------------------------------------------------------------------* * text *----------------------------------------------------------------------* * -->P_LV_AGR_NAME text * -->P_LV_TEXTS text *----------------------------------------------------------------------* FORM FRM_CREATE_MODIFY_ROLES USING P_AGR_NAME TYPE AGR_NAME P_TEXTS TYPE AGR_TITLE. CALL FUNCTION 'PRGN_RFC_CREATE_ACTIVITY_GROUP' EXPORTING ACTIVITY_GROUP = P_AGR_NAME ACTIVITY_GROUP_TEXT = P_TEXTS NO_DIALOG = 'X' "必须要打叉,否则会出现窗口 ORG_LEVELS_WITH_STAR = '' "相关组织级别为星号如果打叉 UNMAINTAINED_FIELDS_WITH_STAR = '' "相关未指定值字段为星号打叉 TABLES TCODES = GT_TCODES. COMMIT WORK. CALL FUNCTION 'SUPRN_PROFILE_BATCH' EXPORTING ACT_OBJID = P_AGR_NAME * LTEXT = * ENQUEUE = ' ' EXCEPTIONS OBJID_NOT_FOUND = 1 NO_AUTHORIZATION = 2 GENERATION_NOT_ACTIVE = 3 EMPTY_AUTHORIZATIONS = 4 ENQUEUE_FAILED = 5 NOT_GENERATED = 6 VALUE_OVERFLOW = 7 OTHERS = 8. IF SY-SUBRC <> 0. * Implement suitable error handling here ENDIF. ENDFORM. " FRM_CREATE_MODIFY_ROLES |