0% found this document useful (0 votes)
424 views8 pages

BADI

BADI - Business Add-Ins are enhancements to the standard version of the code of SAP. They can be inserted into the system to accommodate user requirements too specific to be included in the standard delivery. SAP guarantees the upward compatibility of all Business Add-In interfaces.

Uploaded by

Josif Lal
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
424 views8 pages

BADI

BADI - Business Add-Ins are enhancements to the standard version of the code of SAP. They can be inserted into the system to accommodate user requirements too specific to be included in the standard delivery. SAP guarantees the upward compatibility of all Business Add-In interfaces.

Uploaded by

Josif Lal
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 8

BADI – Business Add Ins are enhancements to the standard version of the code of SAP.

They
can be inserted into the SAP system to accommodate user requirements too specific to be
included in the standard delivery. Customers can find the possible enhancements (BADIs) in
their SAP system in the Implementation Guide (IMG) and in the component hierarchy. BADI
definitions are included in the IMG so that the customer can create suitable, company-specific
implementations. SAP guarantees the upward compatibility of all Business Add-In interfaces.
Release upgrades do not affect enhancement calls from within the standard software nor do they
affect the validity of call interfaces.

Two different views are available:

• In the definition view, an application programmer defines exit points in a source that
allow specific industry sectors, partners, and customers to attach additional coding to
standard SAP source code without having to modify the original object.
• In the implementation view, the users of Business Add-Ins can customize the logic they
need or use a standard solution if one is available.

Definition of A BAdI

SAP application developer actually defines a Business Add-In available to an application


program. Tcode SE18 can also be used to see the definition of existing badi .The following are
the steps in defining a BADI:

1. Using the SAP BADI builder, the SAP application developer defines an enhancement (BADI).
It consists of an interface with a method.
2. The interface name is generated automatically and can be changed. The system branches to the
Class Builder.
3. Using the Class Builder, the developer assigns a method to the interface.
4. For each method, he defines parameters. Parameters can either be importing or changing and
these are the fields available for customer to use for enhancements. Importing parameters are the
fields being passed from the calling program and changing parameters are the fields being passed
back to the program.
5. The Business Add-In is then activated in the Class Builder.

Note: Documentation of the BADI usually provides the list of parameters and their definition.
For example, for method DETERMINE_EXTPO, the available parameters are:
Importing
o ITEM_DATA Item data (is a structure)
Changing
o BBP_EXTPO_GL
o If the field has the value X, the request is subject to the extended classic scenario.
o If the field is empty, the request is not subject to the extended classic scenario.
Implementation of a BAdI

If a customer wishes to use a Business Add-In, he or she first creates an implementation. The
customer must implement the methods and the enhancements. You need to program the interface
method in such a way that, when the add-in is called from the application program, it will
perform the specific action the customer intends. The following are the steps customer can
follow in implementing a BADI:
1. In the SAP menu, choose ABAP Workbench ® Utilities ® Business Add-Ins (transaction
SE19) or double-click the corresponding activity in the Implementation Guide (IMG).

2. Enter a name for the implementation and then click the Create pushbutton.
3. Enter the name of the add-in for which you want to create an implementation for in the dialog
box that appears. Choose the Interface tab.
4. Choose ABAP Code as the implementation type.
5. Navigate to the Class Builder by double-clicking the method. You must first enter a
package before the Class Builder is displayed.
6. Insert the desired source code for the implementation between the method
if_ex_businessaddin~method. and endmethod (statements that already exist) You need to use the
parameters (importing and changing) as fields within the BADI. You can define additional fields
you need in the coding as local data fields.
7. Save your entries and return to the Change Implementation screen.
8. Choose Activate. The enhancement’s active components are then called at runtime.

EXAMPLE (code)

Definition name BBP_EXTLOCALPO_BADI

Implementation Name ZEXTENDEDCLASSIC

Interface name IF_EX_BBP_EXTLOCALPO_BADI


Name of implementing class: ZCL_IM_EXTENDEDCLASSIC

Method DETERMINE_EXTPO
ABAP Code Determination of Control for Extended

