Beruflich Dokumente
Kultur Dokumente
Introduction
There are multiple ways of searching for BAdIs. My favorite one is using the
Performance Trace (formerly known as SQL trace) transaction code ST05.
This analyzing technique is based on the fact that all BAdIs are registrated in SAP
database tables. So for each BAdI call these database tables will be accessed. The
BAdI database tables are SXS_INTER, SXC_EXIT, SXC_CLASS and SXC_ATTR. These
tables are always accessed by the views V_EXT_IMP and V_EXT_ACT. So these two
ABAP views (T: SE11) will be the basis for the trace.
The procedure to discover BAdIs by a Performance Trace will be explained by using
the example used below.
Example case
I want to know which BAdIs are called in the transaction "Maintain Business Partners"
transaction code BP.
Pre checks
Check if no other users (T:SM04) or batch jobs (T: SM50) are using the same
user as you do.
Trace Actions
Start the Performance trace
Start transaction ST05 (Performance Analysis)
Set flag field "Buffer trace"
Remark: We need to trace also the buffer calls, because BAdI database tables are
buffered. (especially view V_EXT_IMP and V_EXT_ACT)
Name
Street
House
number
Postal code
City
Country
NL4B
Olympia
1a/1b
1213 NS
Hilversu
m
NL
Performance trace
(If you cant find the BAdI definition name, search in table SXS_INTER.)
If youd like to keep your analysis, you can export it to Excel file format.
Actually the file will be saved in tab separated file format, but giving the file the
extension .xls it will automatically be opened by Excel.
Delete the columns and rows you dont need and the result looks like:
Tips
Make a full test entry in the Business transaction before starting the
Performance analysis.
So during the Performance trace you wont make mistakes. Making mistakes
during the recording will cause extra trace lines in your trace list.
Try to start with an empty Business transaction screen.
This tip is best explained by an example.
When I restart transaction BP after I have created, displayed or changed a
business partner, the last opened business partner will be displayed
automatically. This means also I will get extra trace lines in my trace list.
To start again with an empty business partner screen you have to close all GUI
sessions and login again.
In the Business transaction you need to fill all required fields so all BAdIs will
be called.
Appendix BP analysis
View
V_EXT_AC
T
V_EXT_IM
P
V_EXT_AC
T
V_EXT_IM
P
V_EXT_AC
T
V_EXT_IM
P
V_EXT_AC
T
V_EXT_AC
T
V_EXT_IM
P
V_EXT_IM
P
V_EXT_AC
T
V_EXT_AC
T
V_EXT_IM
P
V_EXT_IM
P
V_EXT_IM
P
V_EXT_IM
P
V_EXT_AC
T
V_EXT_AC
T
V_EXT_AC
T
V_EXT_AC
T
Call
R 20 ADDR_LANGU_TO_VERS
BadI
ADDR_LANGU_TO_VERS
R 30
IF_EX_ADDR_LANGU_TO_VERS
R 20 BUPR_FILTER_RELTYP
ADDR_LANGU_TO_VERS
R 30 IF_EX_BUPR_FILTER_RELTYP
BUPR_FILTER_RELTYP
R 20 BUPR_FILTER_RELTYP
BUPR_FILTER_RELTYP
R 30 IF_EX_BUPR_FILTER_RELTYP
BUPR_FILTER_RELTYP
R 20 BUPR_FILTER_RELSHP
BUPR_FILTER_RELSHP
R 20 BUPA_AUGRP
BUPA_AUGRP
R 30 IF_EX_BUPA_AUGRP
BUPA_AUGRP
R 30 IF_EX_BPTIME_BP001
BPTIME_BP001
R 20 ADDRESS_SUBSCREEN
ADDRESS_SUBSCREEN
R 20 ADDRESS_SEARCH
ADDRESS_SEARCH
R 30
IF_EX_ADDRESS_SUBSCREEN
R 30
IF_EX_ADDRESS_SUBSCREEN
R 30
IF_EX_ADDRESS_SUBSCREEN
R 30
IF_EX_ADDRESS_SUBSCREEN
R 20 ADDRESS_SEARCH
ADDRESS_SUBSCREEN
R 20 ADDRESS_CHECK
ADDRESS_CHECK
R 20 ADDRESS_CHECK
ADDRESS_CHECK
R 20 ADDR_TXJCD_CHECK
ADDR_TXJCD_CHECK
BUPR_FILTER_RELTYP
ADDRESS_SUBSCREEN
ADDRESS_SUBSCREEN
ADDRESS_SUBSCREEN
ADDRESS_SEARCH
V_EXT_AC
T
V_EXT_AC
T
V_EXT_IM
P
V_EXT_AC
T
V_EXT_IM
P
V_EXT_AC
T
V_EXT_IM
P
V_EXT_AC
T
V_EXT_IM
P
V_EXT_AC
T
V_EXT_IM
P
V_EXT_AC
T
V_EXT_IM
P
V_EXT_AC
T
V_EXT_IM
P
V_EXT_AC
T
V_EXT_IM
P
V_EXT_AC
T
V_EXT_IM
P
V_EXT_AC
T
V_EXT_IM
P
V_EXT_AC
T
V_EXT_IM
P
R 20 ADDRESS_CHECK
ADDRESS_CHECK
R 20 ADDR_PRINTFORM_SHORT
R 30
IF_EX_ADDR_PRINTFORM_SHORT
R 20 BUPA_ROLE_EXPORT
ADDR_PRINTFORM_SHO
RT
ADDR_PRINTFORM_SHO
RT
BUPA_ROLE_EXPORT
R 30 IF_EX_BUPA_ROLE_EXPORT
BUPA_ROLE_EXPORT
R 20 BUPA_BANK_EXPORT
BUPA_BANK_EXPORT
R 30 IF_EX_BUPA_BANK_EXPORT
BUPA_BANK_EXPORT
R 20 BUPA_CCARD_EXPORT
BUPA_CCARD_EXPORT
R 30
IF_EX_BUPA_CCARD_EXPORT
R 20 BUPA_INDSEC_EXPORT
BUPA_CCARD_EXPORT
R 30
IF_EX_BUPA_INDSEC_EXPORT
R 20 BUPA_ADDR_EXPORT
BUPA_INDSEC_EXPORT
R 30 IF_EX_BUPA_ADDR_EXPORT
BUPA_ADDR_EXPORT
R 20 BUPA_GENERAL_EXPORT
BUPA_GENERAL_EXPORT
R 30
IF_EX_BUPA_GENERAL_EXPORT
R 20 BUPA_GENERAL_UPDATE
BUPA_GENERAL_EXPORT
R 110
IF_EX_BUPA_GENERAL_UPDATE
R 20 BUPA_BANK_UPDATE
BUPA_GENERAL_UPDATE
R 110
IF_EX_BUPA_BANK_UPDATE
R 20 BUPA_CARDS_UPDATE
BUPA_BANK_UPDATE
R 30
IF_EX_BUPA_CARDS_UPDATE
R 20 BUPA_ROLES_UPDATE
BUPA_CARDS_UPDATE
R 30 IF_EX_BUPA_ROLES_UPDATE
BUPA_ROLES_UPDATE
BUPA_INDSEC_EXPORT
BUPA_ADDR_EXPORT
BUPA_GENERAL_UPDATE
BUPA_BANK_UPDATE
BUPA_CARDS_UPDATE
BUPA_ROLES_UPDATE
V_EXT_AC
T
V_EXT_IM
P
V_EXT_AC
T
V_EXT_IM
P
V_EXT_AC
T
V_EXT_IM
P
V_EXT_IM
P
V_EXT_AC
T
V_EXT_IM
P
V_EXT_AC
T
V_EXT_IM
P
V_EXT_AC
T
V_EXT_IM
P
V_EXT_IM
P
V_EXT_AC
T
V_EXT_IM
P
V_EXT_IM
P
V_EXT_AC
T
V_EXT_IM
P
V_EXT_AC
T
V_EXT_AC
T
V_EXT_IM
P
V_EXT_IM
P
R 20 BUPA_INDSEC_UPDATE
BUPA_INDSEC_UPDATE
R 30
IF_EX_BUPA_INDSEC_UPDATE
R 20 BUPA_IDENT_UPDATE
BUPA_INDSEC_UPDATE
R 30 IF_EX_BUPA_IDENT_UPDATE
BUPA_IDENT_UPDATE
R 20 ADDRESS_UPDATE
ADDRESS_UPDATE
R 30 IF_EX_ADDRESS_UPDATE
ADDRESS_UPDATE
R 30 IF_EX_ADDRESS_UPDATE
ADDRESS_UPDATE
R 20 BUPA_ADDR_UPDATE
BUPA_ADDR_UPDATE
R 110
IF_EX_BUPA_ADDR_UPDATE
R 20 BUPA_TAX_UPDATE
BUPA_ADDR_UPDATE
R 110 IF_EX_BUPA_TAX_UPDATE
BUPA_TAX_UPDATE
R 20 FSBP_BPID_UPDATE
FSBP_BPID_UPDATE
R 30 IF_EX_FSBP_BPID_UPDATE
FSBP_BPID_UPDATE
R 30 IF_EX_BPTIME_BP001
BPTIME_BP001
R 20 FSBP_BP001_UPDATE
FSBP_BP001_UPDATE
R 30 IF_EX_FSBP_BP001_UPDATE
FSBP_BP001_UPDATE
R 30 IF_EX_BPTIME_BUT021_FS
BPTIME_BUT021_FS
R 20 FSBP_BUT021_UPDATE
FSBP_BUT021_UPDATE
R 30
IF_EX_FSBP_BUT021_UPDATE
R 20 ADDRESS_SEARCH
FSBP_BUT021_UPDATE
R 20 PARTNER_UPDATE
PARTNER_UPDATE
R 30 IF_EX_PARTNER_UPDATE
PARTNER_UPDATE
R 30 IF_EX_PARTNER_UPDATE
PARTNER_UPDATE
BUPA_IDENT_UPDATE
BUPA_TAX_UPDATE
ADDRESS_SEARCH
V_EXT_IM
P
V_EXT_IM
P
V_EXT_AC
T
V_EXT_IM
P
V_EXT_AC
T
R 30 IF_EX_BPTIME_BP001
BPTIME_BP001
R 30 IF_EX_BPTIME_BUT021_FS
BPTIME_BUT021_FS
R 20 GOS_SRV_SELECT
GOS_SRV_SELECT
R 30 IF_EX_GOS_SRV_SELECT
GOS_SRV_SELECT
R 20 ADDRESS_SEARCH
ADDRESS_SEARCH
Ignore the details of the source code enhancement for the moment. This particular
example only serves to illustrate the point of how enhancements function: You have
the anchor point or enhancement option, which is an enhancement point in our
particular example. At this enhancement point which is in the orange marked line the
enhancement element 1 (in grey colour) is inserted. The spot flights_display_b and
the enhancement flights_display are units you should not be interested in at this
point.
In some way you can compare the enhancement technology with a closet system
where you can insert different elements at particular positions. You need not drill the
wood in the side walls, but nevertheless you can attach boards and other elements
where there are already hooks or holders at important positions. The boards and
other elements such as drawer or CD-holder look as if they were integral parts of the
closet system while in fact they are only attached to the walls by hooks or holders.
The holder in our analogy corresponds to the enhancement options. The different
elements you can attach there such as boards, drawers, CD- elements etc. behave
like the enhancements. You can not attach a board to the closet system everywhere
you like, but rather only where a holder is prepared. In the same way you cannot
enhance a development object anywhere, but only at predefined positions, which are
called enhancement options.
So irrespective of all further refinements, superimposed containers and their
respective connections, the basic structure of how an enhancement functions is as
simple as could be:
On the one hand, there are hooks or enhancement options where you can
insert enhancement elements. Further on I will also speak of the definition side of the
Enhancement Framework because it is there that the enhancement options are
defined.
On the other hand, there are the enhancement implementation elements that
you can attach to a hook or an enhancement option.
composite containers that can hold basic containers and other composite containers.
These composite containers can contain basic containers of different enhancement
types. As these composite containers can be nested, you can build a structure that
really fulfills the needs of your project. A simple structure looks like this:
It is important that you have a clear idea of this structure in mind because everything
you do when creating an enhancement happens within this structure. This is due to
the fact that the compliance to the rules is enforced by the framework. This means
for you: Every enhancement element has to be part of an enhancement spot. When
you create an enhancement from scratch you always have first to create the
respective containers. You can compare this to creating a method. There is no such
thing as a method on its own. A method is always part of a class. In the same way
there is no stand-alone BAdI. Every BAdI is part of an enhancement spot and it is the
spot that is the transport object. It is because of this fact that you cannot build a new
BAdI and just forget about the framework in the way you might be accustomed to
from the classic BAdI. It is also not possible to build the BAdI first and take care later
of how it fits in the structure of containers. When building a BAdI you have to put the
BAdI within the relevant structure from the very beginning. But it is only mandatory
to have simple containers. Composite enhancements spots and composite
enhancement implementations are not enforced by the tools.
I mention this explicitly because, at first, it might be a bit astonishing for you when
you want to create an enhancement point and you first have to create an
enhancement spot. When this happens, you should keep in mind two things:
You should be aware of the fact that you have only the containers after having
created an enhancement spot and a simple enhancement implementation. You have
prepared the ground for building enhancements, but that is all. Don't delude yourself
into thinking that you have already an enhancement option or the respective
implementation.
Previously, you have learnt the basic concept of an enhancement. In this , you have
seen the different kinds of enhancement options, you understand the difference
between implicit and explicit enhancement option and you know the structure where
the enhancements fit in. In other words, now you have everything you need at hand
to build a BAdI. We will build a BAdI and see all the pieces of theory at work that you
have become acquainted with by now.
there are implicit enhancement options, that are, so to speak, for free and always
available. But there are not implicit BAdIs. If you need a BAdI, somebody has to
define it explicitly. Let us call this role the (enhancement) option provider. In general,
the option provider is identical with the developer of a development object that
should offer an explicit enhancement option. Let us call this object the basic
development object. Typically, the developer of the basic development object could
be somebody working in the SAP core who anticipates that the customer or an
industry solution might want to add some code at a particular point. In this case he
creates both the development object to be enhanced at a later stage and defines an
enhancement option.
An enhancement option that has no implementation does not do a lot when
processed, in fact, it has no effect at all. To make something happen at an
enhancement option, you need to implement it. The developer who implements an
enhancement option, or to put it in the analogy, attaches something to the hook, is
called the implementer. He need not care about the details of an enhancement
option, but just know how he implements it. But, of course, he should have a sound
knowledge of the way enhancement options function. You might compare this to
somebody who uses a service class. He does not need to know the inside of this
class, but just its public methods or maybe even only the respective interface he is
interested in. In the same way, the implementer only needs a limited knowledge as
to how to define an enhancement option.
In the strict sense, many of you are probably only interested in implementing a BAdI.
They suppose that SAP provides the BAdI and calls the respective BAdI methods. All
they want to know is what they have to take heed of when writing the BAdI
implementation. But it is quite useful to know a bit more about defining a BAdI, and
once you have understood what a powerful pattern a BAdI is, you might also be
tempted to write your own BAdI definitions. Moreover, it would be a bit long-winded
to write two different series of ,s, one for the option provider and another one for the
implementer, because there is a large overlap in the background knowledge. For all
these reasons, I have decided to handle both topics in this one series. But still, I treat
building the BAdI in this , and providing an BAdI implementation in the next one. And
you should always keep in mind: Implementing and defining a BAdI are two different
roles. And the same is true for source code enhancements.
With a BAdI the option provider defines what has to be done, but leaves it to the
implementer how he implements the BAdI. Moreover, the BAdI implementer cannot
fiddle with the basic program. It is assured that a BAdI implementation can only
change the parameters handed over to BAdI. The implementation of a method has a
context of its own and the variables of the development object using the BAdI are not
even visible from inside the BAdI implementation.
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.
The BAdI Itself
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:
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.
A BAdI interface has to implement the interface if_badi_interface. But if we create a
BAdI interface in the way just shown this marker interface is already integrated in the
BAdI interface. Probably you know how to work with the class builder, but still I have
inserted the following two screenshots to show you: Defining a BAdI interface is just
normal ABAP Objects programming and as simple as could be for anyone familiar
with the Class Builder. We define one BAdI method.
We have created an enhancement spot and a BAdI with an interface. The interface
has one method so far.
Of course, 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. Remember: A BAdI definition is the option to insert an
object plug-in that does a job at runtime. You still need an object that is plugged in to
get something done.
If we run the program it dumps. Considering what I have told you before about the
single use BAdI, this is no wonder. 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.
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.
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. Again the tools do a great job
for you: The respective method of the BAdI interface is already defined. We only have
to implement it:
I skip this, because it is no news to anybody familiar with the Class Builder. Of course,
we have to 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.
And this is the end of this ,. Now, you know how to build an enhancement spot and a
BAdI including the BAdI interface and a fallback class plus the ABAP commands to use
the new BAdI. In the next , you learn how to create a BAdI implementation inside the
respective container, that is the (simple) enhancement implementation and how to
select among the different BAdI implementations using the addition FILTER to the GET
BADI command.
How to implement a BAdI And How to Use a Filter Part 4 of the Series on the New Enhancement
Framework
In the last , we defined a BAdI, provided a fallback class, instantiated the BAdI and
called a BAdI method. Of course, we also provided an enhancement spot, because
our BAdI, as every BAdI, needs a container to live in.
As you have learned, the fallback class is chosen in case no BAdI implementation is
available. As we have not created a BAdI implementation so far, the method
implementation of the fallback class was used in our example code. To change this,
we create a BAdI implementation in this ,. As soon as there is a suitable BAdI
implementation the methods of the fallback class are not used any longer.
First let us have a short look at the entities we have so far: There is the enhancement
spot z_es_calc_tax in which the BAdI z_badi_calc_vat lives. The BAdI interface defines
an important part of the BAdI identity, insofar it defines the BAdI methods that can be
used. Our interface z_if_calc_vat has one method get_vat( ).
The definition and the implementation of BAdIs are similar in one respect: Just as you
need a container that is an enhancement spot for a BAdI, you cannot build a BAdI
implementation unless you have the relevant container first. The relevant container
type for BAdI implementations is called (simple) enhancement implementation. A
simple enhancement implementation can keep many different BAdI implementations,
but with one restriction:
A simple enhancement implementation is uniquely assigned to an enhancement spot.
That means: A (simple) enhancement implementation can keep only BAdI
implementations of BAdIs that belong to the spot the simple enhancement
implementation is assigned to. This has the consequence: An (simple) enhancement
implementation cannot keep BAdI implementations that implement BAdIs belonging
to different spots.
This being so, we have first to create a container that is uniquely assigned to the
enhancement spot our BAdI belongs to. Despite the fact that we have to do
something pretty complex, the respective tool in the SE80 has paved a smooth way
to do this. All you have to do is to press one button. This button is marked with an
orange frame in the screenshot below:
What are we asked to type in here? We have created so far a container for BAdI
implementations, that is a (simple) enhancement implementation. This container is
uniquely assigned to our enhancement spot. Once this connection is established, we
can create a BAdI implementation for the BAdI within the enhancement spot. As we
have defined only one BAdI within the enhancement spot, we have no choice. If we
had more BAdIs in our enhancement spot, this would be the point where to select
which BAdI we want to implement. As matters stand, we type in z_bdi_calc_vat_us as
the name of the BAdI implementation, confirm and save the enhancement spot in the
next window. There we are: This is (simple) enhancement implementation that
contains the BAdI implementation z_bdi_calc_vat_us:
At the top, there is the definition part: In principle, such a spot can contain many
different BAdI definitions. Our enhancement spot contains only one BAdI definition.
We have created a container for the BAdI implementations. This (simple)
enhancement implementation is uniquely assigned to the enhancement spot, but one
enhancement spot can have many enhancement implementations assigned to it. We
have a one-to-many relationship between the enhancement spot and the
enhancement implementation. With this relationship established, we have assigned a
BAdI implementation to our BAdI. Again, this is a one-to-many relationship: A BAdI
definition can have many BAdI implementations, but a BAdI implementation uniquely
belongs to a BAdI.
Only if the relationship between the containers that is the enhancement spot and the
enhancement implementation is established, you can assign a BAdI implementation
to a BAdI definition. I have tried to show this in the picture by the large orange pipe
that contains the small grey pipe.
You should keep in mind: When implementing a BAdI, you have first to establish a
connection between the relevant containers. Based on this connection you can go on
and implement the BAdI. This principle applies to source code plug-ins in an
analogous fashion.
Now that we have a BAdI implementation, we need an implementing class. We click
the triangle in front of the name of the BAdI implementation in the tree and next
double-click Implementing Class:
It works the same way as with the creation of the fallback class in the last ,. As we do
not want to reuse an existing class we enter the name z_cl_calc_vat_us and select the
Change icon. Again, we get to the Class Builder where the relevant interface methods
are already defined. In our case it is only the method: get_vat( ).
We implement it:
We save and activate the class. If we have not activated the (simple) enhancement
implementation before, we have to activate it now. Now, we return to the program:
We run the program, and what do we get? The result is a percentage of four percent.
And this is because the fallback class is not selected, if we have an active BAdI
implementation.
As a next step, we create another BAdI implementation, this time with the VAT rate of
Great Britain. To make our example more like real world programming, we create
another (simple) enhancement implementation, that is another container. This is
because implementing the taxes for different countries most probably belongs to
different projects and because the structure of the (simple) enhancement
implementations should mirror the project structure.
We navigate to our enhancement spot and use the same button as we have done
above. We name the simple enhancement implementation z_ei_bad_calc_gb, the BAdI
implementation z_bdi_calc_vat_gb, and the implementing class Z_BDI_CALC_VAT_GB.
The implementation of the method get_vat is the same as for the USA except for the
VAT rate, which is 16,5% now. After saving and activating the enhancement
implementation and the class we return to the program and run it again.
We confirm and get to the next screen. Obviously, the filter is now visible as a
property below the BAdI. After activating the enhancement spot, we double click
Implementation and navigate to the respective BAdI implementation by doubleclicking the respective row in the table of BAdI implementations.
We switch to the change mode, click the triangle in front of the BAdI implementation
in the tree and then double-click the filter icon below. In the next window we select
the Combination icon, select "Country" as filter and confirm:
Double-clicking the row below "Combination 1" leads us to the next window:
As I have told you above, adding or changing a filter value of a BAdI implementation
is part of the implementer's role.
After we have activated the (simple) enhancement implementation, we navigate back
to the spot. Apparently, the other implementation, that is the one for USA needs also
the respective filter value. So we go to the respective (simple) enhancement
implementation and change the BAdI implementation in an analogous manner. The
respective filter value for this country is 'US'. I skip the description of how to do this,
because what we do is identical to what we have done before when creating the filter
value for the BAdI implementation z_bdi_calc_vat_gb. We must take care that we do
not forget to activate the (simple) enhancement implementations and to select the
property "Implementation is active" for every BAdI implementation.
Now it is time to return to our program and adapt it to the modified BAdI (this is also
the task of the BAdI provider). Running the syntax check shows you that you need to
have a filter parameter in the GET BADI command if the BAdI you try to instantiate is
defined with a filter. The requisite addition to the GET BADI command is FILTERS. It is
after this keyword that you insert the name of the BAdI filter and a value the filter is
compared to. Of course, we also have to take care that an appropriate value can be
passed to the GET BADI routine:
If you pass "GB" to the parameter ctry, you will get a VAT rate of 16,5 percent. If the
value of the parameter ctry is "US", the VAT rate will be 4 percent. When the
parameter ctry has any other value, we will still get a calculated value for the data
field 'percent'. And this is because we have defined a fallback class for our BAdI. The
fallback class is not only selected if no BAdI implementation is available, but also if
none of the existing BAdI implementations meets the filter conditions in the GET BADI
command. Accordingly, we get a VAT rate of 20 percent. And this was the VAT rate we
have implemented in the method get_vat in the fallback class.
And this is the end of this ,. You have now learned how to create a BAdI
implementation for a given BAdI. You know that a (simple) enhancement
implementation is a container for BAdIs and moreover how and also why to assign it
to a (simple) enhancement spot. That is you have understood the way the different
elements of the enhancement framework interact when implementing a BAdI. And, in
the second part; you have learned how to create a filter for a BAdI, how to determine
filter values for BAdI implementations and what the appropriate syntax for calling a
BAdI with a filter is like.
In this , I want to address several topics that center more or less around creating
source code enhancements. At the beginning, I focus on the different use cases in
which developers outside of SAP create an enhancement option. In a next step I
narrow the scope and ask the question which type of enhancement option you should
prefer as an option provider and in which cases a source code enhancement should
be your first choice. As I have already stated , in general SAP recommends the use of
BAdIs. Still the BAdI is no all-purpose weapon. There are situations in which it is
better to use source-code enhancements instead. After sketching these situations I
will show you how to create an enhancement point, how to implement an
enhancement point and how to overwrite an implementation created in another
system without modifications.
Don't worry here about the details of the syntax. At this stage, you should just note
that the code marked as an enhancement section is substituted by a source code
plug-in as soon as one is provided. Obviously it is required by the logic of
enhancement sections that one enhancement section can have exactly one active
implementation.
Let me just restate the main point about the use of source code enhancements: This
enhancement technology is suitable if you want to provide an enhancement option
and cannot or do not want to specify an interface.
In the next dialogue window we enter the name of the enhancement point and the
name of the spot plus the name of the relevant package as shown below.
As a result an enhancement point is inserted into the code before the line where the
cursor was:
This is what an enhancement point looks like. An enhancement point has a name that
is unique within the source code unit it belongs to and is uniquely assigned to an
enhancement spot.
There we are. We choose the right mouse menu on the line where the enhancement
point is and select Create in the submenu:
As I have told you have first to provide a container for the source plug-in, that is an
enhancement implementation. Let us call our enhancement implementation
ei_my_implementation. Of course you should not forget the explanatory text. It is
possible to create a composite enhancement implementation by using the Create
icon. But it is not necessary, and so we do without this meta-container here. And
there we are:
Before inserting some code just note that the source code plug-in itself is not named.
It is by assigning an enhancement implementation to an enhancement point that a
source code plug-in comes into being. We just enter the code: WRITE
'implementation'.
After the code for the source code plug-in is supplied we should activate it by
selecting the respective button:
By using the respective entries in the context menu you can also change and delete
source code plug-ins. But you should keep in mind: You should not touch source code
plug-ins created by SAP as this would mean to modify a SAP object, in this case, the
respective (simple) enhancement implementation. If a source code plug-in created by
SAP does not meet your requirements, you should replace it in the way just shown in
the last use case. So you should change and delete only the source code plug-ins you
have created yourself. Instead of deleting an source code plug-in created by SAP you
should replace it by an empty source code plug-in. Again, this is the way to avoid a
modification.
Summary
By now you should have learned a lot of different things about the source code
enhancement technology. Let us first consider the definition part or the role of the
enhancement option provider. You know the use cases for this enhancement
technology: As an option provider source code enhancements are the means of
choice if you do not know the interface of the enhancements to be made. You can
also create an enhancement point as a modification and add the rest of the code you
need to a source code plug-in assigned to this enhancement point. This helps keeping
unavoidable modifications small. Apart from these use cases, the enhancement
technology recommended by SAP, in general, is to define a BAdI.
As to the implementing part, you know: