Concepts and Working with BADI.doc

31
Concepts and Working with BADI Added by Aveek Ghose , last edited by Craig Cmehil on Aug 05, 2009 (view change ) Labels: abap , badi , filter Add Labels Enter labels to add to this page: Tip: Looking for a label? Just start typing. 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 Applies to: Summary Author(s): Aveek Ghose

description

Concepts and Working with BADI.doc

Transcript of Concepts and Working with BADI.doc

Page 1: Concepts and Working with BADI.doc

Concepts and Working with BADI

Added by Aveek Ghose , last edited by Craig Cmehil on Aug 05, 2009  (view change) Labels: abap, badi, filter

Add LabelsEnter labels to add to this page:

Tip: Looking for a label? Just start typing.

Applies to:

 SAP technology / Netweaver / ABAP Development.

SummaryOverview 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 IndiaCreated on:   04/07/2009Author(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

Applies to: Summary Author(s):   Aveek Ghose

Overview - What is a BADI?   Overview - Features of BADI BADI vs. User Exit BADI Definition

Page 2: Concepts and Working with BADI.doc

BADI Definition - Attributes BADI Definition - Interface BADI Definition - Interface Methods BADI Definition - Interface Methods - Parameters BADI Definition - Exceptions BADI Implementation BADI Implementation - Interface Filter dependent BADI Filter dependent BADI - How it works?   Filter dependent BADI - Implementation       Finding a BADI - Transaction VD02 Finding a BADI - Transaction LBK1 Steps to create an Implementation for an SAP provided BADI BADI - some useful information Example |

Related Content

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 BADIUses 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 ExitIn User Exits, an application programmer predefines exit points in a source that allow

Page 3: Concepts and Working with BADI.doc

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

Page 4: Concepts and Working with BADI.doc

 

Page 5: Concepts and Working with BADI.doc

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

Page 6: Concepts and Working with BADI.doc

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

Page 7: Concepts and Working with BADI.doc

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

Page 8: Concepts and Working with BADI.doc

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

Page 9: Concepts and Working with BADI.doc

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             

Page 10: Concepts and Working with BADI.doc

BADI Definition - Exceptions

Page 11: Concepts and Working with BADI.doc

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

BADI ImplementationTo create an implementation, choose ABAP Workbench -> Utilities -> Business Add-Ins

from the SAP menu Transaction - SE19 SE19

Enter Implementation nameClick on createEnter the BADIDefinition name

BADI Implementation - Interface

Page 12: Concepts and Working with BADI.doc

 Double click onthe method to modifymethod code

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

Page 13: Concepts and Working with BADI.doc

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

Modify the methodcode within the METHOD/ENDMETHODstatements and activate  

Page 14: Concepts and Working with BADI.doc

Filter dependent BADIIf 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?

Page 15: Concepts and Working with BADI.doc

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

Page 16: Concepts and Working with BADI.doc

 * 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-

Page 17: Concepts and Working with BADI.doc

>method          exporting             flt_val = flt.          Changing             parameter = word.

....

....

   Finding a BADI - Transaction VD02

Page 18: Concepts and Working with BADI.doc

 * 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   

Page 19: Concepts and Working with BADI.doc
Page 20: Concepts and Working with BADI.doc

Double click on the method to enter the source code

Page 21: Concepts and Working with BADI.doc
Page 22: Concepts and Working with BADI.doc

BADI being usedIf 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 nameInterface 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 :

Page 23: Concepts and Working with BADI.doc

width=32,height=32!

Page 24: Concepts and Working with BADI.doc

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

Page 25: Concepts and Working with BADI.doc

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.

Page 26: Concepts and Working with BADI.doc
Page 27: Concepts and Working with BADI.doc

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

Page 28: Concepts and Working with BADI.doc

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 ContentPlease include at least three references to SDN documents or web pages.

www.help.sap.com

www.sdn.sap.com

www.service.sap.com