METHOD IF_EX_BBP_EXTLOCALPO_BADI~DETERMINE_EXTPO.
DATA: zzecs type zecs. * local data field

*extended classic will be activated only for specific product categories


IF item_data-category eq '420DD2C2CFDF56478E705E352FEC86CB'.
bbp_extpo_gl-bbpexpo = 'X'.
ELSE.

SELECT single * from zecs into zzecs where product eq item_data-


product.
IF sy-subrc eq 0.
bbp_extpo_gl-bbpexpo = 'X'.
ENDIF.

ENDIF.
ENDMETHOD.

Filter-Ddependent BAdI

Business Add-Ins may also be implemented on the basis of a filter value. The application
program provides the filter value for the enhancement method. The filter parameter is defined
within the method when creating the interface. For each method created in the interface of a
filter-dependent enhancement, the filter value must be defined as the importing parameter so that
the application program can provide the filter value to the enhancement method. The method
then selects the active implementation for that value. The filter value is always declared using the
parameter flt_val and is predefined in the list of parameters
For example:
You can use the Business Add-Ins BBP_DOC_CHANGE_BADI to make changes to the
document, after user entry and before saving the document to the database. These changes are
subject to the document-specific checks. The parameter FLT_VAL acts as a filter value that
assigns the BAdI implementation to a particular document type. You can use the BAdI to change
some of these documents:
o Shopping cart (filter value BUS2121 – shopping cart EC)
o Purchase order (filter value BUS2201 – purchase order EC)
o Confirmation (filter value BUS2203 – confirmation of goods/services EC)
o Invoice (filter value BUS2205 – incoming invoice EC)
o Bid invitation (filter value BUS2200 – bid invitation EC)

Calling A BAdI in The Applicat?on Program

When a Business Add-In is created, enhancement management generates a class that implements
the interface. The application developer uses a factory method to create an instance of this
adapter class in the application program and calls the corresponding method, if necessary.
The adapter class method generated by add-in management decides whether one or several active
implementations should be called. If necessary, these implementations are subsequently
executed. The application program ensures only that the adapter class method is called. The
application program does not know which implementations are called.

Bu using following two methods you can find any BAdI for any transaction

Method 1:
Go to Tranaction: SE24.
open class CL_EXITHANDLER
Open the method ” GetInstance”
Put Break point in the statement

call method cl_exithandler=>get_class_name_by_interface

Now execute the Transaction which you need teh BDC it will automatically stops at the the
method. In debugging mode double click on the variable: ” exit_name” It will return the BADI
Name.

Method 2:
find the Package name and go to the transaction SE84.
Enter the package name
inside the left navaigaiton panel there is one option ” Enhancements” click on this enhancement
and then enter the package name and execute it. you will get hte number of enhancement.

Home » ABAP »
Post your Article

Simple sap BADI example


ShareThis

By: rekha | 27 Aug 2007 7:18 am

DEFINING THE BADI

1) execute Tcode SE18.


2) Specify a definition Name : ZBADI_SPFLI
3) Press create
4) Choose the attribute tab. Specify short desc for badi.. and specify the type :
multiple use.
5) Choose the interface tab
6) Specify interface name: ZIF_EX_BADI_SPFLI and save.
7) Dbl clk on interface name to start class builder . specify a method name (name,
level, desc).

Method level desc


Linese;ection instance methos some desc

8) place the cursor on the method name desc its parameters to define the interface.
Parameter type refe field desc
I_carrid import spfli-carrid some
I_connid import spefi-connid some

9) save , check and activate…adapter class proposed by system is


ZCL_IM_IM_LINESEL is genereated.

IMPLEMENTATION OF BADI DEFINITION

1) EXECUTE tcode se18.choose menuitem create from the implementation menubar.


2) Specify aname for implementation ZIM_LINESEL
3) Specify short desc.
4) Choose interface tab. System proposes a name fo the implementation class.
ZCL_IM_IMLINESEL which is already generarted.
5) Specify short desc for method
6) Dbl clk on method to insert code..(check the code in “AAA”).
7) Save , check and activate the code.

Now write a sample program to use this badi method..


Look for “BBB” sample program.

