REPORT z_modify_user_parameter_id.
*---------------------------------------------------------------------*
* This program lists the user's Parameter-IDs, These Parameter-IDs *
* can be modified and saved via Batch-Input *
*---------------------------------------------------------------------*
* Author : Michel PIOUD *
* Email : mpioud@yahoo.fr HomePage : http://www.geocities.com/mpioud *
*---------------------------------------------------------------------*
TABLES : ust04, " User masters
usr05. " User Master Parameter ID
TYPE-POOLS: slis. " ALV Global types
SELECTION-SCREEN :
BEGIN OF LINE, COMMENT 10(20) v_1 FOR FIELD s_bname. "#EC NEEDED
SELECT-OPTIONS s_bname FOR ust04-bname.
SELECTION-SCREEN END OF LINE.
SELECTION-SCREEN :
BEGIN OF LINE, COMMENT 10(20) v_2 FOR FIELD s_parid. "#EC NEEDED
SELECT-OPTIONS s_parid FOR usr05-parid.
SELECTION-SCREEN END OF LINE.
SELECTION-SCREEN :
SKIP, BEGIN OF LINE,COMMENT 10(20) v_3 FOR FIELD p_dsplay."#EC NEEDED
PARAMETERS p_dsplay AS CHECKBOX.
SELECTION-SCREEN END OF LINE.
CONSTANTS :
gc_refresh TYPE syucomm VALUE '&REFRESH'.
TYPES :
BEGIN OF ty_s_user,
bname LIKE usr04-bname, " User name
name_last LIKE addr3_val-name_last," Last name
parid LIKE usr05-parid, " Set/Get parameter ID
partext LIKE tparat-partext, " Memory ID Text
parva LIKE usr05-parva, " Parameter value
END OF ty_s_user.
DATA :
gt_user TYPE STANDARD TABLE OF ty_s_user WITH HEADER LINE,
gt_user_old TYPE SORTED TABLE OF ty_s_user
WITH UNIQUE KEY bname parid.
FIELD-SYMBOLS <user> LIKE LINE OF gt_user.
*---------------------------------------------------------------------*
INITIALIZATION.
v_1 = 'User'.
v_2 = 'Parameter Id'.
v_3 = 'Display only'.
*---------------------------------------------------------------------*
START-OF-SELECTION.
PERFORM f_read_data.
PERFORM f_display_data.
*---------------------------------------------------------------------*
* Form f_read_data
*---------------------------------------------------------------------*
FORM f_read_data.
DATA :
l_mandt TYPE mandt, "#EC NEEDED
l_adresse LIKE addr3_val.
* Read data
SELECT bname parid parva
INTO CORRESPONDING FIELDS OF TABLE gt_user
FROM usr05
WHERE bname IN s_bname
AND parid IN s_parid.
* Sorting to improve performance with FM 'SUSR_USER_ADDRESS_READ'
SORT gt_user BY bname.
LOOP AT gt_user ASSIGNING <user>.
* User exists ?
SELECT SINGLE mandt INTO l_mandt
FROM usr01
WHERE bname = <user>-bname.
IF sy-subrc NE 0.
DELETE gt_user. " Delete
CONTINUE. " Next loop.
ENDIF.
* Get the parameter-id texts.
SELECT SINGLE partext INTO <user>-partext
FROM tparat
WHERE paramid = <user>-parid
AND sprache = sy-langu.
IF sy-subrc NE 0 AND sy-langu <> 'E'.
* Not found, try in English
SELECT SINGLE partext INTO <user>-partext
FROM tparat
WHERE paramid = <user>-parid
AND sprache = 'E'.
ENDIF.
IF sy-subrc NE 0 AND sy-langu <> 'D'.
* Not found, try in German
SELECT SINGLE partext INTO <user>-partext
FROM tparat
WHERE paramid = <user>-parid
AND sprache = 'D'.
ENDIF.
* Get user address data
CALL FUNCTION 'SUSR_USER_ADDRESS_READ'
EXPORTING
user_name = <user>-bname
* READ_DB_DIRECTLY = ' '
IMPORTING
user_address = l_adresse
* USER_USR03 =
EXCEPTIONS
user_address_not_found = 1
OTHERS = 2.
IF sy-subrc = 0.
CONCATENATE l_adresse-name_last l_adresse-name_first
INTO <user>-name_last SEPARATED BY space.
ELSE.
<user>-name_last = <user>-bname.
ENDIF.
ENDLOOP.
* Save data
gt_user_old[] = gt_user[].
ENDFORM. " F_READ_DATA
*---------------------------------------------------------------------*
* Form f_display_data
*---------------------------------------------------------------------*
FORM f_display_data.
* Macro definition
DEFINE m_fieldcat.
add 1 to ls_fieldcat-col_pos.
ls_fieldcat-fieldname = &1.
ls_fieldcat-ref_tabname = &2.
ls_fieldcat-edit = &3.
append ls_fieldcat to lt_fieldcat.
END-OF-DEFINITION.
DEFINE m_sort.
add 1 to ls_sort-spos.
ls_sort-fieldname = &1.
ls_sort-up = 'X'.
ls_sort-group = &2.
append ls_sort to lt_sort.
END-OF-DEFINITION.
DATA:
ls_fieldcat TYPE slis_fieldcat_alv,
lt_fieldcat TYPE slis_t_fieldcat_alv, " Field catalog
lt_sort TYPE slis_t_sortinfo_alv,
ls_sort TYPE slis_sortinfo_alv,
lt_event_exit TYPE slis_t_event_exit,
ls_event_exit TYPE slis_event_exit,
ls_layout TYPE slis_layout_alv.
* Build field catalog and sort table
m_fieldcat 'BNAME' 'USR05' ''.
m_fieldcat 'NAME_LAST' 'ADDR3_VAL' ''.
m_fieldcat 'PARID' 'USR05' ''.
m_fieldcat 'PARTEXT' 'TPARAT' ''.
IF p_dsplay IS INITIAL.
m_fieldcat 'PARVA' 'USR05' 'X'. " Column alterable
ELSE.
m_fieldcat 'PARVA' 'USR05' ''.
ENDIF.
m_sort 'BNAME' 'UL'. " Line break
m_sort 'NAME_LAST' ''.
m_sort 'PARID' ''.
ls_layout-group_change_edit = 'X'.
ls_layout-colwidth_optimize = 'X'.
ls_layout-cell_merge = 'X'.
ls_layout-detail_popup = 'X'.
ls_layout-get_selinfos = 'X'.
CLEAR ls_event_exit.
ls_event_exit-ucomm = gc_refresh. " Refresh
ls_event_exit-after = 'X'.
APPEND ls_event_exit TO lt_event_exit.
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
EXPORTING
i_callback_program = sy-cprog
i_callback_user_command = 'USER_COMMAND'
is_layout = ls_layout
it_fieldcat = lt_fieldcat
it_sort = lt_sort
it_event_exit = lt_event_exit
TABLES
t_outtab = gt_user.
ENDFORM. " F_DISPLAY_DATA
*---------------------------------------------------------------------*
* FORM USER_COMMAND *
*---------------------------------------------------------------------*
FORM user_command USING u_ucomm LIKE sy-ucomm
us_selfield TYPE slis_selfield. "#EC CALLED
* Macro definition
DEFINE m_bdc_dynpro.
clear lt_bdcdata.
lt_bdcdata-program = &1.
lt_bdcdata-dynpro = &2.
lt_bdcdata-dynbegin = 'X'.
lt_bdcdata-fnam = 'BDC_OKCODE'.
lt_bdcdata-fval = &3.
append lt_bdcdata.
END-OF-DEFINITION.
DEFINE m_bdc_field.
clear lt_bdcdata.
lt_bdcdata-fnam = &1.
lt_bdcdata-fval = &2.
append lt_bdcdata.
END-OF-DEFINITION.
DATA :
l_modif TYPE flag,
lt_message TYPE STANDARD TABLE OF bdcmsgcoll WITH HEADER LINE,
lt_bdcdata TYPE STANDARD TABLE OF bdcdata WITH HEADER LINE.
CASE u_ucomm.
WHEN '&IC1'.
READ TABLE gt_user INDEX us_selfield-tabindex.
CHECK sy-subrc EQ 0.
m_bdc_dynpro 'SAPLSUU5' '0050' '=SHOW'.
m_bdc_field 'USR02-BNAME' gt_user-bname.
* Tabstrip Parameter-Id
m_bdc_dynpro 'SAPLSUU5' '0100' '=PARAM'.
* Show user
CALL TRANSACTION 'SU01' USING lt_bdcdata MODE 'E'
MESSAGES INTO lt_message.
READ TABLE lt_message WITH KEY msgid = '01'
msgnr = '495'.
CHECK sy-subrc EQ 0.
* You are not authorized to display users
MESSAGE i495(01).
WHEN '&DATA_SAVE'.
* Update User's Parameter-IDs
LOOP AT gt_user.
READ TABLE gt_user_old ASSIGNING <user>
WITH KEY bname = gt_user-bname
parid = gt_user-parid.
CHECK gt_user-parva <> <user>-parva.
l_modif = 'X'.
m_bdc_dynpro 'SAPLSUU5' '0050' '=CHAN'.
m_bdc_field 'USR02-BNAME' gt_user-bname.
* Tabstrip Parameter-Id
m_bdc_dynpro 'SAPLSUU5' '0100' '=PARAM'.
* Last page
m_bdc_dynpro 'SAPLSUU5' '0100' '=P++'.
* Previous page
m_bdc_dynpro 'SAPLSUU5' '0100' '=P+'.
m_bdc_dynpro 'SAPLSUU5' '0100' '=CHECK'.
m_bdc_field 'USPARAM-PARID(10)' gt_user-parid.
m_bdc_field 'USPARAM-PARVA(10)' gt_user-parva.
* Save
m_bdc_dynpro 'SAPLSUU5' '0100' '=UPD'.
CALL TRANSACTION 'SU01' USING lt_bdcdata MODE 'E'
MESSAGES INTO lt_message.
READ TABLE lt_message WITH KEY msgid = '01'
msgnr = '492'.
IF sy-subrc EQ 0.
* You are not authorized to change users in group &
MESSAGE i492(01) WITH lt_message-msgv1.
EXIT.
ENDIF.
REFRESH lt_bdcdata.
ENDLOOP.
IF l_modif IS INITIAL.
MESSAGE i208(00) WITH 'Nothing to do ...'.
ELSE.
gt_user_old[] = gt_user[].
ENDIF.
WHEN '&REFRESH'.
PERFORM f_read_data. " Refresh data
us_selfield-refresh = 'X'.
ENDCASE.
ENDFORM. " USER_COMMAND
************ END OF PROGRAM Z_MODIFY_USER_PARAMETER_ID ****************
유용하게 사용하겠습니다. 감사합니다^^