Skip to end of metadata
Go to start of metadata

Applies to:

 SAP technology / Netweaver / ABAP Development.

Summary

  • Overview
  • Difference between BADI & User Exits.
  • BADI Definition
  • BADI Implementation
  • Filter Dependent BADI
  • Finding BADIs in a transaction or program
  • Steps to create an Implementation for an SAP provided BADI
  • BADI - some useful information
  • General naming conventions for BADI

Author(s):  Aveek Ghose

   
Company:     Accenture India
Created on:   04/07/2009
Author(s) Bio
 

Aveek has more than 14 years experience in software analysis and design and custom development both in India and abroad. Aveek has acquired an MS in Economics, Mathematics, Statistics from Virginia Tech in USA and an MS in Information systems from George Mason University in USA. He has handled software projects U.S., Holland, UK, Switzerland, Japan and India. Aveek was a core member of the Warehouse Management system team in the University of Michigan in Ann-Arbor,Michigan,USA.

Table of Contents

Overview - What is a BADI?

Business Add-Ins are a new SAP enhancement technique based on ABAP Objects

They can be inserted into the SAP System to accommodate user requirements too specific to be included in the standard delivery

Business Add-Ins should be considered generalized Business Transaction Events that can be used to bundle program, menu and screen enhancements into a single add-in

Each Business Add-In has:

  • at least one Business Add-In definition
  • a Business Add-In interface
  • a Business Add-In class that implements the interface

  Overview - Features of BADI

  • Uses Object oriented approach
  • Two parts - Definition and its Implementation - definition can either be SAP provided or user may also create it
  • No longer assumes a two-system infrastructure (SAP and customers)
  • Allows multiple levels of software development (by SAP, partners, and customers, and as country versions, industry solutions, and the like)
  • Can have multiple representations - specific one will be executed based on some criteria (filter)
  • Release upgrades do not affect enhancement calls from within the standard software nor do they affect the validity of call interfaces
  • No SSCR (SAP Software Change Registration) required

BADI vs. User Exit

  • In User Exits, an application programmer predefines exit points in a source that allow specific industry sectors, partners, and customers to attach additional software to standard SAP source code without having to modify the original object.
  • The users of Business Add-Ins can customize the logic they need or use a standard logic if one is available. They can be inserted into the SAP System to accommodate user requirements too specific to be included in the standard delivery.

BADI Definition

  • To define a BADI use Sap Menu -> Tools -> ABAP Workbench -> Utilities -> Business Ad-Ins -> Definition
  • Transaction - SE18

BADI Definition - Attributes


 

  • When a BADI is created, BADI class gets automatically created with the suffix 'CL_EX_' after the first character of the BADI name
  • Multiple use : With this option you can have multiple implementations for the same BADI
  • Filter-Dependent : Discussed later in detail

BADI Definition - Interface


* An interface is created automatically with the suffix 'IF_EX_' after the first character of the BADI name

  • When you double click the interface, you will be taken into the class builder where you can define the methods, parameters and exceptions for that interface

BADI Definition - Interface Methods

  • Specify the methods in the Class Builder for the interface
  • Instance methods can access all of the attributes of a class, and can trigger all of the events of the class
  • Static methods can only access static attributes and trigger static events
  • Click on the Parameters button to specify any Import/Export parameters for the method     

BADI Definition - Interface Methods - Parameters

  • The Import/Export parameters for the method are specified in the 'Parameters' section
  • The type specifies whether the parameter is an Importing, Exporting, Changing or Returning parameter
  • Check the Optional field if it is not a mandatory parameter
  • The type, default value and description of the parameter can be specified             

BADI Definition - Exceptions

  • You can specify any exceptions in the Exceptions section
  • For class based exceptions, check the checkbox 'Exception Classes'

BADI Implementation

  • To create an implementation, choose ABAP Workbench -> Utilities -> Business Add-Ins from the SAP menu
  • Transaction - SE19 SE19

Enter Implementation name
Click on create
Enter the BADI
Definition name

BADI Implementation - Interface

 Double click on
the method to modify
method code


During implementation creation, a class for implementing the enhancement's interface is also created

  • Navigate to the Class Builder by double-clicking the methodBADI Implementation - Method modification


Modify the method
code within the METHOD/ENDMETHOD
statements and activate
  

Filter dependent BADI

  • If enhancement needs to be different based on some parameter (e.g. country-specific or company-code specific), separate implementation of the same Add-In can be created and activated.
  • At run time, the specific implementation will be executed
  • Possible through filter dependent BADI
  • What qualifies as a filter?
  • A Data element
  • Underlying domain may contain a maximum of 30 characters and must be of Character type
  • The data element must
  • Either have a search help with a search help parameter of the same type as the data element and this parameter must serve as both the import and export parameter or
  • the element's domain must have fixed domain values or a value table containing a column with the same type as the data element


Filter dependent BADI - How it works?


  • Switch on Filter-dependency while defining the interface
  • Select a suitable filter element
  • All methods created in the interface will have filter 'FLT_VAL' as one import parameter
  • Application program provides the filter value to the enhancement method
  • The method then selects the active implementation for that value                                                                                                             

 Filter dependent BADI - Implementation

 * Implement the Add-In for each relevant filter value

  • However, multiple filter values may use the same implementation
  • Enter a characteristic filter value for the implementation
  • Pass the filter value as export parameter to the method

