Sunteți pe pagina 1din 34

Understanding Business Add-ins (BADI)

Basic concept SAP has introduced new enhancement technique Business Add-ins from release 4.6A. Business Add-in is the new enhancement technique based on ABAP Objects. BADI is an exit point in a source that allows specific industry sectors, partners, and customers to attach additional software to standard SAP source code without modifying the original object. The users of Business Add-ins can customize the logic according to requirement or they can use the standard logic one available. 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. Basic skills required Work Experience/Knowledge on ABAP Objects (Object orientation of ABAP) is mandatory. Experience on SAP enhancement technique.

BADI in detail Business Add-ins infrastructure is multi-level system landscape (SAP, partner, customer solutions, as well as country versions, and industry solutions). Definitions and implementations of Business Add-ins at each level within system infrastructure. Different Views The different views of the BADIs are:

1. Definition view, Application Programmer can predefine the exit points in the source in which specific industry sector customers can attach additional software to standard SAP source code without having to modify the original object. 2. Implementation view, the users of Business Add-ins can customize the logic they need or use a standard logic if available.
Architecture

User defined BADIs:

i. ii. iii.

First define a Business Add-In, application developer creates an interface for the add-in. Enhancement management creates an adapter class that implements the interface and thus provides the interface for implementation by the customer, partner and so on. The programmer/developer creates an instance of the adapter class in the application program and calls the corresponding method at the appropriate time.

Standard BADIs:
i.

For Standard Business Add-ins, the interface and adapter class will be predefined by SAP. The adapter class that implements the interface and provides the interface for implementation by the customer, partner specific to business.

Each Business Add-in will have one interface and an adapter class that implements interface. Depending on the business requirement user will implement the interface. The generated class (Adapter class) has the following tasks:
1. 2.

Control, the adapter class calls the active implementations Filtering, If the Add-in has to be executed under certain conditions, then the adapter class ensures that only certain implementations will be executed.

Technical Details
a.

b.

BAdIs are contained in the system and are fully operational as of Release 4.6B. SAP creates Add-ins for specific programs, menus, and screen enhancements for standard R/3 applications. This Add-ins doesnt contain any functionality. Instead you can add -on functionality onto these hooks. Customers can find the enhancements in their system in the implementation guide and in the component hierarchy. If customer wishes to use a Business Add-in, he has to first create an implementation. The customer must implement the methods and the enhancements, and afterwards activate the implementation of the enhancement. The enhancements active components are then called at runtime.

c.

Business Add-in contains an interface and other additional components such as function codes for menu enhancements. Business Add-ins also includes enhancements for screens. The enhancement, interface and generated classes are all located in the appropriate application development namespace. Business Add-in implementations are created in the respective implementation namespace.

***********************

Defining and Implementing Business Add-ins (BADI) (Step-by-step with screenshots)


Defining a Business Add-in SAP provides the BADIs where are applicable in the standard applications. Application programmer whoever wishes to have a Business Add-ins in a particular program can define the interface for an enhancement in the Business Add-in builder. Programmer has to program the interface call in the program at the appropriate place. Customers can select the add-in and implement it accordingly to their business needs.

1. From SAP menu, choose Tools -> ABAP Workbench -> Utilities -> Business Add-ins or
transaction code SE18. The example, which is illustrated, is the string conversion in the program. And giving the provision to the users to determine themselves how their strings are to be converted. Application developer define an enhancement, consists of interface with a method with changing parameter used to pass the string. Enter the BADI name and choose create

2.

3. Enter the short text, choose the interface tab.

4. Double click on the interface name field. The system branches to the class builder.

5. In the class builder assign a method to the interface and define a parameter with the attributes.

6. Save and activate the interface and navigate back to the Business Add-in definition. Now in the 7.
BADI screen, displays the method you have created for the interface. When you maintain the interface methods, corresponding executing class (Adapter class) is generated. Save your entries and document the description of the Business Add-in. Documentation is important for the users to understand the purpose of the Add-in.

Implementation of BADI

1. The list of Business Add-ins available in the system can be found through SAP Reference
Implementation guide (IMG) or in component hierarchy. BADIs definition is included in IMG so that the customer/partner can create suitable, company-specific implementations

2. In the SAP menu, choose ABAP Workbench -> Utilities -> Business Add-ins or transaction code SE19. 3. Enter the implementation name and click on the create button.

4. Enter the BADI name

5. Enter the short description for the BADI implementation and implement the interface in the class
appearing in the BADI implementation screen.

6. Double click on the implementation class and insert the desired source code for the
implementation between the method ZIF_EX_BUSINESSADDIN~CONVERSION. And Method. In this particular example enter the statement translate parameter to upper case. Save and activate your entries and return to the change implemention screen. Choose Activate, now you can use this implementation when the application program is executed. Several implementations may exist for a Business Add-in but that is not used in multiple use basis. However only one implementation can be activate at any one time. But in case of multiple use of the BADI, we can have multiple implementations activate. The instance generation of the implementing class must set the attribute as public and not as private, protected or abstract. System will give dump if you do so. Following is the code for the class ZCL_CONVERSION_BADI_IMPL method CONVERSION

7.

8.

Method ZIF_EX_BUSINESSADDIN~CONVERSION. translate parameter to upper case. endmethod. Calling BADI in the Application
1.

2.

When we define BADI, enhancement management generates a class that implements the interface. The application developer uses a factory method to create an instance of adapter class in the application program and calls corresponding method. The adapter class method generated by the enhancement management decides by checking the entries in the table whether one or several active implementations need to be called. If required, the implementations are subsequently executed. The application program ensures only the adapter class method is called. The application program doesnt know which implementations are called. Call the string conversion Business Add-in, the program calling the Business Add-in. Following is the ABAP source code

REPORT ZMPTEST_BADI. * Declaring the handler class: cl_exithandler definition load. * Interface Reference

data: badi_interface type ref to ZIF_EX_BUSINESSADDIN. * String data: w_str(15) type c value 'baddi test'. ************************************************* ****Start of Selection Event..................... ************************************************ start-of-selection. call method cl_exithandler=>get_instance changing instance = badi_interface. write: / 'Please click here'. ************************************************* ****At line-selection Event..................... ************************************************ at line-selection. write: / 'original word', w_str. if not badi_interface is initial. call method badi_interface->conversion changing parameter = w_str. endif. write: / 'Converted word', w_str. Filter dependent Badi
1. Business Add-in definition level (for example a country, industry sector) we can have filter dependent option. If an enhancement for country specific versions then it is likely that different partners can implement this enhancement. The individual countries can create and activate their own implementation. In the enhancement definition, all the methods created in the enhancements interface need to have filter value as their importing parameter. The application program provides the filter values for the implementation method. Filter dependent BAdi is called using one filter value only, it is possible to check active implementation for the filter value using the function module SXC_EXIT_CHECK_ACTIVE.

2.

3.

Multiple use Badi


1. 2. There are multiple use and single use Business Add-ins. This option can be choose at Business Addin definition. The distinction is base on the procedure or event character of an enhancement. In the first case the program waits for the enhancement to return a return code. Typical example is benefit calculation in HR depending on the implementation, alternative calculations can be executed. In case of multiple use add-ins, an event that may be interest to other components in program flow. Any number of components could use this event as a hook to hang their own additional actions on to. There is no sequence control for multiple-use implementations of BAdis. Sequence control is technically impossible, at the time of the definition the interface does not know which implementations parameters will be change the implementations.

3.

4.

The concept of multiple use of the Business Add-in is that has been implemented once already can be implemented again by right of the software chain.

**************************************************

Defining and Implementing Business Add-ins (BADI) (Step-by-step with screenshots)


Business add-ins are enhancements to the standard version of the system. They can be inserted into the SAP System to accommodate user requirements too specific to be included in the standard delivery. Two different views are available:
1.

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.

Steps for Defining BADI: Go to transaction SE18 and create a BADI Definition.

Enter the description of the definition. The name of the interface will be automatically proposed.

Save

Double click on the interface YIF_EX_H387_GET_MATNRDATA . Enter the name of the method you want to create.

Click the Parameters pushbutton to create parameters for the method.

Save and activate it. Steps for BADI Implementation: This can be done in any of the following way: (a) On the menu bar of the initial screen of SE18 - Implementation -- Create.

Enter the Implementation name. Press enter (b) Or go to T.code SE19.

A popup window will ask you for the definition name. Enter the name of the BADI definition which you have created. Press Enter.

Enter the description for the implementation. Then save and activate it. Double click on the method name. Write the following code. Save and activate it.

Now create the following code , using the created BADI

Note: The above example is Single implementation. For multiple implementations, define an add-in and select the Multiple Use checkbox from the Attributes tab.

