User-dependent BAdI implementation. How?

1.6k views Asked by At

Is there any way to create user-dependent BAdI implementations? I mean that the BAdI has different implementations which are called depending on user which is logged and which calls the specific transaction.

Other scenario is to not call certain implementations for this user and to call for other user. Is is possible?

Now I'm using simple check

IF sy-uname = 'username'.
1

There are 1 answers

1
Philipp On BEST ANSWER

New BAdIs allow the GET BADI call to have one or more FILTERS parameters which can be used in the implementation definition to select different implementing classes. But these filter parameters must be provided by the code which calls the BAdI. When the standard code doesn't provide the username as a filter parameter, there is no way to choose an implementing class based on the username.

So when you want different logic for different users, you need to do this in your implementation code. But using the username to decide what to do might not be the most maintainable architecture.

I guess the reason why the BAdI is supposed to behave differently for a specific user is because that user has some special job in the company. What will you do when the person who has this position changes, or when he gets one or two other people to help them, or when he just calls in sick and someone else has to do his job? Do you want to transport a program change whenever that happens? But there are other options:

  • Different behavior by user group. You can read the user group from the database table usr02 (field CLASS)
  • Different behavior by permissions. Do an AUTHORITY-CHECK, and make the BAdI behave differently depending on the success.
  • Different behavior by user parameter. To read a user parameter in your program, use GET PARAMETER ID. The parameters of a user can be set by the administrators in the transaction SU03, by the users themself with the transaction SU3 (when they have the permission to do so) or programatically with SET PARAMETER ID.