메뉴 건너뛰기

SAP 한국 커뮤니티



REPORT z_list_user_profiles

노름마치 2007.11.05 22:03 조회 수 : 4463

REPORT z_list_user_profiles.
*---------------------------------------------------------------------*
* This program lists the user's auth. profiles.
*---------------------------------------------------------------------*
* Author : Michel PIOUD                                               *
* Email : mpioud@yahoo.fr  HomePage : http://www.geocities.com/mpioud *
*---------------------------------------------------------------------*
TABLES : usr02,                        " Logon data
         ust04,                        " User masters
         ust10c,                       " Profile
         usr10.                        " User authorization profiles


TYPE-POOLS: slis.                      " ALV Global types


SELECTION-SCREEN :
BEGIN OF LINE, COMMENT 20(10) 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 20(10) v_2 FOR FIELD s_profil.       "#EC NEEDED
SELECT-OPTIONS s_profil FOR ust10c-profn.
SELECTION-SCREEN END OF LINE.


SELECTION-SCREEN :
BEGIN OF LINE, COMMENT 20(10) v_3 FOR FIELD s_class.        "#EC NEEDED
SELECT-OPTIONS s_class FOR usr02-class.
SELECTION-SCREEN END OF LINE.


DATA :
  BEGIN OF gt_user OCCURS 0,
    bname     LIKE usr04-bname,        " SAP User name
    name_last LIKE addr3_val-name_last," User name
    class     LIKE usr02-class,        " User group
    profile   LIKE ust04-profile,      " Profile
    ptext     LIKE usr11-ptext,        " Texts authorizations
    samprof,
  END OF gt_user.


*---------------------------------------------------------------------*
INITIALIZATION.


  v_1 = 'User'.
  v_2 = 'Profile'.
  v_3 = 'User group'.


*---------------------------------------------------------------------*
START-OF-SELECTION.


  PERFORM f_read_data.


  PERFORM f_display_data.


*---------------------------------------------------------------------*
*      Form  f_read_data
*---------------------------------------------------------------------*
FORM f_read_data.


  CONSTANTS :
    lc_aktivated  VALUE 'A',
    lc_generprof  VALUE 'G',
    lc_colectprof VALUE 'C'.


  DATA l_adresse LIKE addr3_val.


  FIELD-SYMBOLS <user> LIKE LINE OF gt_user.


  SELECT t~bname profile class
    INTO CORRESPONDING FIELDS OF TABLE gt_user
    FROM ust04 AS t
    JOIN usr02 AS r ON t~bname = r~bname
   WHERE t~bname IN s_bname
     AND profile IN s_profil
     AND class   IN s_class.


* Sorting to improve performance with FM 'SUSR_USER_ADDRESS_READ'
  SORT gt_user BY bname.


  LOOP AT gt_user ASSIGNING <user>.
    CLEAR usr10.
    SELECT SINGLE * FROM usr10
                   WHERE profn = <user>-profile
                     AND aktps = lc_aktivated.
    IF usr10-typ = lc_colectprof.
      <user>-samprof = 'X'.
    ELSEIF usr10-typ = lc_generprof.
      <user>-samprof = lc_generprof.
    ENDIF.


*   Get the profile texts.
    SELECT SINGLE ptext FROM usr11
                        INTO <user>-ptext
                       WHERE langu = sy-langu
                         AND profn = <user>-profile
                         AND aktps = lc_aktivated.


    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.


ENDFORM.                               " F_READ_DATA
*---------------------------------------------------------------------*
*      Form  f_display_data
*---------------------------------------------------------------------*
FORM f_display_data.


  DEFINE m_fieldcat.
    add 1 to ls_fieldcat-col_pos.
    ls_fieldcat-fieldname   = &1.
    ls_fieldcat-ref_tabname = &2.
    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        = &2.
    ls_sort-group     = &3.
    append ls_sort to lt_sort.
  END-OF-DEFINITION.


  DATA:
    ls_fieldcat TYPE slis_fieldcat_alv,
    lt_fieldcat TYPE slis_t_fieldcat_alv,
    lt_sort     TYPE slis_t_sortinfo_alv,
    ls_sort     TYPE slis_sortinfo_alv,
    ls_layout   TYPE slis_layout_alv.


  m_fieldcat 'BNAME'     'UST04'.
  m_fieldcat 'NAME_LAST' 'ADDR3_VAL'.
  m_fieldcat 'CLASS'     'USR02'.
  m_fieldcat 'PROFILE'   'UST04'.
  m_fieldcat 'PTEXT'     'USR11'.
  m_fieldcat 'SAMPROF'   'USR10'.


  m_sort 'BNAME'     'X' 'UL'.
  m_sort 'NAME_LAST' 'X' ''.
  m_sort 'PROFILE'   'X' ''.


  ls_layout-group_change_edit = 'X'.
  ls_layout-colwidth_optimize = 'X'.
  ls_layout-zebra             = 'X'.
  ls_layout-cell_merge        = 'X'.
  ls_layout-detail_popup      = 'X'.
  ls_layout-get_selinfos      = 'X'.


  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
       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


  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 :
    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.
      CASE us_selfield-fieldname.
        WHEN 'PROFILE'.
          CALL FUNCTION 'SUSR_PROF_DISPLAY_WITH_AUTHS'
               EXPORTING
                    profile = gt_user-profile.
        WHEN OTHERS.
          m_bdc_dynpro 'SAPLSUU5' '0050' '=SHOW'.
          m_bdc_field  'USR02-BNAME' gt_user-bname.


          m_bdc_dynpro 'SAPLSUU5' '0100' '=PROF'.


          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).
      ENDCASE.
  ENDCASE.


ENDFORM.
***************** END OF PROGRAM Z_LIST_USER_PROFILES *****************