You are on page 1of 5

*//////////////////////////////////////////////////////////////////////*

*
* This program will get the list of users & the roles assigned based on
* the mentioned user group(s)
*
*//////////////////////////////////////////////////////////////////////*
*&---------------------------------------------------------------------*
*& Report z_user_roles_report
*
*& Rel. 4.6B
*
*&---------------------------------------------------------------------*
*& Author : Sasi Kiran & Raghu Boddu
*
*&---------------------------------------------------------------------*
REPORT z_user_roles_report .
TYPE-POOLS: slis.
TABLES: usr02.
DATA: BEGIN OF it_users OCCURS 0,
class LIKE usr02-class,
bname LIKE usr02-bname,
persnumber LIKE usr21-persnumber,
END OF it_users.
DATA: BEGIN OF it_adrp OCCURS 0,
persnumber LIKE adrp-persnumber,
name_first LIKE adrp-name_first,
name_last LIKE adrp-name_last,
END OF it_adrp.
DATA: BEGIN OF it_agr_users OCCURS 0,
uname LIKE agr_users-uname,
agr_name LIKE agr_users-agr_name,
from_dat LIKE agr_users-from_dat,
to_dat
LIKE agr_users-to_dat,
END OF it_agr_users.
DATA: BEGIN OF it_output OCCURS 0,
bname LIKE usr02-bname,
class
LIKE usr02-class,
name_first LIKE adrp-name_first,
name_last LIKE adrp-name_last,
agr_name LIKE agr_users-agr_name,
from_dat LIKE agr_users-from_dat,
to_dat
LIKE agr_users-to_dat,
END OF it_output.
DATA: it_fieldcat TYPE slis_fieldcat_alv OCCURS 0.
DATA: v_index
TYPE sy-tabix.
DATA: v_fieldcat TYPE slis_fieldcat_alv,
v_repid
TYPE sy-repid.
SELECT-OPTIONS: s_class FOR usr02-class.

START-OF-SELECTION.
PERFORM initialize_varibales.
PERFORM get_data.
PERFORM dispaly_alv.
*&---------------------------------------------------------------------*
*&
Form initialize_varibales
*&---------------------------------------------------------------------*
*
text
*----------------------------------------------------------------------*
* --> p1
text
* <-- p2
text
*----------------------------------------------------------------------*
FORM initialize_varibales.
REFRESH: it_users, it_adrp, it_agr_users, it_fieldcat, it_output.
CLEAR: it_users, it_adrp, it_agr_users, it_fieldcat, it_output.
v_repid = sy-repid.
ENDFORM.
" initialize_varibales
*&---------------------------------------------------------------------*
*&
Form get_data
*&---------------------------------------------------------------------*
*
text
*----------------------------------------------------------------------*
* --> p1
text
* <-- p2
text
*----------------------------------------------------------------------*
FORM get_data.
SELECT
INTO
FROM
ON
WHERE

a~class a~bname b~persnumber
TABLE it_users
usr02 AS a INNER JOIN usr21 AS b
b~bname = a~bname
a~class IN s_class.

IF sy-subrc <> 0.
MESSAGE s398(00) WITH 'No data found!'.
STOP.
ENDIF.
IF NOT it_users[] IS INITIAL.
SORT it_users BY persnumber.
SELECT persnumber name_first name_last
FROM adrp
INTO TABLE it_adrp
FOR ALL ENTRIES IN it_users
WHERE persnumber = it_users-persnumber.
SORT it_users BY bname.
SELECT uname agr_name from_dat to_dat
FROM agr_users
INTO TABLE it_agr_users
FOR ALL ENTRIES IN it_users

