BADI Implementation Example
BADI Implementation Example
The following simple steps will allow you to find all BADI's that are called when
you execute a specific SAP transaction code. Once you have found the BADI
name you can view its full details and implement it via SAP transaction SE18.
If you only have the BADI name the last section will also help you find where
the BADI is triggered from.
Another way to find which BADI's are executed from a specific transaction is to place a
break-point within method 'GET_INSTANCE' of class 'CL_EXITHANDLER'. To do this use
the following steps
7. To find more in this transaction simply press the execute(F8) button and the break-
point will be triggered again if a second BADI is called, keep doing this until all have
been found.
This is not an exact science but may help you locate where a BADI is triggered from
1. Execute the BADI transaction SE18, enter BADI name and press display
2. Within the properties tab you should see the package associated with the BADI (i.e.
SZAD). Simply copy it or remember it.
3. Now go to tcode SE80 and select package as the repository browser object type
4. Enter the package name from the BADI properties (i.e. SZAD)
5. Now expand the transactions node and you will see all the tcodes assiciated with this
package, one of which will probably execute this BADI.
6. Also note all the other objects within this package including programs, includes,
function modules etc as well as a full list of other classic BADi's and enhancement
spots.
he use of object orientated code within SAP has lead to a new method of
enhancing standard SAP code called a Business Add-In or BADI for short.
Although the implementation concept is based on classes, methods and
inheritance you don't really need to understand this fully to implement a BADI.
If you need to, simply think of methods as a function modules with the same
import and export parameters and follow the simple instructions below.
Steps:
2. Enter BADI name i.e. HRPBSGB_HESA_NISR and press the display button.
Also see here for how to find an SAP BADI
Note the type attributes of this BADI as it is not a multiple use badi and has no
filter option. I will go into what this means later in the multiple use badi section
5. You can now implement any ABAP code changes you require within this BADI
implementation. For example choose the Interface tab to see the list of
available methods you can add your code into.
6. Before we go any further press the save button and assign your new
implementation to a transaport or create it as a local object.
7. Double click on the method you want to change (i.e. CONTRACT). You can
now enter your ABAP code as required.
8. Please note to view the Methods import and export parameters simply select
the menu option Goto->Method Definition.
The method definition will then be displayed
You could also return to the original BADI definition screen (i.e.
HRPBSGB_HESA_NISR) and double click on the method name from there.
9. Once you are familiar with the parameters available you can add your own
custom ABAP code. For this example we are going to update changing
parameter p_contract based on importing parameter p_pernr
10. Save and activate the method
11. Then return to the main implementation screen and save and activate the
overall implementation
12. Remember, as mentioned earlier this is not a multiple use BADI? This
basically just means that you can only have one implementation active at any
one time. For example if you now create a new implementation called somthing
like Z_HRPBSGB_HESA_NISR2.
Then try activating this, you would get the error message that there are
implementations already active.
Ignore the fact that it says active at the top of the screen. If you back out to
the main definition screen and then choose change implementation
Additional Info
If you have used a different method that has filter options, when you save you
might get an error message saying 'Specify filter values'. To do this simply go to
the properties tab and click on the dropdown menu options for filter values at
the bottom and select the entry approriate to you.
A BADI that has the multiple use checkbox ticked simply means that you can
not only create multiple instances but also have more than 1 of them active at
the same time. This is unlike a standard BADI without the multiple use option
ticked, which can only have one implementation active at any one time.
There is however one caveat to multiple use badi’s, although you can have
multiple implementations you can’t specify which order these will be fired in.
Therefore, each implementation needs to be coded as a separate entity and
must not rely on a specific execution sequence or another one being completed
first i.e. you could not have one performing some checks and another updating
a database based on these checks.
To be honest I can’t think of an instance where this would cause you too much
of a problem. Why would you need to split connected coding across two
implementations? If you have come across a requirement to do this, please add
it to the comments section below as there could be ways around this limitation
if required!
There may be instances if you have a multi-national company, but filter values
might help with this. I will cover this in more detail at the end of this article.
One final point about Multiple use BADI’s, is that they can only have
IMPORTING and CHANGING parameters.
Well Implementing a multiple use badi is much the same as implementing a none-
multiuse BADI so see that article for full step by step details...
You basically execute Business Add-In(BADI) transaction SE18, choose the BAdI option,
enter a multiple use BADI name ( i.e. ADDRESS_UPDATE ) and press display. Also if
you want to know which badi is executed within a particular transaction see here for
how to find where a BADI is triggered
Note this BADI has the multiple use badi checkbox ticked
Now follow the usual classic BADI implementation steps i.e. select menu option
Implementation->Create
On the next screen enter some implementation short text and press save
Etc etc...until you you have added your desired ABAP code into BADI methods ( within
the interface tab) and then activated the implementation.
A BADI that has the filter-depend checkbo x option ticked simply means that
you can activate multiple BADI implementations at the same time based on this
filter value. Without the filter value, a classic BADI can only have one
implementation active at any one time.
A filter option means that you can implement a filter type of say country and
then create implementations based on different values for country i.e. if you are
a multinational organisation.
One thing I would just like to add before going any further. If you are
maintaining two BADI's with filters via transaction SE18 make sure you leave
the transaction fully when switching between the different BADI's. If I only
returned to the main selection screen of SE18 before selecting the second I
have often seen filter values from one BADI appearing in the second BADI.
Leave the transaction all together before maintaining the second BADI.
Implementing a filter BADI
Well Implementing a badi with the filter-depend check box selected is much the same
as implementing a classic BADI so check out that article for full step by step details...
As you can see this BADI has the filter-depend option check box checked. Also note the
filter type, which for NOTIF_EVENT_SAVE is Notification Type. If you wanted to create
your own BADI you could choose the filter type you required. For example, check out
BADI ADDRESS_CHECK which has a filter value of "Country ISO code"
Implementing a BADI with a filter is much the same as implementing one without a
filter, see below for basic steps. Also, see implementing a classic BADI for more detailed
steps.
1. As with a classic badi without a filter the first step is much the same, you select the
menu option Implementation->Create
then give the implementation a name such as Z_NOTIF_EVENT_SAVE
2. On the next screen enter some implementation short text and press save
It's at this point you will see the first difference, as when you save you will see the
error "Specify filter value"
Press Enter to remove the message, then simply select a filter value by first selecting
the insert row option
Then by selecting a value for the row using the Search Help / F4 Value help. Note you
can add more than one value here, but must not be the same values as assigned to
another implementation. I will cover this in more detail in a second.
Once you have selected your values ( i.e. 11 and 50) you can press the save icon to
save this implementation
If you have chosen values contained in another implemantation of this BADI you will
see the message "There are already implementation active for these filter values"
The values I have chosen are not already used and just saved it as a local object for
this example
3. From this point on it is much the same as implementing a classic BADI i.e. you can
go to the Interface tab and select a method you want to enhance by double clicking on
it.
Then you just need to enter your desired ABAP code into the method.
4. But don't forget about the filter value as this actually becomes one of the importing
parameters of the method. To see this simply choose menu option Goto->Method
Definition from within the method.
You will then see the list of method parameters. For this example, the filter value
parameter is FLT_VAL which you can confirm by looking at the parameter type and
comparing to the filter type.
If multiple values are used you can then incorporate this filter value into your ABAP
code something like this, i.e. by checking the filter value and performing the
appropriate ABAP processing.
5. Once your done Save and activate the method and then the BADI implementation
6. As this BADI has a filter enabled you can now create a second, third, four etc
implementation. But they need to be based on different filter values.
Enter some short text and then enter one of the same filter values as the first one i.e.
11. You will now see the message "There are already implementations active for these
filter values".
This just demonstrates that although you can use the filter to activate multiple
implementations of the same BADI you must assign each one a different filter value.
For example, now change the value to something else like 52 or a value not already
used. This time when you press the activate button it should activate fine.
any classic BADI's have now been migrated to the new enhancement framework
and are now implemented via an enhancement spot, this includes standard
BADI's and Multiple use BADI's.
You basically execute Business Add-In(BADI) transaction SE18, choose the BAdI option,
enter a migrated BADI name ( i.e. BADI_MM_MATNR ) and press display. Also if you
want to know which badi is executed within a particular transaction see here for how
to find a BADI
It is simple to see if a BADI has been migrated as it is displayed within the type
properties. For example within the properties of the BADI_MM_MATNR BADI it shows
that it has been migrated to an enhancement spot with the same name
BADI_MM_MATNR. Therefor implementing this BADI actually uses the enhancement
framework and implements via an Explicit enhancement spot. Note this BADI is also a
multiple use badi but this does not effect how it is implemented just means you
can have more than one BADI implementation active.
This only changes a number of the steps slightly from a that of a classic BADI. See
below for steps required to implement this enhancement spot based SAP BADI.
1. The first step is much the same you select menu option Implementation->Create
2.On the next screen enter some implementation short text and press save
4.Simply press OK, then on the next screen you will need to create a new enhancement
implementation or select an existing one. For this example I will create a new one so
press the create button
Give the enhancement implementation a name and description. Then press the ok tick
and assign your implementation to a transport or create as a local object.
Your new implementation should now be available, select it and press the ok green tick
icon
5. From this point on it is much the same as implementing a classic BADI i.e. you can
go to the Interface tab and select a method you want to enhance by double clicking on
it.
6. Once your done Save and activate the method and then the BADI implementation
7. As this is a multi use BADI you can now create a second, third, four etc
implementation and activate them without any problem. But remember they will not be
executed in any particular sequence and could be a different sequence each time. You
can also create each implementation within the same enhancement implementation you
just created.