有朋友问到怎么批量分配角色到用户,刚上班跟踪了下源代码,发现了这个FM,特意分享给大家。PRGN_1001_SAVE_USER_ASSIGNMENT
*&---------------------------------------------------------------------*
*& Report ZYCC248
*&---------------------------------------------------------------------*
*&
*&---------------------------------------------------------------------*
REPORT zycc248.
DATA p_agr_name TYPE agr_name.
p_agr_name = 'ZFIORITEST'.
DATA: lt_asgm_new TYPE TABLE OF agr_users.
DATA: lf_error TYPE char01.
APPEND INITIAL LINE TO lt_asgm_new ASSIGNING FIELD-SYMBOL(<fs>).
<fs>-mandt = '102'.
<fs>-agr_name = 'ZFIORITEST'.
<fs>-uname = '007374'.
<fs>-from_dat = sy-datum.
<fs>-to_dat = '99991231'.
* Table I_AGR_USERS always contains the current user assignments on the
* screen while I_AGR_USERS_SIK reflects the assignments on database.
"lt_asgm_new = i_agr_users[].
CALL FUNCTION 'PRGN_1001_SAVE_USER_ASSIGNMENT'
EXPORTING
activity_group = p_agr_name
" zbv_active = zbv_active
" central_system = gd_cua_center
update_table = 'X'
IMPORTING
ef_error = lf_error
TABLES
i_agr_users = lt_asgm_new.
"i_agr_users_sik = i_agr_users_sik.
IF lf_error IS INITIAL.
COMMIT WORK AND WAIT.
ENDIF.