We can differentiate between single-use and multiple use Business Add-Ins. The distinction is based on the procedure or event character of an enhancement. In the first case, the program waits for the enhancement to return something, usually a return code. A typical example could be a benefit calculation in HR. Depending on the implementation, alternative calculations can be executed. With multiple use addins, an event that may be of interest to other components is processed in program flow. Any number of components could use this event as a hook to hang their own additional actions on to. Note: The system does not check whether the class or method specified in BADI implementation actually exists. If a class or method does not exist, a runtime error occurs when using the function in the formula builder.

********************************

Implementing BADI for the transactions VL02 & MM02


Introduction to BADI
1. 2. 3.

Based on OOPS concept. No access key required. All BADIs can be seen in a class CL_EXITHANDLER.

Step 1: Run the transaction SE24. Under object type put the class name CL_EXITHANDLER. Click on display button.

Under this class CL_EXITHANDLER select the method GET_INSTANCE and double click.

Under the method GET_INSTANCE put break point on a function module called CALL METHOD CL_EXITHANDLER=>GET_CLASS_NAME_BY_INTERFACE

Step 2: Then according to the requirement run the transaction. In this example transaction code is VL02. Run the transaction VL02. As in 1 step we have putted a break point, that function module will give all BADI used by the transaction in each screen and activity on the application (VL02).
st

Under the parameter EXIT_NAME this debugger screen will give all BADI name for each screen.

Each time press F8, you will get all BADI used for the screen. After that system will go for next screen. BADI NAME: EHS_DG_001 LE_SHP_DELIVERY_PROC LE_SHP_PRICING BADI_LAYER

CU_CONFIG_DELEGATION 1 screen of transaction VL02.


st

Step 3: Choose your BADI name and you can see the detail in transaction SE18. Lets take a BADI BADI_LAYER. Click on display button.

Press F8 to get the details of the corresponding BADI.

Here we can get the attribute and interface details of the BADI. As this one is screen BADI sub-screen tab also is there.

Step 4: To implement the BADI, we have transaction SE19. To create new BADI to implement the put your BADI name here. If the BADI is an enhancement-point then put the BADI name in option NEW BADI and if only BADI then put the name in CLASSIC BADI.

Give the BADI name and click on create button.

Press F8.

Again press F8. Give an implementation name. Let it be ZTTTTT

Give the description and select a suitable method double click to get into the method to put the ABAP code.

To edit an implemented BADI the below portion is used. Click on the change button to edit the BADI.

EXAMPLE: To change the description of a material in transaction MM02. Step 1: Run the transaction SE24. Under object type put the class name CL_EXITHANDLER. Click on display button.

Under this class CL_EXITHANDLER select the method GET_INSTANCE and double click.

Under the method GET_INSTANCE put break point on a function module called CALL METHOD CL_EXITHANDLER=>GET_CLASS_NAME_BY_INTERFACE

Step 2: Then according to the requirement run the transaction. In this example transaction code is MM02. Run the transaction MM02. As in 1 step we have putted a break point, that function module will give all BADI used by the transaction in each screen and activity on the application (MM02).
st

Press F8 to get the BADI used.

BADI name before calling the main screen of MM02. BADI_SCREEN_LOGIC_RT W_RETAILSYSTEM_IDENT

Press enter to get into the details.

BADI name after calling the main screen of MM02. BADI_MATERIAL_OD

Press enter to proceed.

BADI used. BADI_MATERIAL_OD ECM_EXIT BADI_LAYER GOS_SRV_SELECT

BADI_MATERIAL_OD ECM_EXIT

Change the description line and click on SAVE icon.

BADI name: BADI_GTIN_VARIANT BADI_MATERIAL_CHECK EHSS_SPEC_CHECKS Step 3: Run the transaction SE18 to see the details of BADI.

Click on display button to see the methods declared in that.

Choose the method where the material description is defined.

Step 4: Run the transaction SE19 and create an implementation for the corresponding BADI. Click on create button to create an implementation.

Give a name for the implementation.

Give the description. Click on save icon and double click on the method chosen.

On a double clicking system will provide you the editor to write the code.

Code is DATA:WA1 TYPE SHORT_DESC. DATA: WA TYPE SHORT_DESC. WA-MAKTX = 'HELLO'. LOOP AT STEXT INTO WA1. CONCATENATE WA1-MAKTX WA-MAKTX INTO WA1-MAKTX. MODIFY STEXT FROM WA1. ENDLOOP. Note: activate the program and the implementation.