Tag Archives: Enhancement Framework

Enhancement Framework – BADI

The new Enhancement Framework and Kernel BADI

The BADI is an object-oriented enhancement option. The BADI defines an interface that can be implemented by BADI-implementations that are transport objects of their own. The new BADI is fully integrated into the Enhancement Framework.

BAdis are like predefined Enhancement options available in SAP which can then be Implemented by the Industries as per there needs.

BAdis: Business Add Ins are Enhancements to the standard SAP code. These BAdi Enhancement can be done with the Interfaces which contains various methods (standard or customized). This Interface name is generated automatically and can be changed as required.

After defining the Interfaces developer assign some methods as required to these interfaces. These methods can have only Importing and Changing parameters Exporting Parameters are not allowed. Finally BAdi is Activated and ready to be used in program.

For creating BAdi first we need to create Enhancement Spot. New BAdi can only be created inside SPOT.

Below figure shows how to create Enhancement SPOT (TCode-SE18)

clip_image002

clip_image004

 

1

New Enhancement SPOT is created.

Now we are creating new BAdi inside this created Enhancement SPOT

Click on Create BADI button.

clip_image008

Provide BAdi name and short description.

clip_image010

BAdi requires one Interface which will contains all methods.

Creating new Interface, just doule click on Interface link under the BAdi definition section.

clip_image012

Provide the Interface name to be created.

clip_image014

 

1

clip_image018

As soon as you will save Interface, it will open new screen to define methods inside this Interface.

All these methods can then be called using BAdi.

clip_image020

Create two different methods namely Addition and Subtraction and provide the parameter list for these methods created inside Interfaces.

clip_image022

The parameters inside these Interface methods can only be Importing and Changing. Exporting parameters are not allowed in Interface methods.

clip_image024

Two created methods are displayed inside Interfaces.

clip_image026

Two steps are already completed

  1. Created new BAdi
  2. Created Interface and added two methods as required.

 

Now need to create Enhancement Implementation so that methods created inside Interfaces can be called.

clip_image028

Enhancement Implementation required Class name.

clip_image030

Class name is required here because using this class only we will be able to use ethods.

clip_image032

A new BADI implementation will be created with name “Z_BADI_IMPL”.

clip_image034

Double click on Implementing Class then following screen with two Interface methods will get displayed.

clip_image036

Double click on any Interface method. Currently these methods are all blank and need to Implement to have custom logic inside these methods.

clip_image038

clip_image040

clip_image042

Now to use this we have created new Report Program

clip_image044

ABAP statements GET BADI, CALL BADI are used to Access Badi Objects.

Filters:

Filters are mainly used as a condition to switch over different implementations methods. For example there is one BAdi having Implementation for converting any amount to UD. Now there is one more new requirement to have currency conversion to IN.

In this case we need to have different Implementation in BAdi which will be switched based on the input provided by the user. This calling of Implementation is all dynamic and can only be determined by BAdi at runtime.

Now creating filters in BADI

clip_image046

clip_image048

clip_image050

Click on Activate.

Now Double click on Enhancement Implementation to open it.

clip_image052

Double Click on Filter and then click on EDIT button.

After this to add different Filter condition click on Combination button.

Now time to add filter condition in created Filters.

clip_image054

When click on Combination button following screen will be displayed.

Here double click on “????” to add new filter conditions.

clip_image056

Need to place value for these filters which will be used by BAdi to decide at runtime which method to call.

In our example we are making calculation based on Country so I have taken IN (India) and another filter will be US.

clip_image058

Two filters are created.

clip_image060

Activate the BADI.

Now to play with Filters we need to create another Implementation which will get called based on Country selected by User.

Need to create another Implementation which will calculate the result based on US country.

1

Every Implementation needs a class, if we provide same class name then this Implementation will inherit the methods of first Implementation which will be useless.

clip_image064

Now we have two Enhancement Implementations, having different method implementations one for US and another for IN.

clip_image066

Double click on Enhancement

clip_image068

Now create new filter for this Implementation

clip_image070

For US we have added 100 more to both parameters.

clip_image072

Now filters are all ready to be used in Report program.

clip_image074

In above screen shot highlighted section shows how to use filters in program.

Source Code:

REPORT z_badi_calc_ab.

PARAMETERS : pctry TYPE land1,

paramet1 TYPE i,

paramet2 TYPE i.

DATA : resultadd TYPE i,

resultsub TYPE i,

objbadi TYPE REF TO z_badi_calc_ab. "Creating object to call BADI's implemented methods

GET BADI objbadi

FILTERS

z_country_filter = pctry. "
Passing Filter values.

CALL BADI objbadi->;;addition

EXPORTING

param1 = paramet1

param2 = paramet2

CHANGING

RESULT = resultadd.


WRITE: / 'Add Result: ', resultadd.

CALL BADI objbadi->;;substraction

EXPORTING

param1 = paramet1

param2 = paramet2

CHANGING

RESULT = resultsub.

WRITE: / 'Substraction Result: ', resultsub.

 

This is how we can implement BAdis.

SAP Enhancement Framework

 image

This New Enhancement frame work provides all new enhancement technologies such as new business add-ins ( BAdIs ) and source code plug-ins.

Kernel BADIs

New BADIs are also Known as Kernel BADIs , These BADIs are object-oriented enhancement options (or plug-ins). These BAdIs are based on interfaces that may be implemented by classes that may then be transported.

You can see Kernel BADIs from the transaction code Se18:

(Note :Technically badis are link with the Enhancement Spot)

 Source code plug-ins

In Source code plug-ins we have many options like Explicit Enhancement and Implicit Enhancement Developers (both SAP and non-SAP) may provide special hooks or portions in their code where enhancements may be applied. These are known as explicit enhancement options, and are mostly created by SAP at specific points of standard programs.

Explicit Enhancement:

In simple word explicit enhancement is provided by SAP, It is predefined location or plugs where you can put your code and enhance the standard. To see the explicit enhancement options in the object it requires to click on the spiral button (shown in yellow color and blue border in below image) which is given in the top tool bar.

 image

Supported Enhancement Technologies

The Enhancement Framework supports a number of different enhancement technologies, including:

• Class Enhancements. Class enhancement lets you add new methods to a class. Moreover, you may also

add optional parameters to existing methods.

• Function Group Enhancements. You may add new parameters to a function module via function group

enhancements.

• Source Code Enhancements. These may be enhancement points in the source code where source

code plug-ins may be attached. These plug-ins contain the code that enhances the given program, and

are treated as an addition to the original code of the program in question. On the other hand, the code

with the enhancement section may be substituted with the source code plug-in code used.

This plug-ins in the source code is called as Enhancement SPOTS.

SPOTS can be categorized in :

  1. Enhancement POINTS
  2. Enhancement SECTION

In simple words When you want to add your extra logic over the existing one use POINTS while when you want to replace the existing one use SECTION. When a SPOT is static it is used for data declaration while Dynamic SPOTS are used for coding.

Enhancement POINTS and SECTION are looks like as mentioned Below:

ENHANCEMENT-POINT <name> SPOTS <spot1> [<spot2>] [STATIC] …

ENHANCEMENT-SECTION <name> SPOTS <spot1> [<spot2>] [STATIC] END-ENHANCEMENT-SECTION.

Implicit Enhancement:

In last if nothing works , like you don’t have any Explicit enhancement or you don’t have any BADIs, Do implicit enhancement .

This is easiest enhancement you can ever find.

Implicit enhancement options are provided internally in the beginning and end of every subroutine , Function module and methods. Where you can put your own code. Check the article

Switch Frame Work:

Each Enhancement package contains a set of business functions. Each “business function” are optionally implemented and activated. Switch frame work is something using which you can deactivate certain Business functionality depending on the client requirement. You can also assign switch to your implemented enhancements so if required you can de activate all of them in single go.

Code Example of Explicit and Implicit Enhancement :

image

CMOD and SMOD:

CMOD and SMOD is another Enhancement technique.

CMOD is the Project Management of SAP Enhancements (i.e., SMOD Enhancements). SMOD contains the actual enhancements and CMOD is the grouping of those SMOD enhancements. 

Enhancements are exits developed by SAP. The exit is implemented as a call to a function module. The code for the function module is written by the developer. You are not writing the code directly in the function module, but in the include that is implemented in the function module.