You are on page 1of 54

BADIs

U V S Varma

Copyright 2006 Deloitte Development LLC. All rights reserved.

Lesson Objectives
After completing this lesson you will be able to : Understand what Business Add Ins (BAdIs) are Define BAdIs Implement BAdIs Use BAdIs Create an implementation for an existing SAP BAdI Create Multiple Use BAdIs Create Filter Dependent BAdI Create Menu Enhancement with BAdI

Copy right 2009

Introduction
Traditional way of doing code modifications Exits 3 Tier Architecture PRESENTATION : Function Exits Screen Exits Menu Exits APPLICATION: Programs -> Program exits -> call customer function > Include DATABASE Table -> SE11 -> Goto -> Append Structure With BAdIs you can make changes only at the Application Layer.
3 Copy right 2009

BAdIs
Business Add-Ins are a new SAP enhancement technique based on ABAP Objects They can be inserted into the SAP system based on specific user requirements 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

Copy right 2009

BAdI Enhancement options


In Business Add-Ins, all the components of an enhancement option are grouped together Program Enhancements: Functional enhancement of the program are defined in the form of interface methods and can be used with or without Menu Enhancements or Screen Enhancements Menu Enhancements: Function codes can be entered for a BAdI for the corresponding menu entries in the user interface definition. Screen Enhancements: Subscreen areas can be entered for a Business Add-In. Screen enhancements can be implemented for these in the form of subscreen screens.

Copy right 2009

BAdIs SAP Delivered vs. Custom Developed


SAP has already created BAdI definitions (created with SE18) and placed references to these throughout the application code. SAP developers create implementations (created with SE19) of these existing BAdIs, entering custom code into the implemented methods It is also possible for developers to create new BAdI definitions, and reference them in their own custom code. You would do this if you wanted to give future users of your application the ability to expand on functionality in a custom development. You would NOT define a new BAdI to place in SAP code! Overview of steps to complete a BAdI. 1. Create BAdI definition with SE18 2. Code a reference to the BAdI in application code where functionality is to be expanded 3. Create an implementation of the BAdI that actually does something.
Copyright 2006 Deloitte Development LLC. All rights reserved.

Defining BAdIs
SE18

Enter BADI name

Click on CREATE

Copyright 2006 Deloitte Development LLC. All rights reserved.

Defining BAdIs Attributes

Enter short text

BADI class is automatically created

Copy right 2009

BADI Definition - Save

Enter Package name

Copy right 2009

Defining BAdIs

Package name populated

BAdI class created

10

Copy right 2009

Defining BAdIs - Interface

BADI Interface is created automatically To edit double click on the interface

11

Copy right 2009

Defining BAdIs Interface methods


Method name Method type

12

Copy right 2009

Defining BAdIs Interface methods - parameters

Import and Export parameters

13

Copy right 2009

Defining BAdIs Exceptions

Exceptions

14

Copy right 2009

BADI Implementation
SE19

Enter Implementation name


Click on create

Enter the BAdI Definition name

Copyright 2006 Deloitte Development LLC. All rights reserved.

15

BAdI Implementation

Double click on the method to modify method code

16

Copy right 2009

Implementing BAdIs: Method implementation

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

17

Copy right 2009

Using a BAdI

18

Copy right 2009

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 and select the appropriate method Enter custom code in the method and activate Execute SAP transaction and test if method with custom code is being invoked

19

Copy right 2009

Finding a BAdI Transaction VD02

Select System->St from the drop down

20

Copy right 2009

Finding a BAdI Transaction VD02

Double click on the program name

21

Copy right 2009

Finding a BAdI Source program

Do a search on CL_EXITHANDL GET_INSTANCE

Copyright 2006 Deloitte Development LLC. All rights reserved.

22

Finding a BAdI Search results

Three BAdIs used in this program. Double click requi BAdI to see the source code

23

Copy right 2009

Finding a BAdI Call to a BAdI in the source code

BAdI being used

Interface reference Variable for the BA

24

Copy right 2009

Finding a BAdI Interface reference to the BAdI

Interface referen Variable defined

25

Copy right 2009

Using an SAP BAdI Create a Custom Implementation


SE19

Enter the implementation name

Click on CREATE

Enter the name of the BAdI

Copyright 2006 Deloitte Development LLC. All rights reserved.

26

BAdI Implementation Attributes

Enter description

27

Copy right 2009

BAdI Implementation Interface methods

Click on the interf tab to view the av methods

Double click on me SAVE_DATA to mo

28

Copy right 2009

BAdI Implementation Class builder

Enter custom code

29

Copy right 2009

BAdIs Execute the Change customer transaction


VD02

Click on SAVE button

Change name of Cust

30

Copy right 2009

