Google Search - Blog...........

ABAP - Function Module To Get Authorisation Details Of A User.

This function module gets the authorisation value for a User and authorisation object on any given date.
/*

FUNCTION z_check_authorization.
*"----------------------------------------------------------------------
*"*"Local interface:
*" IMPORTING
*" VALUE(UNAME) TYPE SYUNAME DEFAULT SY-UNAME
*" VALUE(OBJECT) TYPE XUOBJECT
*" VALUE(FIELD) TYPE XUFIELD OPTIONAL
*" VALUE(DATE) TYPE DATS DEFAULT SY-DATUM
*" TABLES
*" AUTHTAB STRUCTURE ZHR_AUTHOBJECT
*"----------------------------------------------------------------------

*-------------------------------------------*
* Data Declaration
*-------------------------------------------*
DATA: BEGIN OF authobj,
begda TYPE begda,
endda TYPE endda,
agr_name TYPE agr_name,
auth TYPE auth,
END OF authobj.

DATA: l_field TYPE xufield.

* Internal tables.

DATA:
itab_agr_users TYPE STANDARD TABLE OF agr_users WITH HEADER LINE,
itab_agr_1250 TYPE STANDARD TABLE OF agr_1250 WITH HEADER LINE,
itab_ust12 TYPE STANDARD TABLE OF ust12 WITH HEADER LINE.



*-------------------------------------------*
* Processing Logic
*-------------------------------------------*

REFRESH authtab. CLEAR authtab.
REFRESH itab_agr_users. CLEAR itab_agr_users.
REFRESH itab_agr_1250. CLEAR itab_agr_1250.
REFRESH itab_ust12. CLEAR itab_ust12.

SELECT * FROM agr_users INTO TABLE itab_agr_users
WHERE uname EQ uname
AND from_dat LE date
AND to_dat GT date.

LOOP AT itab_agr_users.
SELECT * FROM agr_1250
APPENDING CORRESPONDING FIELDS OF TABLE itab_agr_1250
WHERE agr_name = itab_agr_users-agr_name.
ENDLOOP.

LOOP AT itab_agr_1250.
IF field is initial.
SELECT * FROM ust12
APPENDING CORRESPONDING FIELDS OF TABLE itab_ust12
WHERE objct = object
AND auth = itab_agr_1250-auth
AND aktps = 'A'.
ELSE.
SELECT * FROM ust12
APPENDING CORRESPONDING FIELDS OF TABLE itab_ust12
WHERE objct = object
AND auth = itab_agr_1250-auth
AND aktps = 'A'
and field = field.
endif. ENDLOOP. LOOP AT itab_ust12.
authtab-seqnr = sy-tabix.
authtab-field = itab_ust12-field.
authtab-fieldval = itab_ust12-von.
APPEND authtab.

ENDLOOP.
delete adjacent duplicates from authtab comparing field.

ENDFUNCTION.*/

No comments:

Post a Comment