step by step badi

37
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 BADI’s 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

Upload: pradeepta-kumar-sethi

Post on 08-Nov-2014

369 views

Category:

Documents


26 download

DESCRIPTION

ABAP badi creation steps

TRANSCRIPT

Page 1: Step by Step BADI

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 BADI’s 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         

Page 2: Step by Step BADI

User defined BADI’s:

i.  First define a Business Add-In, application developer creates an interface for the add-in. ii. Enhancement management creates an adapter class that implements the interface and thus

provides the interface for implementation by the customer, partner and so on.  iii. The programmer/developer creates an instance of the adapter class in the application program

and calls the corresponding method at the appropriate time.

Standard BADI’s:

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. Control, the adapter class calls the active implementations 2. 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. 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 doesn’t contain any functionality. Instead you can add-on functionality onto these hooks. 

b.  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

Page 3: Step by Step BADI

activate the implementation of the enhancement. The enhancement’s 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 BADI’s 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.

2. Enter the BADI name and choose create

       

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

Page 4: Step by Step BADI

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.

Page 5: Step by Step BADI

6. Save and activate the interface and navigate back to the Business Add-in definition. Now in the BADI screen, displays the method you have created for the interface. When you maintain the interface methods, corresponding executing class (Adapter class) is generated.

7. 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. BADI’s 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.

Page 6: Step by Step BADI

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.

Page 7: Step by Step BADI

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.

7. 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.

8. Following is the code for the class ZCL_CONVERSION_BADI_IMPL method CONVERSION

Method ZIF_EX_BUSINESSADDIN~CONVERSION.translate parameter to upper case.endmethod.

Calling BADI in the Application

1. 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 doesn’t know which implementations are called.

2. 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 handlerclass: cl_exithandler definition load.

Page 8: Step by Step BADI

* Interface Referencedata: badi_interface type ref to ZIF_EX_BUSINESSADDIN.* Stringdata: 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. 

2. In the enhancement definition, all the methods created in the enhancement’s interface need to have filter value as their importing parameter. The application program provides the filter values for the implementation method. 

3. 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.

Multiple use Badi

1. There are multiple use and single use Business Add-ins. This option can be choose at Business Add-in definition. 

2. 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. 

3. There is no sequence control for multiple-use implementations of BAdi’s. Sequence control is technically impossible, at the time of the definition the interface does not know which implementations parameters will be change the implementations. 

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.

Page 9: Step by Step BADI

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

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.

2             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.

Page 10: Step by Step BADI

 

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

Page 11: Step by Step BADI

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.

Page 12: Step by Step BADI

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.

Page 13: Step by Step BADI

Enter the Implementation name. Press enter

(b) Or go to T.code SE19.

Page 14: Step by Step BADI

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. 

Page 15: Step by Step BADI

 Now create the following code , using the created BADI 

Page 16: Step by Step 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.

Page 17: Step by Step BADI

 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 add-ins, 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.

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

Page 18: Step by Step BADI

Implementing BADI for the transactions VL02 & MM02

Introduction to BADI  

1. Based on OOPS concept. 2. No access key required. 3. All BADI’s 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’ 

Page 19: Step by Step BADI

 

 

Step 2:

Then according to the requirement run the transaction. In this example transaction code is VL02.

Run the transaction VL02. As in 1st 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).  

Page 20: Step by Step BADI

 

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

Page 21: Step by Step BADI

CU_CONFIG_DELEGATION 

1st screen of transaction VL02. 

 

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. 

 

Page 22: Step by Step 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. 

Page 23: Step by Step BADI

 

Press F8. 

 

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

Page 24: Step by Step BADI

 

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. 

Page 25: Step by Step 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.

Page 26: Step by Step BADI

 

Under the method ‘GET_INSTANCE’ put break point on a function module called

CALL METHOD CL_EXITHANDLER=>GET_CLASS_NAME_BY_INTERFACE’ 

Page 27: Step by Step BADI

 

Step 2: 

Then according to the requirement run the transaction. In this example transaction code is MM02.

Run the transaction MM02. As in 1st 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).  

 

Press F8 to get the BADI used.

Page 28: Step by Step BADI

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 

Page 29: Step by Step BADI

Press enter to proceed.

 

BADI used. 

BADI_MATERIAL_OD

ECM_EXIT

BADI_LAYER

GOS_SRV_SELECT

Page 30: Step by Step BADI

BADI_MATERIAL_OD

ECM_EXIT 

 

Change the description line and click on SAVE icon. 

 

Page 31: Step by Step BADI

 

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. 

Page 32: Step by Step BADI

 

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.

Page 33: Step by Step BADI

 

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.

Page 34: Step by Step BADI

 

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.