Skip to Content

Author: Abyson Joseph Chavara 

Created on : 26.09.2013

The BADI(Business Add-in’s) is an object-oriented enhancement option. The BADI defines an interface that can be implemented by BADI-implementations that are transport objects of their own. The new BADI or Kernel BADI is fully integrated into the Enhancement Framework. Within the Enhancement Framework a BADI is an enhancement option or an anchor point for an object plug-in.

Kernel BAdI’s Features

  • Are integrated directly in the ABAP Language/Runtime
  • Improved filter support allows non-character filter types and complex filter conditions
  • Enable reusable implementation instances (Stateful BAdI)
  • Control of the lifetime of implementations (BAdI-context)
  • Allow for inheritance of implementations
  • Can be switched by the Switch Framework

In this document, I have demonstrated the various steps for creating a Kernel BADI and calling it in our own Custom program.

1. First  create a  Enhancement spot from SE18. Kernel Badi’s belong to an enhancement spot.

Enhancement spots carry information about the positions at which enhancement options were created. One enhancement spot can manage several enhancement options of a Repository object. Conversely, several enhancement spots can be assigned to one enhancement option.

Enter the description and if you want you can assign the new enhancement spot to a composite enhancement spot. Composite enhancement spots are used for the semantic grouping of simple enhancement spots. A composite enhancement spot contains either one or more simple enhancement spots and/or one or more composite enhancement spots of the relevant type. You can use composite enhancement spots to combine simple enhancement spots into meaningful units.

2. On creating the Enhancement spot, you will be directed to Enhancement Spot Editor. Now we need to create a new BADI Definition.

3. Click on the create BADI button.

4. You will find certain options for the BADI definitions as below.


Usability – Multiple use – that is, there can be several active implementations

Limited Filter Use – This makes the BADI Filter-dependent – that is, you apply a filter value to each method called (for example, a country). A different (active) implementation is then called for each value. Possible filter values are characterized by the filter type.



Instance Generation Mode – This property controls the instantiation of the object plug-ins during execution of the statement GET BADI.

The first two specifications define context-free BAdIs.

Newly Created Instantiation – New object plug-ins are created at each execution of the statement GET BADI.

Reusing Instantiation – An object plug-in that was used once in the current internal mode is reused, if it is required more than once.

Context-Dependent Instantiation – A context must be specified for GET BADI. This context controls the instantiation. Only one object plug-in is created for each context and implementing class. Each time there is another GET BADI with the same context, it is reused. A context is an instance of a class that implements the tag interface if_badi_context. The specification takes place in the form of a reference to such an instance.



Fallback Class – Fallback class for a BADI is used if there is no active BADI implementation. This means: The GET BADI command returns a handle to an instance of the fallback class and the respective CALL BADI calls the methods of the fallback class instance. As soon as there is an active BADI implementation, the fallback class is not used any longer at runtime.


5. Now we need to add an interface to the BADI. Expand the Node of BADI definition name and double click on node Interface. You can either add existing interface or will be prompted to create.

6. On clicking ‘Yes’, you will be navigated to the below screen, where you can add a method to the new interface.

Save, activate and comeback to the BADI definition screen and activate the Enhancement Spot.

7. Next we need to implement the Enhancement spot and BADI. Right click on the BADI definition and select Create BADI Implementation.

8. First the system will ask for enhancement implementation name. Please enter a name and description.

9. Next it will ask for BADI Implementation name and Class name for implementing BADI. Enter the names and click ok.

10. Next we have to implement the interface method. Expand the BADI Definition name and double click on BADI implementation.

11. You will be directed to the enhancement implementation screen, shown below. Double click on the Interface method and you will be prompted to create implementation for the method.

12. On clicking yes, you will be navigated to editor for the method. Add the following code for showing a message or anything as per your requirement. Save it and activate.

So the BADI definition and implementation part is complete.

Next we will see how we can call this Kernel BADI in our Custom program.

