A Badi or Business Add-in is an software extensions to SAP developments. With Object Oriented programming the road to a better approach to user exits became available. Badi's are made available by SAP and can be implemented as part of the Object oriented framework.
With transaction SE18
and SE19
the available Badi implementations can be looked up and activated/deactivated. Badi's are not very new, which means there are old style Badi's and new style Badi's available. To implement a Badi, a Badi class is created and coding within it's methods is made available. Multiple Badi implementations can be created for the same starting-point and filtering logic can be applied to identify whether the respective Badi should be involved in a given case.
So what can be implemented with a Badi ? Just about anything, but normally the additions have a well defined purpose, the names of the available methods and the parameters on these methods should be quite clear indications of what can/should be done.
A practical example - definition
Just to explain why there is an SE18
as well as an SE19
let's have a closer look at an example Badi implementation. In effect, a BAdi is an interface. Interfaces can be implemented through a class and the implementation class for Badi's is something you will need to add to your own system. Nothing to worry about, because most Badi's come with example implementation classes, such as our example for today, the HRBAS00_STRUAUTH
.
Badi HRBAS00_STRUAUTH
is about "structural authorization" which is quite a tricky topic, but will serve as example just fine. First of all, since we already know which BAdi we want to implement, let's look at the definition in transaction SE18
- BAdi Builder - definition. Set the BAdi name and select "Display". The BAdi definition is shown, it has a name and description, it is assigned a package (mind you, you could set up BAdi's for your own custom solutions as well) and it has a type. BAdi's can be implemented "when they are applicable" or always. BAdi's can also be implemented several times. So your finance department has developers working the system, and the MM/SD department also work with their own developments - and both want to use the same BAdi implementation. All possible. The type is used to define whether multiple implementations are allowed, and what the filtering conditions apply for your BAdi to be relevant (Only for company code ...).
Then there is an "Interface" tab which will reveal the interface definition for the implementing class. An interface is effectively the definition of methods (and their parameters) of a class. Transaction SE24
will reveal all there is to reveal on the interface - in this example the IF_EX_AUTHORITY_BADI
.
Just to keep all viewers happy - I'll skip the FCodes and Subscreens tabs for now.
In the "Interface" tab on SE18
the interface is shown and an example implementation class is shown. For this example, this is class CL_EXM_IM_HRBAS00_STRUAUTH
. A class which was composed, implementing the interface IF_EX_AUTHORITY_BADI
. Thus all methods (and parameters) that are listed on the interface, are available on the implementation class. Btw, the implementation class can hold other methods as well, in fact, it could implement whole other interfaces as well. Let's have a look at SE24
Class builder for the CL_EXM_IM_HRBAS00_STRUAUTH
class, check the Interfaces tab: you will find the interface from our BAdi here.
So what is this implementation class for ? I'ts an example implementation which you can used to create your own implementation with. Simply copy the example class to your own Z
-class and implement the BAdi with it. That's where SE19
- BAdi builder - implementations comes in.
The implementation
Before attempting your own implementation, you should find out whether the BAdi was already implemented. This way you can chose whether you want to change the existing implementation or create a new one.
From SE18
's main screen, go to Implementation > Overview. This will list implementations that are already in place. Any implementations available ? Pick up the name and hand it to SE19
BAdi builder - implementations to find out which implementation class was used for the Badi. No implementations available yet ? Let's create one - using SAP's example class - so we can get a grip on how it works.
SAP's example class can itself only be implemented if you want to change it. Since it is quite a felony (serious crime) to change SAP's standard programs (you would need an access key) we will copy the CL_EXM_IM_HRBAS00_STRUAUTH
to ZCL_EXM_IM_HRBAS00_STRUAUTH
in transaction SE24
first. Then we will start SE19
fill the definition name (HRBAS00_STRUAUTH
) on the bottom part of the screen and select "Create implementation". It's a good coding convention to name your implementation as the definition, preceded by Z_
. The system will present a default implementation class, but you can simply fill in the class name of your copied implementation class. Activate and GO !
Now with your BAdi implementation alive and well, you can set break-points in the class methods and try out whether the setup is working and what you can do in the methods.