List SAP User-Roles Assignments in ABAP Code
To get a list of valid SAP User Role assignments in ABAP codes, developers can use AGR_USERS SAP transparent table to get a similar list seen on SU01D transaction screen.
Using SAP SU01D transaction code (Display Users screen), SAP users can display the Roles assigned to a specific SAP user or assigned roles to themselves.
SAP user roles assignments are stored in ABAP table AGR_USERS with the validity dates.
If you query the transparent table AGR_USERS in SE11 or using ABAP codes, you can get a list of SAP roles assigned to a user as follows
Here is a short ABAP code which queries SAP table AGR_USERS for valid user roles at the execution time for the current SAP user and lists SAP user roles on the screen.
SELECT * INTO TABLE @DATA(gt_user_roles)
WHERE uname = @syst-uname
AND agr_name LIKE '%CUS%'
AND from_dat <= @syst-datum
AND to_dat >= @syst-datum.
LOOP AT gt_user_roles REFERENCE INTO DATA(lr_user_role).
WRITE :/ lr_user_role->agr_name.