13. Create or open an existing program in SE38. Point to the line where you need to add enhancement option. Right click and select Create Option.


(Please note, to call a Kernel BADI in a Custom program we don’t need any enhancement options, as we can just write the code anywhere. Just meant to show reader the creation of enh option and a point in  a program.  While creating an option either you could use an existing enh spot imp or can create a new one there. Rather than explaining the topic in an atmosphere of real business scenario, I focused on giving the reader an understanding in the concepts.)

14. Give an Enhancement point or section name and Enhancement spot implementation name. Here I have opted an Enhancement point and have entered Enhancement spot implementation name as ‘ZENH_IMP_TEST’ (which we have created before).

A new line will be added to the existing code as shown below.

15. Then add the below code which is shown in the red box below.

Apart from Classic BADI’s which are been called by Proxy class cl_exithandler, Kernel BADI’s are called directly with the reference to the BADI definition via GET BADI and CALL BADI statements.  That is one of the reasons why Kernel BADI is faster than classic BADI. Also in Classic BADI, while we call it via cl_exithandler,  we use the reference to the interface rather than BADI definition

16. Now activate the program and execute it. When the cursor reaches the enhancement point, where the BADI is called it will trigger all the active implementations of that BADI. Here we have only one implementation and that will be triggered, which shows the below message as we have written in the BADI implementation.

If the program fails to trigger the BADI implementation, please recheck whether everything associated with it is ‘Activated’ after the creation.

Thank You.

To report this post you need to login first.

14 Comments

You must be Logged on to comment or reply to a post.

  1. Sameej T.K.

    Very informative blog. Just one question though – I didn’t understand why did you assign an enhancement spot implementation to the enhancement point in step 14. Enhancement points can be used to plug-in source code at the position in the future state and directly assigning an implementation doesn’t make much sense.

    14. Give an Enhancement point or section name and Enhancement spot implementation name. Here I have opted an Enhancement point and have entered Enhancement spot implementation name as ‘ZENH_IMP_TEST’ (which we have created before).

    (0) 
    1. Abyson Joseph Post author

      To call a Kernel BADI in a custom program we don’t need any enhancement options, as we can just write the code anywhere. Just meant to show reader the creation of enh option and a point in  a program.  While creating an option either you could use an existing enh spot imp or can create a new one there. Rather than explaining the topic in an atmosphere of real business scenario, I focused on giving the reader an understanding in the concepts.

      (0) 
  2. abilash n

    Hi Abyson,

    can you please tell me what is the diff between kernel badi and normal badi implementation. As you have implemented in normal way.

    I know that kernel badi is faster than normal classical badi. but i never understood the kernel badi. if you dont mind can you please reply to this or create new blog on kernel badi,,,,

    (0) 
      1. abilash n

        Thanks Abyson for sharing the blog. Now i got some good idea on it. If possible please share some more info on the kernel and classic badi.

        Another question – As there are limitations in customer exit so sap came up with badi’s previously. And what made sap to move to new badis even after classic badis(apart from fast).

        Thanks for your feedback.

        (0) 
  3. Sri Lakshmi Naidu

    Hi All,

    I may sound too layman,but i wanted to know. why a custome program needs a enhancement spot?

    can we not implement directly in the custom program.for me this seems a overdo.

    Experts,please clarify my doubts.

    Thanks & Regards,

    Lakshmi

    (0) 
    1. Abyson Joseph Post author

      Hi Sri Lakshmi Naidu

      Your doubt doesn’t sound too layman. We don’t need an enhancement spot in custom program. But I have explained it already above, why i have added the spot in the demo custom program. Untitled.jpg

      Thanks and Regards,

      (0) 
      1. Matthew Billingham

        Custom BADIs are useful in CMOD and other old-style user exits, to keep implementations separate, and to use the new technology in “old” places. They’re also useful if you are, for example, building a template system that is rolled out globally, but allows local enhancements.

        (0) 

Leave a Reply