WhatsApp Button




top of page

Mastering SAP Enhancements: Business Add-Ins (BAdIs)

ree

In the world of SAP, adapting standard functionalities to meet unique business requirements is a common challenge. While various enhancement techniques exist, Business Add-Ins (BAdIs) stand out as a powerful and flexible solution. But what exactly are BAdIs, and how do they differ from other enhancement options like user exits or modifications? 

This post will demystify BAdIs, exploring their object-oriented nature, different types, and practical implementation, including how to find and activate them. 

 

What Exactly is a BAdI? 

A BAdI is an enhancement technique in SAP that allows you to extend standard SAP code without modifying the original core system. This is crucial for maintaining system integrity and simplifying upgrades. When you enhance SAP functionalities using BAdIs, your custom code resides in the customer namespace (typically starting with Y or Z). 


ree

 

BAdIs vs. Other SAP Enhancement Techniques 

So, what makes BAdIs unique compared to implicit enhancements, explicit enhancements, customer exits, user exits, or even direct modifications? The key differentiator lies in their foundation: 

  • Object-Oriented Programming (OOP): BAdIs are built upon OOP concepts, primarily interfaces and classes. This provides a structured, modular, and reusable approach to enhancements, unlike older, more procedural methods. 

  • Dedicated Transaction Codes: 

    • SE18 is used for BAdI definition. Think of it as defining the interface where SAP provides a hook for your custom logic. 

    • SE19 is for BAdI implementation. This is where you write your actual ABAP code within a class that implements the BAdI interface. 

 

The Two Flavors of BAdIs: Classic vs. Kernel 

SAP offers two main types of BAdIs: 

  1. Classic BAdIs: These are the original BAdIs, widely used for many years. 

  2. Kernel BAdIs (New BAdIs): Introduced later, these offer more advanced features and improved performance. This blog will focus on Classic BAdIs for practical demonstration. 

 

Practical Example: Restricting Unit of Measure (UOM) in MM01 


Let's illustrate how to use a Classic BAdI with a common business requirement: preventing users from entering "KG" as the Unit of Measure (UOM) when creating a material in transaction MM01

Currently, if you go to MM01, select "Pharmaceuticals" as the industry sector and "Raw Materials" as the material type, then enter "KG" for the UOM and save, the system allows it. Our goal is to prevent this. 

 

Let’s see this in action 

  1. Navigate to MM01

    MM01 on SAP Server
  2. Select "Pharmaceuticals" as the industry sector and "Raw Materials" as the material type and press Enter


    Initial screen for creating material in SAP

     

  3. Select the View as Basic Data1 and Basic Data2 and click on Continue  

    Selection of views while creating material in SAP
  4. Give the description and UOM as KG and click on the save button.  

    Entering material details such as description and base unit of measure
  5. You will see our material is getting saved.  

    Confirmation message for material successfully created

 

 

Now let’s use classic BAdI and enhance the standard SAP to prevent saving the data if the Basic Unit of measure is KG. 

These are the 3 tasks we perform 

  1. Finding a Classic BAdI 

  2. Implementing the Classic BAdI 

  3. Cleaning Up Your Implementation (optional) 

 

Finding a Classic BAdI 

Before implementing, we need to find the right BAdI. Here are the common methods: 

1. Using CL_EXITHANDLER=>GET_INSTANCE (Recommended for ABAPers) 

This is the preferred method for technical users because it allows for debugging, which is invaluable for understanding the flow and identifying suitable BAdIs. 

  • Go to transaction SE24 and display class CL_EXITHANDLER. 

    SE24: Enter object type CL_EXITHANDLER to explore the class details.
  • Double-click on the GET_INSTANCE method. 

    Methods tab of class CL_EXITHANDLER showing the available static methods, including GET_INSTANCE
  • Go to MM01, enter the material data, and before saving, in the other window set a breakpoint at sy-subrc condition within the GET_INSTANCE method. 

    ABAP code calling method GET_CLASS_NAME_BY_INTERFACE of CL_EXITHANDLER with parameters
  • Back in MM01, when you press "Save" the debugger will stop at this breakpoint, and you'll see BAdI names populate in the exit_name variable one by one. 

    Debugging screen showing EXIT_NAME value
  • Check each BAdI in SE18 to see if its purpose aligns with your requirement. For our UOM validation, BADI_MATERIAL_CHECK (Enhanced checks for material master tables) is ideal, as it has an interface method CHECK_DATA where we can inspect the UOM.  

    SE18 screen with BAdI name
