BADIS : Exercice

This exercise will allow you to have a comprehensive view on the use of BABIs.

Before starting, please read the following articles:
ABAP Objects
Badis: Introduction

The exercise covers two steps : definition and implementation of BADI knowing the definition phase is performed by SAP.

1-Defining a BADI
1.1-Initial Screen
To create a BAdI, use the BAdI Builder (Tools -> ABAP Workbench -> Utilities -> Business Add-Ins -> Definition) (Transaction SE18).

badis_exo-01


1.2-Properties

The adaptation class name “ZCL_EX_BADI” is automatically generated and can not be changed.

badis_exo-02

1.3-Interface
The name of the BADI’s interface “ZIF_EX_BADI” is proposed automatically. It can be changed but it is preferable to keep the naming logic proposed by SAP. The proposed name is constructed as follows:

Namespace prefix, Y or Z
IF_ (Interface)
EX_ (exit)
Name of business add-in

badis_exo-03

-> To define the interface, double-click on its name or use the Class Builder (SE24).
badis_exo-04

-> Create the interface method “USER_EXIT”
badis_exo-05

-> Assign method parameters
badis_exo-06

1.4-Activation
badis_exo-07


2-Implementing a BADI

2.1-Initial Screen
For the implementation of business add-ins, use transaction SE19 (Tools -> ABAP Workbench -> Utilities -> Business Add-Ins -> Implementation).

Enter the implementation name and select Create. A dialog box is displayed. Enter the name of the business add-in. The management screen is displayed.

You can also use BADI definition transaction to access to its implementations. The menu contains an entry ‘implementation’, which you can use to get an overview of existing implementations. You can also create new implementations at this level.

badis_exo-08


2.2-Implementation Class
You can assign the name of your choice to the implementation class. However, it is recommended to follow the naming convention proposed. The proposed name is constructed as follows:

Namespace prefix, Y or Z
CL_ (for class)
Im_ (for implementation)
Implementation name

In the case of the example, the proposed name of the implementation class is “ZCL_IM_BADI”

badis_exo-09


2.3-Interface method

-> To implement the method, double-click on its name. The system then runs  Class Builder (SE24). When you have finished the implementation, you must activate your objects.

badis_exo-10

-> Implementing interface method USER_EXIT ZIF_EX_BADI
badis_exo-11

-> Implementing source code of the method
badis_intro-12

2.4-Activation
-> Once interface is implemented, you have to activate it.

3-Second implementation of the same BADI
-> The main advantage of the Badis is their reusability. A business add-in can have multiple implementations in the same system. In the following example, we will create a second implementation for the same business add-in ZBADI.

-> Implementation (SE19)

badis_exo-13

-> Implementing method USER_EXIT for interface ZIF_EX_BADI

4-Calling program

To call a business add-in method from a program, you must include three statements in the program :

  1. Declare a reference variable to refer to the interface of business add-in (in our example, ‘ZIF’).
  2. Call the static method GET_INSTANCE of service class CL_EXITHANDLER. The system returns an instance of the required object. This implies a narrow implicit distribution, so that only the interface methods with the reference variable ‘ZIF’ are available.
  3. You can now call all the methods of business add-in. Be sure to specify correctly the method parameters. If the business add-in is filter dependent, you must pass an appropriate value for the parameter FLT_VAL. If the business add-in has several active implementations, they will be called in alphabetical order.

To test implementations, just run the above program and double-click on the displayed rows.

The first implementaion show the details of the selected flight and the second will show an information message.