WHERE uname = it_users-bname.
ENDIF.
SORT it_users BY class bname.
SORT it_adrp BY persnumber.
SORT it_agr_users BY uname.
LOOP AT it_users.
CLEAR it_output.
it_output-bname = it_users-bname.
it_output-class
= it_users-class.
READ TABLE it_adrp WITH KEY persnumber = it_users-persnumber BINARY
SEARCH.
IF sy-subrc = 0.
it_output-name_first = it_adrp-name_first.
it_output-name_last = it_adrp-name_last.
ENDIF.
READ TABLE it_agr_users WITH KEY uname = it_users-bname.
IF sy-subrc = 0.
v_index = sy-tabix.
ENDIF.
WHILE sy-subrc = 0 AND it_agr_users-uname = it_users-bname.
it_output-agr_name = it_agr_users-agr_name.
it_output-from_dat = it_agr_users-from_dat.
it_output-to_dat = it_agr_users-to_dat.
APPEND it_output.
v_index = v_index + 1.
READ TABLE it_agr_users INDEX v_index.
ENDWHILE.
ENDLOOP.
ENDFORM.
" get_data
*&---------------------------------------------------------------------*
*&
Form dispaly_alv
*&---------------------------------------------------------------------*
*
text
*----------------------------------------------------------------------*
* --> p1
text
* <-- p2
text
*----------------------------------------------------------------------*
FORM dispaly_alv.
CLEAR v_fieldcat.
v_fieldcat-ref_tabname = 'USR02'.
v_fieldcat-ref_fieldname = 'BNAME'.
v_fieldcat-tabname = 'IT_OUTPUT'.
v_fieldcat-fieldname = 'BNAME'.
v_fieldcat-seltext_l = 'User ID'.
v_fieldcat-outputlen = '12'.

APPEND v_fieldcat TO it_fieldcat.
CLEAR v_fieldcat.
v_fieldcat-ref_tabname = 'USR02'.
v_fieldcat-ref_fieldname = 'CLASS'.
v_fieldcat-tabname = 'IT_OUTPUT'.
v_fieldcat-fieldname = 'CLASS'.
v_fieldcat-seltext_l = 'User Group'.
v_fieldcat-outputlen = '12'.
APPEND v_fieldcat TO it_fieldcat.
CLEAR v_fieldcat.
v_fieldcat-ref_tabname = 'ADRP'.
v_fieldcat-ref_fieldname = 'NAME_FIRST'.
v_fieldcat-tabname = 'IT_OUTPUT'.
v_fieldcat-fieldname = 'NAME_FIRST'.
v_fieldcat-seltext_l = 'First Name'.
v_fieldcat-outputlen = '20'.
APPEND v_fieldcat TO it_fieldcat.
CLEAR v_fieldcat.
v_fieldcat-ref_tabname = 'ADRP'.
v_fieldcat-ref_fieldname = 'NAME_LAST'.
v_fieldcat-tabname = 'IT_OUTPUT'.
v_fieldcat-fieldname = 'NAME_LAST'.
v_fieldcat-seltext_l = 'Last Name'.
v_fieldcat-outputlen = '20'.
APPEND v_fieldcat TO it_fieldcat.
CLEAR v_fieldcat.
v_fieldcat-ref_tabname = 'AGR_USERS'.
v_fieldcat-ref_fieldname = 'AGR_NAME'.
v_fieldcat-tabname = 'IT_OUTPUT'.
v_fieldcat-fieldname = 'AGR_NAME'.
v_fieldcat-seltext_l = 'Role name'.
v_fieldcat-outputlen = '30'.
APPEND v_fieldcat TO it_fieldcat.
CLEAR v_fieldcat.
v_fieldcat-ref_tabname = 'AGR_USERS'.
v_fieldcat-ref_fieldname = 'FROM_DAT'.
v_fieldcat-tabname = 'IT_OUTPUT'.
v_fieldcat-fieldname = 'FROM_DAT'.
v_fieldcat-seltext_l = 'Start Date'.
v_fieldcat-outputlen = '10'.
APPEND v_fieldcat TO it_fieldcat.
CLEAR v_fieldcat.
v_fieldcat-ref_tabname = 'AGR_USERS'.
v_fieldcat-ref_fieldname = 'TO_DAT'.
v_fieldcat-tabname = 'IT_OUTPUT'.
v_fieldcat-fieldname = 'TO_DAT'.
v_fieldcat-seltext_l = 'End Date'.
v_fieldcat-outputlen = '10'.
APPEND v_fieldcat TO it_fieldcat.
CALL FUNCTION 'REUSE_ALV_LIST_DISPLAY'
EXPORTING
i_callback_program = v_repid

it_fieldcat
TABLES
t_outtab
EXCEPTIONS
program_error
OTHERS
IF sy-subrc <> 0.

= it_fieldcat
= it_output
= 1
= 2.

ENDIF.
ENDFORM.

" dispaly_alv