SAP BADI_MATERIAL_CHECK definition screen showing enhanced checks for material master tables

SAP BADI_MATERIAL_CHECK interface screen showing IF_EX_BADI_MATERIAL_CHECK with methods like CHECK_DATA

 

2. Searching by Package Name in SE18 

  • Go to MM01 and find the program's package name (System > Status > Program > Attributes). For MM01, the package is typically MGA

    SAP GUI System menu opened showing options including Status highlighted

ree
  • In SE18, use F4 help on the BAdI name field and choose new selection. 

    SAP BADI selection screen with options for Enhancement Spot and BAdI Name
    SAP BADI list selection screen with highlighted New Selection button
  • Select "Classic BAdIs" and enter "MGA" as the package name. This will list all Classic BAdIs within that package. You'll then need to manually check each one in SE18 to find the relevant BAdI. 

    SAP Repository Info System Find BADIs screen with Classic BADIs option and package MGA selected
    SAP Repository Info System results showing list of BADIs with names and descriptions

3. Searching by Package Name in SE84 

  • Go to transaction SE84

    SAP command field with transaction code SE84 entered
  • Navigate to Enhancement > Business Add-Ins > Definitions

    SAP menu showing Enhancements folder with Business Add-Ins and options for Definitions and Implementations
  • Select "Classic BAdIs" and provide the package name (MGA). This yields the same results as searching in SE18, requiring manual checks. 

    SAP Repository Information System screen with Classic BADIs option selected and package MGA entered
    SAP Repository Info System displaying BADIs list with names and descriptions such as BADI_MATERIAL_CHECK

While the second and third methods provide a list, the CL_EXITHANDLER=>GET_INSTANCE method with debugging is generally more efficient for pinpointing the exact BAdI you need. 

 

Implementing the Classic BAdI (BADI_MATERIAL_CHECK) 

Once you've identified BADI_MATERIAL_CHECK as the suitable BAdI: 

  • Go to transaction SE19 to create an implementation. 

    SAP command field with transaction code SE19 entered
  • Select "Classic BAdI" and enter BADI_MATERIAL_CHECK. Click "Create". 

    SAP SE19 Create Implementation screen with Classic BAdI BADI_MATERIAL_CHECK selected
  • Give your implementation a name (e.g., Z_UOM_CHECK_BADI_IMP – remember the Z prefix for customer namespace). 

    Creating a BAdI implementation in the Implementation Builder
  • Provide a description. You'll notice that the class name (e.g., ZCL_IM_BADI_IMP_UOM_CHECK) is automatically generated. This is a key feature of Classic BAdI implementation.

    BAdI implementation details showing interface and available methods
  • Double-click on the generated class name. Confirm saving it as a local object. 

    Confirmation prompt to save the BAdI implementation changes
  • Activate the class. 

  • Double-click on the CHECK_DATA method within the class. 

    List of interface methods available in the implementing class of the BAdI
  • Inside the CHECK_DATA method, you'll find importing parameters, including a structure like WMARA which contains the UOM in the MEINS field. Write your ABAP logic here to check if WMARA-MEINS is 'KG'. If it is, raise an error message. ABAP IF im_wmara-meins = 'KG'.   MESSAGE 'Unit of measure KG is not allowed!' TYPE 'E'. ENDIF.  

    Sample implementation of the CHECK_DATA method in the BAdI
    SAP Message Maintenance (SE91) where a custom message class is defined
  • Save and activate the method. 

  • Crucially, activate the BAdI implementation itself in SE19. 

