Translate

Sunday, 13 May 2012

Badi Notes

Business Add-Ins

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. Since specific industries often require special functions, SAP allows you to predefine these points in your software.



As with customer exits, 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.



Architecture of the Enhancement Technique

In order to enhance a program, you must first define a Business Add-In. The application developer creates an interface for the add-in. From this, 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 developer then creates an instance of the adapter class in the application program and calls the corresponding method at the appropriate time.



For each Business Add-In you have one interface and an adapter class that implements this. The interface is implemented by the user.
The generated class (Add-In adapter) has the following tasks:
· Control

The adapter class calls the active implementations.
1. · Filtering
If a Business Add-In is to be executed only under certain conditions, the adapter class ensures that only certain implementations will be executed.

This concept ensures mutlple use. Any Business Add-In that has been implemented once already can be implemented again by those groups listed to the right of the software chain shown in the above graphic.
Customers can find the enhancements in their system in the Implementation Guide (IMG) and in the component hierarchy. 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, and afterwards activate the implementation of the enhancement. The enhancement's active components are then called at runtime. Normally, a Business Add-In contains an interface and other additional components such as function codes for menu enhancements. In some cases, Business Add-Ins also include 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.

A Comparison of Different Enhancement Techniques

Due to the necessity of adjusting R/3 to meet the specific needs of a variety of customers, several different enhancement techniques were developed in the past. A short description of each of the various enhancement techniques follows.

Business Transaction Events (Open FI)

The Open FI enhancement technique was developed in the Financial Accounting component. Open FI is based upon the following principles:

Application developers must define their interface in a function module, an assignment table is read in the accompanying (generated) code, and the customer modules assigned are called dynamically.
This technique differentiates between enhancements that are only allowed to have one implementation and enhancements that can call multiple implementations in any sequence desired. Both industry-specific and country-specific enhancements may be defined.
The concepts behind the Business Add-Ins enhancement technique and Open FI are basically the same. However, the two enhancement techniques do differ from each other in the following points:

1. · Open FI can only be used to make program enhancements, that is, you can only enhance source code using Open FI. You cannot enhance user interface elements with Open FI like you can with Business Add-Ins.
1. · Open FI assumes that enhancement will only take place on three levels (SAP - partners - customers), whereas with Business Add-Ins you can create and implement enhancements in as many software layers as you like.
2. · Open FI uses function modules for program enhancements. With Business Add-Ins, ABAP Objects is used to enhance programs.
Enhancements in Transactions SMOD/CMOD

Making enhancements using the transactions SMOD/CMOD has the following disadvantages:
1. · This enhancement technique assumes a two-tiered system infrastructure (SAP – customers).
2. · The naming conventions in effect do not tolerate name extension.

Conclusion:None of the techniques mentioned above can easily be extended to fulfill the requirements of a system infrastructure containing country versions, industry solutions, partners, and customers.Business Add-Ins should be considered generalized Business Transaction Events that can be used to bundle program, menu and screen enhancements into a single add-in. Business Add-Ins can be created and employed in each of the various software levels.

Defining a Business Add-In

Use
An application developer who wishes to have a Business Add-In in a particular program defines the interface for an enhancement in the Business Add-In Builder. In the following step, he or she programs the interface call in the application program at the appropriate place. Customers can then select the add-in and implement it according to their needs.

Procedure
1. ...
1. From the SAP menu, choose Tools ® ABAP Workbench ® Utilities ® Business Add-Ins (transaction SE18).

We would like to explain the procedures using an application program as an example. There is a string conversion in the program. You want the add-in users to determine themselves how their strings are to be converted. The application developer defines an enhancement. It consists of an interface with a method. A changing parameter is used to pass on the string.




Option: Within SAP



Meaning: If the customer selects this option for an Add-In, he or she has no option for creating his or her own implementations for this Business Add-In or for using them. In the input help, Business Add-Ins with this flag are not displayed. For more information on the checkbox Within SAP, refer to the section Definition of a Business Add-In in the Enterprise Core.




Option: Multiple Use



Meaning: The Business Add-In can be set for multiple use. For more information, refer to the section Multiple-Use Business Add-Ins.



Option: Filter-Dependent



Meaning : The implementation of a Business Add-In is dependent on a particular filter value.For more information, refer to the section Multiple-Use Business Add-Ins.
None of the above options is selected.







5. Choose the Interface tab. The interface name is generated automatically and can be changed here.

2. Enter a name with a maximum of 20 characters for the Business Add-In.









3. Choose Create.
4. On the following screen, enter a short text as the description for the Business Add-In.In this example, we are dealing with a simple enhancement.











Under the FCodes tab, you can create Menu Enhancements, and under the Subscreens tab you can create Screen Enhancements.
6. Double-click the interface name field. The system branches to the Class Builder.
7. Confirm that you want to save the entries you have made. Assign a package to the Business Add-In.


8. Use the Class Builder to assign a method to the interface.









9. Now define a parameter with the following attributes:






10. Save and activate your entries. Use the pushbutton Back to navigate back to the Business Add-In definition.

You can now continue with the definition of the Business Add-In by executing activation in the Class Builder.
A table control now appears on the definition screen for the Business Add-In. It displays the method you have created for the interface.
When you maintain the interface methods, the corresponding executing class is generated. The generated code cannot be altered in the initial expansion phase.
11. Save your entries and use the Documentation pushbutton to create a description for your new Business Add-In. Remember that this documentation is very important for users to be able to understand the purpose behind the Add-In. For more information, read the section Documentation of a Business Add-In.