BAdI Implementation Invoked by VD02

Custom code for method invoked via BAdI CUSTOMER_ADD_DATA

31

Copy right 2009

Multiple Use BAdIs


Single Use Business Add-Ins
Do NOT select the Multiple use checkbox from the Administration tab when defining a Single Use BAdI BAdI has a single Implementation Similar to procedures Return values can be expected Can use importing, changing and returning parameters N/A

Multiple Use Business Add-Ins


Select the Multiple use checkbox from the Administration tab when creating the BAdI definition BAdI has multiple implementations Similar to event calls Cannot expect return values Can use importing and changing parameters For multiple implementations there is no sequence control because at the time of BAdI definition it does not know which implementation will be active All active implementations will be triggered by the application program using the BAdI

A single implementation will be triggered by the application program

Copyright 2006 Deloitte Development LLC. All rights reserved.

32

Multi Use BAdIs CUSTOMER_ADD_DATA Definition

SAP defined BAdI CUSTOMER_ADD_DATA Multiple use Button checked

33

Copy right 2009

Multi Use BAdIs Custom Implementation for BAdI CUSTOMER_ADD_DATA

Create a second implementa for BAdI CUSTOMER_ADD_ Click on CREATE

Specify BAdI name

Copyright 2006 Deloitte Development LLC. All rights reserved.

34

Multi Use BAdIs Interface method SAVE_DATA

Double click on method SAVE_DATA

35

Copy right 2009

Multi Use BAdIs Modify method SAVE_DATA

Enter custom code for method SAVE_DATA

36

Copy right 2009

Multi Use BAdIs View implementations for BAdI


SE18

Select to display lis Implementations fo CUSTOMER_ADD

Displays list of Implementations

Copyright 2006 Deloitte Development LLC. All rights reserved.

37

Filter Dependent BAdIs


Business Add-Ins can be implemented based on a specific filter value If you want to call the implementation of a Business Add-In depending not only on one filter value but on various values, you can enter the name of a structure into the Filter type field. The structure can consist of several data elements that fulfill the above conditions for data elements

38

Copy right 2009

Filter Dependent BAdIs BAdI Definition


SE18

Click checkbox for Filter Dependent BAdIs Enter Filter type

39

Copy right 2009

Filter Dependent BAdIs BAdI Definition


Enter text Double click on the Interface to add parameters and methods

40

Copy right 2009

Filter Dependent BAdIs Interface - Method Definition

41

Copy right 2009

Filter Dependent BAdIs Interface Parameter Definition

reate parameter to export tax rate

T_VAL parameter preset for method

42

Copy right 2009

Filter Dependent BAdIs Implementation

Create BAdI Implemen

Select CREATE button

Enter name of BAdI

Copyright 2006 Deloitte Development LLC. All rights reserved.

43

Filter Dependent BAdIs BAdI Implementation


SE19

Click on button to create an entry for filter value Select a value from the search help or enter a valid value 44 Copy right 2009

Filter Dependent BAdIs BAdI Implementation

Select the Interface tab Double click on the Method to enter source code

45

Copy right 2009

Filter Dependent BAdIs Method code


Save and activate Enter code for the Method to calculate the tax rate based on the company code in Parameter FLT_VAL

46

Copy right 2009

Filter Dependent BAdIs Source code to Invoke BAdI

Selection screen parameter for Company code Call BADI from within the program

Call method get_bukrs passing the company code The Tax rate is returned

47

Copy right 2009

Menu Enhancement BAdIs Creating a menu enhancement

SE18 Create BADI definition

Fcodes tab is only available when multiple use box is not checked Menu enhancements are for Single Use BAdIs only

48

Copy right 2009

Menu Enhancement BAdIs Definition via SE18 FCode Tab

Enter related program and function code information. Double clicking on the new line will take you to dialog for defining an icon and function texts

49

Copy right 2009

Menu Enhancement BAdIs Function Code Attributes

Function texts screen shows all codes for associated program Function attributes popup allows definition of code type and static texts

50

Copy right 2009

Menu Enhancement BAdIs Define the Interface (SE18)

Add method to interface that will be implemented by the menu exit

51

Copy right 2009

Menu Enhancement BAdIs Implement BAdI in SE19

Double click on method to add in custom code for the implementati on

52

Dont forget to activate during all steps in this process! Copy right 2009

Menu Enhancement BAdIs Enter Fcode in GUI status

53

Dont forget to activate during all steps in this process! Copy right 2009

Menu Enhancement BAdIs Call the BADI in Application

Dont forget to create a reference to the BADI instance in GLOBAL memory of the application as follows:

DATA o_exit TYPE REF TO zif_ex__menu_exit_badi_1. "BADI interface

54

Copy right 2009

You might also like