Now, if you try to create a material in MM01 with UOM as "KG" and save, you will receive your custom error message! If you use a different UOM, the material will save successfully. 

Material creation screen in SAP(MM01)
Selection of views in material master creation
Entering material details such as description and base unit of measure.
Error message in SAP stating 'Unit of Measure KG not Allowed' during material creation

 

 

Cleaning Up Your Implementation 

For practice or when an enhancement is no longer needed, it's good practice to deactivate or delete your BAdI implementation: 

  • Go to SE19, enter your BAdI implementation name, and click "Change". You can deactivate it from here. 

    Screenshot of SAP BAdI Builder initial screen showing implementation ZBADI_IMP_UOM_CHECK for unit of measure validation
    SAP Business Add-In Builder showing implementation ZBADI_IMP_UOM_CHECK with definition name BADI_MATERIAL_CHECK
  • For complete removal, delete the generated class in SE24 (e.g., ZCL_IM_BADI_IMP_UOM_CHECK) and then delete the BAdI implementation in SE19

    SAP Class Builder initial screen with object type for UOM Validation
    Confirmation message in SAP
    Screenshot of SAP BAdI Builder initial screen with classic BAdI implementation selected
    onfirmation message in SAP showing BAdI implementation has been deleted

 


Understanding BAdI Properties: SAP Internal, Multiple Use, and Filter-Dependent 

When defining or examining BAdIs in SE18, you'll encounter several checkboxes that determine their behavior: 

  • SAP Internal: If checked, this BAdI is reserved for SAP's internal use and cannot be implemented by customers. 

  • Multiple Use: 

  • If ticked, you can create and activate multiple implementations for the same BAdI definition. All active implementations will be executed when the BAdI is called, though the order of execution is not guaranteed. Our BADI_MATERIAL_CHECK was a multiple-use BAdI. 

    SAP BAdI definition with properties for enhanced checks of material master tables
  • If not ticked, only a single active implementation is allowed. 

  • Filter-Dependent BAdI: 

  • If ticked, you can activate multiple BAdI implementations simultaneously based on a specific filter value. Without a filter, a classic BAdI (unless it's "Multiple Use") can only have one active implementation at a time. 

    SAP Business Add-In definition
    ree
  • A filter type (e.g., "Notification Type" for NOTIF_EVENT_SAVE or "Country ISO Code" for BADI_ADDRESS_CHECK) allows you to define different implementations that execute based on a specific data value. This is incredibly useful for multinational companies with varying rules per country or other criteria. 

  • When implementing a filter-dependent BAdI in SE19, you must specify a filter value. If you try to activate without one, you'll get an error. You can add multiple filter values to one implementation, but they must be unique across all active implementations of that BAdI. 

  • The filter value is passed as a parameter into your BAdI method, allowing you to tailor your ABAP logic based on it. 

  • Single-Use BAdIs 

  • A BAdI with neither "Multiple Use" nor "Filter-Dependent" checked is a Single-Use BAdI. This means you can only have one active implementation at any given time.  

  • If you try to activate a second implementation, the system will prevent it, indicating that another active implementation already exists. 

 

Pro Tip for Filter-Dependent BAdIs 

When working with multiple filter-dependent BAdIs or switching between BAdI definitions in SE18 or SE19, always exit the transaction completely (e.g., by typing /n in the command field) before opening the next BAdI. This helps prevent filter values from one BAdI from incorrectly appearing in another. 

 

Conclusion 

BAdIs are a cornerstone of effective SAP enhancement, offering a robust, object-oriented approach to customizing standard functionalities. Understanding their types, how to find them, and their implementation nuances, especially the critical properties like "Multiple Use" and "Filter-Dependent," empowers you to build flexible and maintainable solutions. By embracing BAdIs, you can extend SAP's capabilities precisely to meet your business needs while keeping your system future-proof. 


Use full Links -


ree


Chandini Sirigirisetti

SAP ABAP Consultant



SAP ABAP

Comments


bottom of page