Choose Goto ® Default Coding / Sample Coding if you wish to create default coding and/ or sample coding for the Business Add-In. The default implementation is executed only if no other active implementation is available. This applies also to filter-dependent Business Add-Ins.

When you create default or sample coding, do not forget to save your entries. In this way, the connection between the class and the implementation is set up.

Calling a Business Add-In in the Application Program

When you define a Business Add-In, enhancement management generates a class that implements your 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.

Example:

Having created a string conversion Business Add-In, you would program the call of the Business Add-In into your ABAP source code as follows:

1 Report businessaddin.
2 class cl_exithandler definition load. "Declaration
3 data exit type ref to if_ex_businessaddin. "Interface reference
4 data word(15) type c value 'Business Add-in'. "String to change

5 start-of-selection.
6 call method cl_exithandler=>get_instance "Factory method call
7 exporting "Method
exit name =’BUSINESSADDIN’
8 null instance accepted =’X’
9 changing instance = exit.
10 write:/'Please click here'.

11 at line-selection.
12 write:/ 'Original word: ',word.

13 if not exit is initial.
14 call method exit->method "Add-In call
15 changing parameter = word.
16 endif.
17 write:/ 'Original word: ',word.

In order to be able to call static methods, you must declare the corresponding class in ABAP Objects. This is why the class … definition load statement is necessary for the factory class.
A variable for object reference is also necessary when calling the method. Use data to create it and type it to the interface.

During initialization (line 6), the application developer creates an adapter class instance using the factory method. The instance methods are then called at the time specified.

To improve performance during creation of the instances, you should specify additional parameters for the call in the method GET_INSTANCE of the class CL_EXITHANDLER.
EXIT_NAME: The name of the BAdI definition is assigned to this parameter.

NULL_INSTANCE_ACCEPTED: Whenever the value X is assigned to this parameter, no instance is created if there are no active implementations for this BAdI definition. In this case, the INSTANCE parameter has the value NULL. Using this parameter implies that the method calls of this BAdI may only be called under the condition that this instance is not NULL. The query if not is initial. is necessary in this case.

Notes on UsageThe instance generated through the factory method should be declared as globally as possible or generally be passed as a parameter to ensure that the initialization process must be run as rarely as possible – just once would be best. In no case should you discard the instance as soon as it is generated or repeatedly run the initialization process in a loop.

Within the adapter class interface, required database accesses are buffered locally, so that each access is executed once only. However, repeated initialization makes the buffer useless and dramatically reduces performance.

Due to the local buffering, you can call Business-Add-In methods without having to expect considerable performance restrictions, even if no active implementations exist.

Also, if the definition of the Business-Add-In is filter-dependent, a single instance is sufficient.
However, you should not do without initialization altogether. Even if you could call static methods of the implementing class of the Business-Add-In implementation without an instance, you would lose the benefit of performance improvement through the Business-Add-Ins and the possibility of multiple use. If you switch the method type in the interface from the static method to the instance method at any time in the future, many code adjustments are required. In addition, you can no longer use default code that is provided

Implementing Methods Using the Formula Builder

Use 
You can use the Formula Builder to implement methods for Business Add-Ins without writing a single line of ABAP code. The methods are implemented by means of socalled formulas.

This type of implementation does not require you to have programming knowledge. However, the functions it offers are more restricted than if you implement a method by writing ABAP code. If the range of functions provided by the Formula Builder is not sufficient, you can change the implementation type of the method at any time.

Features
A formula can consist of the following steps:

· Condition
You define a Boolean formula expression whose result can be true or false. This formula expression is a logical condition based on the importing and changing parameters of the method. Depending on whether the condition is true or false, the system triggers different steps. If you do not specify a dependent step for one of these two possibilities, the system continues with the next superior step.

· Substitution
The system replaces the value of a specific parameter with another value which you define as a constant value or by means of a mathematic formula. Substitution is only possible if the method contains changing, exporting or returning parameters.

· Message
The system issues a message. All messages issued are collected in a log table. You define the message variables as constant values or by means of mathematic formulas. The system can only issue a message if you created a log table during method definition.

· ExceptionThe system exits the method. No further steps are executed, and the application program continues in accordance with the exception defined. You can additionally display a message whose variables you define as constant values or by means of mathematic formulas. An exception can only be triggered if the method contains exceptions.

A formula editor is available which you can use to enter formula expressions. After starting the formula editor, you can display information on how to use it by choosing the pushbutton next to the status display (traffic light).

Activities
You implement the method using the BAdI Builder. For information on this topic, see Implementing Business Add-Ins. To implement a method as a formula, choose the Formula implementation type on the Interface tab. Double-clicking the method name takes to to the Formula Builder: BadI Implementation screen.

You can change the implementation type of the method on the Interface tab. You can implement a method both using a formula and using ABAP code. At the runtime of the application program, the system executes the implementation type currently chosen.

You create the necessary steps in the left section of the screen. To do this, choose and then select the appropriate step type from the dropdown list. Using the other icons available or the context menu (which you can call by clicking the right mouse button), you then determine the arrangement and the descriptions of the steps. You can also copy steps to use them as templates for other steps, or you can delete individual steps.

To specify the parameters for the individual steps, double-click the corresponding entry in the left section of the screen. You then enter the data required in the right section of the screen.

Formulas are transported automatically.

No comments: