BADIS : Introduction

Before starting, please read this article about ABAP Objects : Advantages of BABIs

The business add-ins are a natural extension of conventional extension techniques. They reuse the management layer of customer exits, associated with various components of extension.

Implementing Object-Oriented provides new opportunities. It is for example possible to make an extension of the Object ‘Document’. It is also possible to provide a new instance of the extension for each individual document.

badis_intro-01

The main advantage of this concept is the reusability. Once implemented, a business add-in can have several new implementations.
In addition, an implementation may also provide its own add-ins.

Components
badis_intro-02

A business add-in contains all the components of an extension. Currently, each business Add-in can contain the following elements:

  • Extensions Program
  • Menu extensions

In future releases, other components included in customer exits will also be available as add-ins components.

When you define a business add-in, you can create several components:

  • Interface
  • Generated class (add-in adapter)

The generated class performs the following tasks:

  • Filtering: When you implement a filter dependent business add-in, adaptation class ensures that only relevant implementations are called
  • Control: the adaptation class calls active implementations.

Process
badis_intro-03

This graph illustrates the process followed by a program containing a call to a Business add-in. Not displayed here, you must declare a reference variable in the appropriate place.

In the first step, a existing service class (CL_EXITHANDLER), creates an object reference. The syntax used is discussed later. Once this step is completed, the extension program can be used.

When you define a business add-in, the system creates an adapter class that implements the interface. During call (2), the interface method of the adaptation class is called. This class research all implementations of business add-ins and call implemented methods .

badis_intro-04

This graph shows the syntax to call a business add-in. The circled numbers correspond to the calls of the previous graph.

You must first define a variable with reference to the interface of the business add-in. The variable name reference does not necessarily contain the name of the business add-in.

In the first step (1), an object reference is created. This creates an instance of the generated adaptation class, limited to the interface methods (narrow distribution).

You can use this object reference to invoke desired methods (2).

Definition of a business add-in

badis_intro-05

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

Attributes
badis_intro-06

You have to define two important attributes for business add-ins:

  • Multiple use
  • Limited filter use

If you want the business add-in supports multiple parallel implementations, select “Multiple Use”.

If you set the attribute “Limited filter use” for a business add-in, calls to the business add-in will depend to certain conditions. You must specify the type of filter as a data element. Table of domain values used by the data element contains valid values for implementation.

When the extension method is called, a filter value has to be transmitted to the interface.

Interface methods

badis_intro-07

The system proposes a name for the generated class and interface. You can change the name of the interface as you want. However, your business add-in will be easier to manage if you retain the proposed name.

The name of the generated class is constructed as follows:

Namespace prefix Z or Y
CL_ (to specify a class in general)
EX_ (for ‘exit’)
Name of business add-in

If you double-click on the interface name, the system switches to the Class Builder (SE24), in which you can define interface methods.
BADI interface can have multiple interface methods.

badis_intro-08

You can use all the standard functions of the Class Builder. You can for example:

  • define interface methods
  • define interface parameters for methods
  • declare the attributes of the interface

If the business add-in is filter dependent, you have to define an import  parameter (FLT_VAL) for each method. Otherwise, you define the interface parameters that you need for the extension.

Activating the interface

badis_intro-09

When you have finished working on your interface, you have to enable it. This generates adaptation class of business add-in. This class is automatically regenerated each time you change the interface.

You can also explicitly generate adaptation class at any time by selecting Tools -> Regenerate from the initial screen of the BADIs management transaction.

Calling program

badis_intro-10

To call a business add-in method from an application program, you have to include three statements in the program:

  1. Declare a reference variable to refer to business add-in interface (in our example, exit_ref).
  2. Call the static method GET_INSTANCE of 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 exit_ref are accessible.
  3. You can now call all the business add-in methods. 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.

Implementation of a business add-in

Naming convention

BADI ‘BADI’
Interface: IF_EX_’BADI ‘
Methods: Free choice
BADI generated class (not editable): CL_EX_’BADI ‘
Implementation name: Z’free ‘
Implementation class: ZCL_IM_’free’

Implementation: Initial Screen

badis_intro-11

To implement 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 will be displayed.

You can also use BADI definition transaction to access to implementation function. The menu contains an entry implementation that you can use to get an overview of existing implementations. You can also create new implementations at this level.

Methods

badis_intro-12

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 by default as follows:

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

To implement the method, double-click on its name. The system then runs Class Builder.
When you have finished, you have to activate your objects.

Private methods

badis_intro-13

Implementation class allows you to create your own methods which can be called from the interface method.

Activation

badis_intro-14

Use the Activate icon to enable the implementation of a business add-in. Now, the implementation metods will be executed at the same time as the calling program.

If you disable the implementation, methods will not be called. However, the corresponding calls in the application program are still processed. The difference lies in the fact that adaptation class instance will not find active implementations. Unlike CALL CUSTOMER-FUNCTION,  CALL METHOD  CL_EXITHANDLER=>GET_INSTANCE is always executed even if there is no more implementations.

This principle is also valid for the instruction calling the adaptation class method.
You can only activate or deactivate an implementation in its original system. Any change other than in the original system is considered as a modification. The activation or deactivation must be transmitted to subsequent systems.

A business add-in can only have one definition, but many implementations may exist in the same system.

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>