Introducing enhancement framework
Enhancement framework
New Enhancement framework in ECC 6.0
The
basic idea of the Enhancement Framework is to make modification-free
enhancements of development objects such as programs, function modules, global
classes, and Web Dynpro components.
All
these technologies and the new kernel-based BAdI are now integrated in one
Framework that has the following features:
Enhancements
of existing development objects on different levels - for example, in an
industry solution, in the IT department of the customer, and finally in a
customer's company.
Better
upgrade support
Switching
of enhancements with the Switch Framework
Support
for grouping enhancements and appropriate tool support for documentation.
Enhancement Options For
Modification-Free Enhancements
The
basic concept is the enhancement option. Think of an enhancement option as a
hook where you can attach the enhancement implementation elements to. If an SAP
system provides these hooks, you can add an implementation element there at
later stages of development in other system, without modifying the original SAP
code.
This is
possible because enhancement implementation elements are in a package of their
own and transport objects in their own right. This way, you avoid all the
trouble with modifications that stems from the fact that modifications are,
from a technical point of view, part of the compilation unit they modify.
Explicit and Implicit
Enhancement Options
Principally, there
are two types of enhancement options:
The
developer of the corresponding development object must insert the options of
the one kind into the coding so that enhancements can be done there at a later
time. These preconceived enhancement possibilities are called explicit
enhancement options.
You can
perform enhancements on implicit enhancement options without the developer of
the appropriate compilation unit having to do anything. Enhancement options are
always available in
programs, global classes, function modules, and includes.
In
other words, the implicit enhancement options are for free, provided by the
framework, while the explicit ones need to be inserted explicitly, as the name
indicates.
The Use Case
And now
let us have a look at an example in detail. Imagine that the developer of the
basic program needs the VAT of different book entries. These entries should be
passed to a method that calculates and returns the VAT. As this developer does
not know what the VAT in a specific country is, he defines a BAdI badi_vat with
the method get_vat. This method should return the VAT for a particular value
that is passed to the method get_vat.
Building a New BADI (in
Enhancement Framework)
Building
the Enhancement Spot
The
first thing you need when creating a BAdI is a container for the BAdI. Up to
now we have no container, so we have to create a (simple) enhancement spot.
This is the container in which we develop our BAdI.
We go
to the ABAP workbench and navigate there to our local objects. We select:
Create->Enhancement->Enhancement-Spot
from the context menu of the local objects folder.
We
enter a name for the enhancement spot and some short text. To name a composite
enhancement spot is voluntary. We are content with our enhancement spot and
need no higher level container for the example. In real life programming, you
probably should take advantage of the structure the composite enhancement spots
offer you and always work with these complex containers.
Next we
create a BAdI within the new enhancement spot. We select the CREATE icon on the
left:
In the
dialog window that appears we enter the BAdI name z_badi_calc_vat plus a short
description and confirm. Now we have a BAdI in the list of our enhancement
spot. We deselect the property "multiple use", because for our
calculation we need a single use BAdI:
The BAdI Interface
Image->enhace4
Selecting the Change icon leads you to
the class builder, where you can create the methods you need for your BAdI in
the same way that you are used to if you are familiar with the class builder.
We just type in the name of the method get_vat and enter the parameters we
need.
Image->enhace5
Next we determine the parameters of the
method.
We save and activate the interface and
the spot.
Image->enhace6
Just building a BAdI does not suffice.
It does not do anything. You need a BAdI instance, and this instance must be
called somewhere in the code. This is the definition part of a BAdI. But as a
BAdI only defines an interface, you need a class that implements this
interface.
So it is time to write some ABAP code to
use the BAdI. We need a variable that can refer to the BAdI and some variables
which are given as actual parameters to the BAdI method. Next we create a
handle for that BAdI and call the BAdI method get_vat. The respective commands
are GET BADI and CALL
BADI.
DATA: handle TYPE REF TO
z_badi_calc_vat,
sum TYPE p,
vat TYPE p,
percent TYPE p.
sum = 50.
GET BADI handle.
CALL BADI handle->get_vat
EXPORTING
im_amount = sum
IMPORTING
ex_amount_vat = vat
ex_percent_vat = percent.
WRITE: 'percentage:', percent, 'VAT:',
vat.
If we run the program it dumps. It is
mandatory, that there is exactly one active implementation for a single use
BAdI. Our BAdI is a single use BAdI. One way to handle this is to catch the
respective exception cx_badi_not_implemented.
Using and Creating a Fallback
Class
The other way is the better solution,
namely to use a fallback class. A fallback class for a BAdI is used if there is
no active BAdI implementation. This means: The GET BADI command returns a
handle to an instance of the fallback class and the respective CALL BADI calls
the methods of the fallback class instance. As soon as there is an active BAdI
implementation, the fallback class is not used any longer at runtime. So using
a fallback class serves two functions at once:
The program runs with a single use BAdI
without raising an exception.
It is guaranteed that the fallback class
is not used any more as soon as a BAdI implementation is supplied. So a
fallback class is only selected conditionally. This is important, because the
BAdI provider does usually not know the details of some process. This is why a
BAdI is used.
Image->enhace3
We
select the checkbox the bottom with the text: Call fallback class if no
implementation is executed and insert a name for the class.
Clicking
the change icon leads us to the class builder. The respective method of the
BAdI interface is already defined. We only have to implement:
DATA:
percent TYPE p VALUE 20.
ex_amount_vat
= im_amount * percent / 100.
ex_percent_vat
= percent.
Save
and activate the class. Then we navigate back to the enhancement spot and
activate it. Running the program again leads to result: percentage: 20 VAT: 10.
Summary
Business
Add-Ins are a new SAP enhancement technique based on ABAP Objects.
Business
Add-Ins are defined through transaction SE18 and implemented through
transaction SE19.
New
Enhancement Framework (Enhancement Spot, Creating New BADI)
Questions
What are BAdis ?
Which transactions are used for BAdi
Definition and Implementation?
How do you locate BAdis defined by SAP
for a SAP standard transaction?
What are the advantages of the New
Enhancement Framework?
0 comments:
Post a Comment