....
.... call method exit->method
         exporting
            flt_val = flt.
         Changing
            parameter = word.

....
....


   Finding a BADI - Transaction VD02

 * Transaction - VD02 Change Customer Master

  • Click on System->Status   Double click on the program name


              Once inside the program

  • search for 'CL_EXITHANDLER'. Make sure the radio button - In main program is checked  A list of all the programs with call to the BADIs will be listed 
     

Double click on the method to enter the source code

BADI being used
If the BADI name is not specified in the CL_EXITHANDLER=>GET_INSTANCE method call, you can find out the BADI name by removing the prefix IF_EX_ from the interface name
Interface reference variable defined
 

Finding a BADI - Transaction LBK1

 * Transaction - LBK1 Logbook

  • The exclusivity about this transaction is that the BADIs are triggered at the sub-screen level and not at the main program level  
  • Execute the transaction by creating a logbook for a functional location
  • Go to Logbook - Create - Func. Loc. Logbook
  • Check for BADIs here with the same procedure as mentioned for the VD02 Transaction. Click on System->Status     * There are 3 programs mentioned - Program (screen), Program (sub screen) & Program (GUI).
  • Click on each of them to find out the respective BADIs (with the same procedure as for transaction VD02)
  • Outcome :

width=32,height=32!

o        No BADI for screen program

o        BADI Definition - GUI_APPL_OBJ_OHFW for sub screen and GUI program as they are the same.  * PS : Remove IF_EX from if_ex_gui_appl_obj_ohfw to get the BADI name

  • Also note that not necessarily the sub screen & GUI Program are the same. * Execute the transaction further by substituting a functional location and pressing 'Create log entry'

           
* Again Go to System - Status and look for the programs


  • Program (screen) - SAPLDIOHFW_GUI
  • Program (sub screen) - SAPLZDIACL_LOG_GRP
  • Program (GUI) - SAPLDIACL_GUI_LGE
  • Again find out the respective BADIs

  • Screen program has no BADI
  • Sub screen program has 2 BADIs - LGE_SUBSCR_ACL & GUI_APPL_OBJ_OHFW
  • GUI program search will give 3 hits but all refer to the same BADI definition - LGE_SUBSCR_ACL      
    * If we investigate the LGE_SUBSCR_ACL BADI definition than we will see that it is attached to Sub screens only    * So it is quite possible that BADIs can be located into a Sub screen & GUI program and not only into the Main program of a transaction.
  • Thus, the best possible search for BADIs would be by executing the transaction and looking into its sub screens also.

Steps to create an Implementation for an SAP provided BADI

  • Find the corresponding BADI for the SAP transaction
  • Create a custom Implementation for the BADI
  • From the methods available in the BADI select the appropriate method (based on which method is triggered for a particular processing)
  • Enter custom code in the method and activate
  • Execute SAP transaction and test if method with custom code is being invoked

BADI - some useful information

-          There can be more than one implementations of the same BADI definition, and in that case only the active implementations will be executed

-          You can activate or de-activate any of the implementations after creation

-          Enhancement, interface, and associated classes generated all lie in the appropriate application development namespace

-          Business Add-In implementations lie in the respective namespaces of the people who created them

-          Changes made to the interface and changes made to the Business-Add-In definition are always incompatible

-          If implementations already exist for a Business-Add-In definition, they are invalidated if you make changes to the interface. This means that their syntax is no longer correct. No statements can be given on the runtime behavior. Avoid making changes to the interface or the Business-Add-In definition after the transport has taken place.

-          If changes to the interface are inevitable, navigate to the Class Builder for all implementing classes and clean up the method includes of these classes (Utilities > Clean up > Method includes) General Naming Conventions | Position | Description | Values | Meaning |

1

Custom Indicator

Z

Custom Developed BADI Definition or Implementation

2

Project indicator


*'DM' + Module of the development*

3

Program type

Alphanumeric

_BDF - BADI Definition
_BIM - BADI Implementation

4

Development Id


_DEV ID / _TPR ID

Suffix

Descriptive Text
EG. _LIST_OPEN_INVOICES

*Alphanumeric and '_'*

ABAP function

Example |

o        ZDMSD_BDF_DEV001_LOGBOOK

o        ZDMSD_BIM_DEV001_LOGBOOK

-          A single BADI can have multiple implementations using filters.

-          Eg. GUI_APPL_OBJ_OHFW Badi is implemented at different places in LBK1 Transaction using filters

-          In most cases the sub screen & screen program are the same that's why we can't see the difference. Even GUI Program is the same. 

Related Content

Please include at least three references to SDN documents or web pages.

www.help.sap.com

www.sdn.sap.com

www.service.sap.com

Useful Information

  • Overview
  • Difference between BADI & User Exits.
  • BADI Definition
  • BADI Implementation
  • Filter Dependent BADI
  • Finding BADIs in a transaction or program
  • Steps to create an Implementation for an SAP provided BADI
  • BADI - some useful information
  • General naming conventions for BADI