cancel
Showing results for 
Search instead for 
Did you mean: 

Authority Check-For Cost Center Based on User name

janardhan-16
Discoverer
0 Kudos
188

Hi all, I hope all are doing well.

I'm new to  SAP ABAP.

We have requirement from our client, where a user should be restricted by the user name to a particular cost center.

For this I have created a Custom Table with fields MANDT, UNAME & KOSTL and i have assigned the cost centers based on User name.

EX:|UNAME ||KOSTL|

    USER1    CC1000

    USER1    CC2000

    USER2    CC2000

    USER3    CC3000

And also I have developed the code in standard functionality using Exits(Enhancements) EXIT_SAPLKBER_001.

But my code is restricting for all users even they are available in table also. 

Can anyone suggest me a proper approach to get a expected output.

Thanks in advance..... 

For Your Reference:

TYPESBEGIN OF ts_z_cs_auth,
         mandt TYPE z_cs_auth-mandt,
         uname TYPE z_cs_auth-uname,
         kostl TYPE z_cs_auth-kostl,
       END OF z_ts_cs_auth.

* Internal Table
DATAlt_user_cs TYPE TABLE OF z_ts_cs_auth.

* Work Area
DATAls_user_cs TYPE ts_z_cs_auth.

* Local Variables
DATAlv_user_name       TYPE sy-uname,
      lv_cs              TYPE ts_z_cs_auth-kostl,
*      lv_message         TYPE string,
      lv_authority_check TYPE LENGTH 1.

lv_user sy-uname.
" Read the authorized cost centers for the user from the custom table
SELECT uname
       kostl
  INTO TABLE lt_user_cs
  FROM z_cs_auth
  WHERE uname lv_user AND kostl lv_cs.
IF lt_user_cs IS INITIAL.
  " No entries found for the user in the custom table
  MESSAGE e001(zuser_auth).
  EXIT.
ENDIF.

CALL FUNCTION 'AUTHORITY_CHECK'
  EXPORTING
*   NEW_BUFFERING       = 3
    user                sy-uname
    object              'z_cs_auth'
    field1              'kostl'
    value1              ls_user_cs-kostl
  EXCEPTIONS
    user_dont_exist     1
    user_is_authorized  2
    user_not_authorized 3
    user_is_locked      4
    OTHERS              5.
IF sy-subrc <> 0.
* Implement suitable error handling here
  MESSAGE e002(zuser_auth).
  EXIT.
ENDIF.

View Entire Topic
Ehsan_Ghasemi
Participant
0 Kudos

Hello 

First of all, you should check the cost center is reachable at this exit.  If yes, then you must fill lv_cs by cost center  that pass to exit.

SELECT count(*)
  FROM z_cs_auth
  WHERE uname = @SY-uname AND kostl = @iv_kostl."iv_kostl is cost center that reachabel form exit.
IF sy-subrc is not INITIAL.
  " No entries found for the user in the custom table
  MESSAGE e001(zuser_auth).
  EXIT.
ENDIF.