LESSON OVERVIEW
This lesson explains how to define Business Add-Ins (BAdIs).
Business Example
You have to define a Business Add-In (BAdI) that serves as an enhancement for later developments in your program. For this reason, you require the following knowledge:
● An understanding of how to create BAdIs that serve as enhancements for later developments in your programs
LESSON OBJECTIVES
After completing this lesson, you will be able to:
● Implement classic BAdI program exits
Business Add-In Creation (BAdI Definition)
Figure 102: BAdI Definition – Introduction
To create a BAdI, use the BAdI Builder ( Tools → ABAP Workbench → Utilities → Business Add-Ins → Definition) or transaction SE18.
Prior to SAP NetWeaver Application Server 7.0, the initial screen of transaction SE18 appears as shown in the figure.
In SAP NetWeaver Application Server 7.0, new BAdIs also exist. They are contained in enhancement spots. To create an older (classical) BAdI from the new initial screen of transaction SE18, choose Utilities → Create classical BAdI.
© Copyright . All rights reserved. 137
Section: BAdI Definition – Attributes
Figure 103: BAdI Definition – Attributes
A BAdI has the following important attributes that you must define:
● Reusable
● Filter-dependent
If you select the Reusable checkbox, many implementations can exist for the BAdI. The sequence in which the system processes implementations is not defined. Even if the BAdI does not support multiple uses, you can still have more than one implementation for it.
However, only one implementation can be active at one time.
If you make a BAdI Filter-dependent, you can make calls to it depending on certain conditions.
Specify the filter type in the form of a data element or a structure present in the ABAP Dictionary. The data element uses the value table of the domain. This value table contains valid values for the implementation. Other than using structures as the filter type, you can use the single fields of the structure as well.
When you call the enhancement method, a filter value must be passed to the interface.
BAdI Definition – Restrictions for Menu Exits
Figure 104: BAdI Definition – Restrictions for Menu Exits
You can include function codes in a BAdI definition, for example, menu exits in customer exits.
To do this, enter the program name, the function code, and a short description on the relevant tab page.
Unit 6: Classic Business Add-Ins
Restrictions for menu exits are as follows:
● It is currently not possible to create BAdIs that consist only of menu enhancements (function codes).
● If you use menu enhancements, you cannot reuse a BAdI or make it filter-dependent.
BAdI Definition – Defining Interface Methods
Figure 105: BAdI Definition – Defining Interface Methods
The system proposes a name for the interface and the generated class. In principle, you can change the name of the interface. However, the BAdI is easier to understand if you retain the proposed name.
The name of the generated class is composed of the following:
● Namespace prefix
● CL_ (to signify a class in general)
● EX_ (stands for exit)
● BAdI name (without namespace prefix)
If you double-click the interface name, the system switches to the Class Builder, where you can define the interface methods. A BAdI interface can have several interface methods.
Lesson: Implementing Classic BAdI Program Exits
© Copyright . All rights reserved. 139
BAdI Definition – Method Interface Parameters
Figure 106: BAdI Definition – Method Interface Parameters
You can use all of the normal functions of the Class Builder.
Some of the functions are as follows:
● Define interface methods.
● Define interface parameters for the methods.
● Declare the attributes of the interface.
If the BAdI is filter-dependent, you must define an import parameter flt_val for each method;
otherwise, define the interface parameters needed for the enhancement.
BAdI Definition – Activating the BAdI Interface
Figure 107: BAdI Definition – Activating the BAdI Interface Unit 6: Classic Business Add-Ins
After working on the interface, you must activate it. This generates the BAdI class for the BAdI.
If you change the interface, the system automatically regenerates the BAdI class.
You can also generate the BAdI class explicitly at any time. To do so, choose Utilities → Regenerate from the initial screen of the BAdI maintenance transaction.
BAdI Definition – Calls in the Program
Figure 108: BAdI Definition – Calls in the Program
To call BAdI methods in an application program, you must include the following statements in the program:
1. Declare a reference variable (1) with reference to the BAdI interface, for example, r_var.
2. Call the static method GET_INSTANCE of the service class CL_EXITHANDLER (2). This returns an instance of the required object. It involves an implicit down cast, so that you can call only the interface methods of the object with the reference variable r_var.
3. Call all of the methods of the BAdI (3). Ensure that you specify the method interfaces correctly.
Lesson: Implementing Classic BAdI Program Exits
© Copyright . All rights reserved. 141
Calling a Filter-Dependent BAdI
Figure 109: Calling a Filter-Dependent BAdI
If your BAdI is filter-dependent, you must pass an appropriate value to the parameter flt_val.
Demonstration: How to Implement a BAdI To implement a BAdI, follow the steps below:
1. Prepare a small program to implement the BAdI you have defined.
2. Define a reference variable.
3. Instantiate the object with CALL METHOD CL_EXITHANDLER=>GET_INSTANCE.
4. Call the methods for your BAdI.
5. Create the BAdI implementation.
6. Point out that now you are on the implementing side. Distinguish the providing and the implementing sides very clearly.
Unit 6: Classic Business Add-Ins