Program to find T-Code
Roles org. level against SAP User.
This
program is basically for the basis guys who want all the information of a user
on one click.
SAP
User -> T-Code -> SAP Roles -> Org. level
Table used:
AGR_USERS - Assignment of
roles to users
AGR_1252 - Organizational
elements for authorizations
AGR_1251 - Authorization
data for the activity group
REPORT ztest.
PARAMETERS : user TYPE agr_users-uname DEFAULT 'RAHUL_ABAP'.
TYPES : BEGIN OF ty_final,
tcode TYPE tcode, " tcode
uname TYPE agr_users-uname, " user name
role TYPE agr_name, " ROLE
varbl TYPE agr_1252-varbl, " org level
END OF ty_final.
DATA: it_final TYPE TABLE OF ty_final,
wa_final TYPE ty_final.
DATA: it_fieldcat TYPE slis_t_fieldcat_alv,
wa_fcat TYPE slis_fieldcat_alv.
START-OF-SELECTION.
PERFORM fetch_data.
PERFORM display_data.
*&---------------------------------------------------------------------*
*& Form FETCH_DATA
*&---------------------------------------------------------------------*
*& text
*&---------------------------------------------------------------------*
*& --> p1 text
*& <-- p2 text
*&---------------------------------------------------------------------*
FORM fetch_data .
SELECT agr_name, " role
uname
FROM agr_users INTO TABLE @DATA(t_user) WHERE uname = @user. " for all role
SELECT agr_name,
varbl
FROM agr_1252 INTO TABLE @DATA(t_agr) FOR ALL ENTRIES IN @t_user WHERE agr_name = @t_user-agr_name. " for all org level agains role
SORT t_agr BY agr_name.
SELECT agr_name,
low
FROM AGR_1251 INTO TABLE @DATA(t_tcode) FOR ALL ENTRIES IN @t_user WHERE agr_name = @t_user-agr_name AND OBJECT = 'S_TCODE'.
LOOP AT t_tcode INTO DATA(w_tcode) .
wa_final-tcode = w_tcode-low.
wa_final-uname = user.
LOOP AT t_agr INTO DATA(w_agr) WHERE agr_name = w_tcode-agr_name.
wa_final-role = w_agr-agr_name.
wa_final-varbl = w_agr-varbl.
APPEND wa_final TO it_final.
CLEAR: w_agr, wa_final.
ENDLOOP.
CLEAR w_tcode.
ENDLOOP.
ENDFORM.
*&---------------------------------------------------------------------*
*& Form DISPLAY_DATA
*&---------------------------------------------------------------------*
*& text
*&---------------------------------------------------------------------*
*& --> p1 text
*& <-- p2 text
*&---------------------------------------------------------------------*
FORM display_data .
PERFORM create_fieldcat.
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
EXPORTING
* I_INTERFACE_CHECK = ' '
* I_BYPASSING_BUFFER = ' '
* I_BUFFER_ACTIVE = ' '
i_callback_program = sy-repid
* I_CALLBACK_PF_STATUS_SET = ' '
* I_CALLBACK_USER_COMMAND = 'INT_ALV1'
it_fieldcat = it_fieldcat
* IT_EXCLUDING =
* IT_SPECIAL_GROUPS =
* IT_SORT =
* IT_FILTER =
* IS_SEL_HIDE =
i_default = 'X'
i_save = 'I'
TABLES
t_outtab = it_final[]
EXCEPTIONS
program_error = 1
OTHERS = 2.
IF sy-subrc <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
ENDFORM.
*&---------------------------------------------------------------------*
*& Form CREATE_FIELDCAT
*&---------------------------------------------------------------------*
*& text
*&---------------------------------------------------------------------*
*& --> p1 text
*& <-- p2 text
*&---------------------------------------------------------------------*
FORM create_fieldcat .
wa_fcat-fieldname = 'UNAME'.
wa_fcat-tabname = 'IT_FINAL'.
wa_fcat-seltext_m = 'USER NAME'.
wa_fcat-outputlen = '20'.
APPEND wa_fcat TO it_fieldcat.
CLEAR wa_fcat.
wa_fcat-fieldname = 'TCODE'.
wa_fcat-tabname = 'IT_FINAL'.
wa_fcat-seltext_m = 'T-CODE'.
wa_fcat-outputlen = '20'.
APPEND wa_fcat TO it_fieldcat.
CLEAR wa_fcat.
wa_fcat-fieldname = 'ROLE'.
wa_fcat-tabname = 'IT_FINAL'.
wa_fcat-seltext_m = 'ROLE.'.
wa_fcat-outputlen = '30'.
APPEND wa_fcat TO it_fieldcat.
CLEAR wa_fcat.
wa_fcat-fieldname = 'VARBL'.
wa_fcat-tabname = 'IT_FINAL'.
wa_fcat-seltext_m = 'ORG. LEVEL'.
wa_fcat-outputlen = '30'.
APPEND wa_fcat TO it_fieldcat.
CLEAR wa_fcat.
ENDFORM.
No comments:
Post a Comment