“AAA”

data : wa_flights type sflight,


it_flights type table of sflight.

format color col_heading.


write:/ 'Flight info of:', i_carrid, i_connid.
format color col_normal.

select * from sflight


into corresponding fields of table it_flights
where carrid = i_carrid
and connid = i_connid.

loop at it_flights into wa_flights.


write:/ wa_flights-fldate,
wa_flights-planetype,
wa_flights-price currency wa_flights-currency,
wa_flights-seatsmax,
wa_flights-seatsocc.
endloop.

“BBB”

*&---------------------------------------------------------------------*
*& Report ZBADI_TEST *
*& *
*&---------------------------------------------------------------------*
*& *
*& *
*&---------------------------------------------------------------------*

REPORT ZBADI_TEST .

tables: spfli.

data: wa_spfli type spfli,


it_spfli type table of spfli with key carrid connid.

*Initialise the object of the interface.


data: exit_ref type ref to ZCL_IM_IM_LINESEL,
exit_ref1 type ref to ZIF_EX_BADISPFLI1.

selection-screen begin of block b1.


select-options: s_carr for spfli-carrid.
selection-screen end of block b1.

start-of-selection.
select * from spfli into corresponding fields of table it_spfli
where carrid in s_carr.

end-of-selection.
loop at it_spfli into wa_spfli.
write:/ wa_spfli-carrid,
wa_spfli-connid,
wa_spfli-cityfrom,
wa_spfli-deptime,
wa_spfli-arrtime.

hide: wa_spfli-carrid, wa_spfli-connid.

endloop.

at line-selection.
check not wa_spfli-carrid is initial.
create object exit_ref.
exit_ref1 = exit_ref.

call method exit_ref1->lineselection


EXPORTING
i_carrid = wa_spfli-carrid
i_connid = wa_spfli-connid.

clear wa_spfli.

Business Add-Ins (BAdis) are a SAP enhancement technique based on ABAP Objects. Two
parts - Definition and its Implementation - definition can either be SAP provided or user may
also create it.

How to find BAdi


You can look for BAdi definition in IMG and in component hierarchy. But there are some easier
methods to find a BAdi. They are follows:

Method 1
These steps should enable you to find a BAdi related to any transaction in a matter of minutes.

• 1) Go to the transaction SE37 to find your function module.


• 2) Locate the function SXV_GET_CLIF_BY_NAME.
• 3) Put a break-point there.
• 4) Now open a new session.
• 5) Go to your transaction.
• 6) At that time, it will stop this function.
• 7) Double click on the function field NAME.
• 8) That will give you name of the BAdi that is provided in your transaction.

Method 2

• 1. Goto SE80, open CL_EXITHANDLER (Class)


• 2. Goto Method, GET_INSTANCE
• 3. Set a break point at

CALL METHOD cl_exithandler=>get_class_name_by_interface


EXPORTING
instance = instance
IMPORTING
class_name = class_name
CHANGING
exit_name = exit_name
EXCEPTIONS
no_reference = 1
no_interface_reference = 2
no_exit_interface = 3
data_incons_in_exit_managem = 4
class_not_implement_interface = 5
OTHERS = 6.
CASE sy-subrc.
WHEN 1.
RAISE no_reference.
WHEN 2.
RAISE no_interface_reference.
WHEN 3.
RAISE no_exit_interface.
WHEN 4.
RAISE data_incons_in_exit_managem.
WHEN 5.
RAISE class_not_implement_interface.
ENDCASE.

• 4) Now open a new session.


• 5) Go to your transaction.
• 6) At that time, it will stop this function.
• 7) Double click on the function field EXIT_NAME.
• 8) That will give you name of the BAdi that is provided in your transaction.

Method 3:

• 1. Goto ST05
• 2. Select SQL trace and buffer trace
• 3. Activate trace
• 4. Now run your transaction
• 5. Deactivate trace
• 6. Display trace7. A pop will come
• 8. Enter V_EXT_ACT and V_EXT_IMP as the 2 objects
• 9. Now display the trace results. It will return all the BAPI and enhancement list in order
of their execution.

You might also like