+ All Categories
Home > Documents > Defining a Business Add-In - skynet.beusers.skynet.be/am261047/SAP/ABAP/Defining a Business...

Defining a Business Add-In - skynet.beusers.skynet.be/am261047/SAP/ABAP/Defining a Business...

Date post: 09-Jun-2018
Category:
Upload: vuongtu
View: 213 times
Download: 0 times
Share this document with a friend
25
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. 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. 2. 2. Enter a name with a maximum of 20 characters for the Business Add-In. 3. 3. Choose Create. 4. 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.
Transcript
Page 1: Defining a Business Add-In - skynet.beusers.skynet.be/am261047/SAP/ABAP/Defining a Business Add... · Web viewUse An application developer who wishes to have a Business Add-In in

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.

Procedure1. ...

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.

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

3.        3.      Choose Create.4.        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.

Option: Meaning:

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

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

Filter-Dependent 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.        5.      Choose the Interface tab. The interface name is generated automatically and can be

changed here.

Page 2: Defining a Business Add-In - skynet.beusers.skynet.be/am261047/SAP/ABAP/Defining a Business Add... · Web viewUse An application developer who wishes to have a Business Add-In in

Under the FCodes tab, you can create Menu Enhancements, and under the Subscreens tab you can create Screen Enhancements.

6.        6.      Double-click the interface name field. The system branches to the Class Builder.7.        7.      Confirm that you want to save the entries you have made. Assign a package to the

Business Add-In.8.        8.      Use the Class Builder to assign a method to the interface.

9.        9.      Now define a parameter with the following attributes:

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

Page 3: Defining a Business Add-In - skynet.beusers.skynet.be/am261047/SAP/ABAP/Defining a Business Add... · Web viewUse An application developer who wishes to have a Business Add-In in

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.

2. ...

Page 4: Defining a Business Add-In - skynet.beusers.skynet.be/am261047/SAP/ABAP/Defining a Business Add... · Web viewUse An application developer who wishes to have a Business Add-In in

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.           "Declaration3 data exit type ref to if_ex_businessaddin.      "Interface reference4 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 call7         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 call15         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.

Page 5: Defining a Business Add-In - skynet.beusers.skynet.be/am261047/SAP/ABAP/Defining a Business Add... · Web viewUse An application developer who wishes to have a Business Add-In in

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 <badi instance> is initial. is necessary in this case.

Notes on Usage

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

Page 6: Defining a Business Add-In - skynet.beusers.skynet.be/am261047/SAP/ABAP/Defining a Business Add... · Web viewUse An application developer who wishes to have a Business Add-In in

Implementing a Business Add-In 

A list of the Business Add-Ins available in your system can be found either in the SAP Reference Implementation Guide (IMG) or in the component hierarchy. BAdI definitions are included in the IMG so that the customer/partner can create suitable, company-specific implementations.

In the SAP Reference IMG, BAdI implementations - in addition to BAdI definitions - can be provided. This would be suitable in cases where you can see in advance which functions are required by the customer. Using a BAdI implementation, the customer/partner can simply switch the delivered implementations on or off, as required. In the SAP Reference IMG, choose Execute in front of the name of the BAdI implementation. The icon serves as a switch for activating and deactivating the implementation.

Starting from the name and the documentation of the enhancement, you can create an implementation. During the implementation, the system creates a class that implements the enhancement’s interface. The implementation is a separate transport object and lies within the namespace of the person or organization implementing it.

For the example given here, you are to create an implementation for the string conversion. You need to program the interface method in such a way that, when the add-in is called from the application program, the string is actually converted in the way the add-in user wants it.

To create an implementation, proceed as follows:...

       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.

Page 7: Defining a Business Add-In - skynet.beusers.skynet.be/am261047/SAP/ABAP/Defining a Business Add... · Web viewUse An application developer who wishes to have a Business Add-In in

       4.      Enter a short text describing your implementation on the following screen.       5.      Choose the Interface tab.       6.      Choose ABAP Code as the implementation type.

In addition to ABAP Code, there is also the Formula option. If you choose Formula, the content of a method is determined using the Formula Builder. For more information on this, refer to the section Implementing Methods Using the Formula Builder.

       7.      Navigate to the Class Builder by double-clicking the method. You must first enter a package before the Class Builder is displayed.

       8.      Insert the desired source code for the implementation between the method if_ex_businessaddin~method. and endmethod. statements that already exist.

In our particular example, you could enter the statement translate parameter to upper case.

       9.      Save your entries and return to the Change Implementation screen.   10.      Choose Activate. You may now use this implementation when the application program

is executed.

Several implementations may exist for a Business Add-In that is not used on a multiple basis. However, only one implementation can be active at any one time.What is also important is that you must declare the instance generation of the implementing class (Attributes tab) as public and not as private, protected, or even abstract. If you do this, the system will return short dumps at runtime.

 

Page 8: Defining a Business Add-In - skynet.beusers.skynet.be/am261047/SAP/ABAP/Defining a Business Add... · Web viewUse An application developer who wishes to have a Business Add-In in

Menu Enhancements 

Menu enhancements with function codes are provided for in the user interfaces. These function codes must adhere to the form /namensraum/+<...>, just like in the enhancement technique SMOD/CMOD. These function codes are assigned to an enhancement. Only when there is an active implementation of the assignment do they appear in the menu.

The application developer reserves specific function codes for customers when defining a Business Add-In and assigns them in the Menu Painter in the appropriate menu lists. The application developer must also ensure that these menu options are queried in the application program and that the corresponding add-in method is also called. Customers can take advantage of menu enhancements by creating a new implementation, choosing a text for the menu option, and then programming the method used to determine what action is performed when the menu enhancement is called.

Menu enhancements can only be used for single-use add-ins (not multiple-use add-ins) that are not filter-dependent. Currently, menu enhancements can only be created in conjunction with program enhancements (interfaces).

To create a menu enhancement, proceed as follows:...

       1.      Create the definition of an add-in and define its interface.       2.      Choose the FCodes tab.       3.      Enter the name of your program, the function code, and a description.

       4.      Call the Menu Painter or double-click on the program name or function code to navigate to user interface maintenance in the Menu Painter. Enter the function code in the appropriate menu list. If you have accessed the Menu Painter directly during add-in definition, you can call the menu lists by choosing Goto ® Object Lists ® Menu Lists.

Calling a Menu Enhancement from the Application Program

The application program should look like this:

(…)case fcode.  when 'SAP'.    (…)  when '+CUS'    call method …

Page 9: Defining a Business Add-In - skynet.beusers.skynet.be/am261047/SAP/ABAP/Defining a Business Add... · Web viewUse An application developer who wishes to have a Business Add-In in

Implementing a Menu Enhancement

To create the implementation of a menu enhancement, proceed as follows:eine Implementierung an und wählen Sie den Registerindex Fcodes

       1.      Create an implementation and choose the FCodes tab. All data adopted from your Business Add-In's definition is displayed here. You can make entries for the implementation on the right. You can also double-click the first input field. The following dialog box appears:

Here you may enter a text for your function code, the name of an icon, a text for the icon, and a short description.The actions that you want the system to perform after the pushbutton is chosen must be programmed in the appropriate method, either manually or using a default source code that has been provided for this purpose. Menu enhancements only become visible after the implementation has been activated and the application program that calls the Business Add-In has been executed.

Page 10: Defining a Business Add-In - skynet.beusers.skynet.be/am261047/SAP/ABAP/Defining a Business Add... · Web viewUse An application developer who wishes to have a Business Add-In in

Screen Enhancements Besides program and menu enhancements, you can also create screen enhancements for Business Add-Ins. Screen enhancements are not supported, however, for Business Add-Ins designed for multiple use.With the old enhancement technique based on customer exits, X function groups were used for data retention and data processing purposes. These tasks are now performed by a user function group or a module pool if you implement a screen enhancement using BAdIs. The instance of the implementing class is only used for data transport.

The name of the function group lies in the namespace of the implementing person/user. The 'X' that was necessary at the beginning of a function group in case of customer exits is now no longer required and therefore eliminated.

An instance of the BAdI class must be passed to the user of the BAdI to allow that user to get the data to be displayed on the screen. For this purpose, the instance is saved in a public static read-only attribute DYNPRO_INSTANCE of the BAdI class. This attribute is generated. A public static method SET_INSTANCE_FOR_SUBSCREEN sets the attribute on the application side to the parameter passed. Using the method GET_INSTANCE_FOR_SUBSCREEN, the parameter is then read on the user side. Different subscreen states can be represented by different instances.

Page 11: Defining a Business Add-In - skynet.beusers.skynet.be/am261047/SAP/ABAP/Defining a Business Add... · Web viewUse An application developer who wishes to have a Business Add-In in

The relationships shown between the calling program, the classes and the user function group or module pool are illustrated below by means of an example.Example:Flight data is to be displayed in a transaction. First, the user enters the airline carrier, the flight number, and the fight date.

The required data is then displayed.

At the specific request of the customer, you are to enhance this function to allow the user to additionally display the time of departure and arrival as well as the departure and destination airport.The definition of a Business Add-In containing the functionality required is then delivered to the customer. If the customer creates an implementation, the system displays additional fields.

Page 12: Defining a Business Add-In - skynet.beusers.skynet.be/am261047/SAP/ABAP/Defining a Business Add... · Web viewUse An application developer who wishes to have a Business Add-In in
Page 13: Defining a Business Add-In - skynet.beusers.skynet.be/am261047/SAP/ABAP/Defining a Business Add... · Web viewUse An application developer who wishes to have a Business Add-In in

Defining Screen Enhancements For general information on how to define Business Add-Ins, see Defining Business Add-Ins. ...

       1.      Create the following methods.

The methods PUT_DATA_TO_SCREEN and GET_DATA_FROM_SCREEN are required for data transport. These methods are called from within the program of the application at PBO or PAI (see below).You could create the methods with the following parameters for the example we have used.

Method: Parameter: Type: Reference type:PUT_DATA_TO_SCREEN FLIGHT IMPORTING SFLIGHT

GET_DATA_FROM_SCREEN FLIGHT EXPORTING SFLIGHT

       2.      Create an instance attribute in the interface. This attribute is used for passing data.

       3.      Write the code for the call of the screen enhancement in the program of the application:Top Include:DATA: program Type program,      dynpro Type dynnr.      exit type ref to if_ex_badi_screen

The variable for the object reference is created using data and typed to the interface.Time PBO:MODULE initialize OUTPUT.CLEAR: sflight, ok_code.

Page 14: Defining a Business Add-In - skynet.beusers.skynet.be/am261047/SAP/ABAP/Defining a Business Add... · Web viewUse An application developer who wishes to have a Business Add-In in

 IF exit IS INITIAL.  CALL METHOD cl_exithandler=>get_instance    CHANGING      instance = exit. ENDIF. CALL METHOD cl_exithandler=>set_instance_for_subscreens    EXPORTING      instance = exit.ENDMODULE.

The factory method is used to create an instance of the adapter class. You then declare the instance using the public static method SET_INSTANCE_FOR_SUBSCREEN to allow the data for display on the screen to be used in the function group of the user or in the module pool. MODULE data_for_subscreen OUTPUT.

  program = sy-repid.  dynpro = sy-dynnr.  CALL METHOD cl_exithandler=>get_prog_and_dynp_for_subscr    EXPORTING      exit_name       = 'BADI_SCREEN'      calling_program = program      calling_dynpro  = dynpro      subscreen_area  = 'SUB'    IMPORTING      called_program  = program      called_dynpro   = dynpro.  CALL METHOD exit->put_data_to_screen    EXPORTING      flight   = sflight    EXCEPTIONS      reserved = 01.ENDMODULE.

Zeitpunkt PAI:MODULE user_command_0200 INPUT.

  CASE save_ok.    WHEN 'BACK'.      SET SCREEN 100.    WHEN 'SAVE'.      PERFORM save_flights.    WHEN '+EXT'.      CALL METHOD exit->get_data_from_screen        IMPORTING          flight      = sflight

Page 15: Defining a Business Add-In - skynet.beusers.skynet.be/am261047/SAP/ABAP/Defining a Business Add... · Web viewUse An application developer who wishes to have a Business Add-In in

        EXCEPTIONS          reserved    = 01.  ENDCASE.

ENDMODULE.The method GET_PROG_AND_DYNP_FOR_SUBSCR and the input/output parameters specified above are used to determine the name of the customer program and the name of the subscreen. The method PUT_DATA_TO_SCREEN called at PBO time as well as the method GET_DATA_FROM_SCREEN called at PAI time are used to transport the data to be displayed. These methods are implemented by the user.

When you define a screen enhancement, you are strongly recommended to provide sample code for the methods PUT_DATA_TO_SCREEN and GET_DATA_FROM_SCREEN. This code is automatically copied when you create an implementation and can be added to if required. The user of the BAdI definition should not be responsible for the data transport. In this case, the sample code would look like this:

method IF_EX_BADI_SCREEN~PUT_DATA_TO_SCREEN .  me->if_ex_badi_screen~flight = flight.endmethod.method IF_EX_BADI_SCREEN~GET_DATA_FROM_SCREEN .  flight = me->if_ex_badi_screen~flight.endmethod.The data to be displayed is assigned in the methods PUT_DATA_TO_SCREEN and GET_DATA_FROM_SCREEN using the interface attribute FLIGHT.

       4.      In the Screen Painter, create a subscreen area on the screen of the calling program, and assign the name 'SUB' to it. For more information on how to create subscreens, see

Subscreens.       5.      In the BAdI Builder, choose the Subscreens tab, and enter the calling program, the

screen number, and the subscreen area.

 

Page 16: Defining a Business Add-In - skynet.beusers.skynet.be/am261047/SAP/ABAP/Defining a Business Add... · Web viewUse An application developer who wishes to have a Business Add-In in

Implementing Screen Enhancements For general information on how to implement Business Add-Ins, refer to the section Implementing Business Add-Ins. The user of the screen enhancement should perform the following steps:...

       1.      Create a screen of the Subscreen type. Arrange the required fields on the screen.       2.      Write the program for the screen by creating either a module pool or a function group.

The program could have the following contents, for example:Topinclude:

DATA: exit TYPE REF TO if_ex_badi_screen,      flight TYPE sflight.TABLES sflview.

At PBO time:MODULE status_0100 OUTPUT.  IF exit IS INITIAL.    CALL METHOD cl_exithandler=>get_instance_for_subscreens     CHANGING       instance  = exit     EXCEPTIONS       OTHERS    = 6.  ...  ENDIF.  CALL METHOD exit->get_data_from_screen    IMPORTING      flight   = flight    EXCEPTIONS      reserved = 1      OTHERS   = 2.  ...  SELECT SINGLE * FROM sflview    WHERE carrid = flight-carrid AND          connid = flight-connid AND          fldate = flight-fldate.  ..ENDMODULE.

At PAI time:If data has been changed, the method PUT_DATA_TO_SCREEN is called at PAI.

MODULE user_command_0100 INPUT.  CALL METHOD exit->put_data_to_screen    EXPORTING      flight = flight    EXCEPTIONS      reserved = 1      OTHERS = 2.  IF sy-subrc <> 0.

Page 17: Defining a Business Add-In - skynet.beusers.skynet.be/am261047/SAP/ABAP/Defining a Business Add... · Web viewUse An application developer who wishes to have a Business Add-In in

  ...ENDMODULE.

       3.      Choose the Subscreens tab. Enter the name of the called program and of the subscreen.

       4.      Choose the Interfaces tab.If required, add any lines necessary to the sample code.

Page 18: Defining a Business Add-In - skynet.beusers.skynet.be/am261047/SAP/ABAP/Defining a Business Add... · Web viewUse An application developer who wishes to have a Business Add-In in

Sorting BAdI Implementations Use

The sequence for execution of BAdI implementations can be controlled for BAdIs used on a multiple basis by a sort mechanism.

Procedureen ....

In the BAdI Builder (SE18), choose Utilities ® Sort. Choose Standard Sort if sorting is to take place using numeric sort values. The numeric values are entered in the displayed field Layer Value when you create the implementations and stored in a table. The implementations are executed in accordance with the specified sequence. Choose Special Sort if sorting is to take place using non-numeric sort values. In this case, you need to enter the name of the implementation that will be created in the following step. Proceed as follows if you require special sorting:

       1.      Create an implementation for the BAdI definition BADI_LAYER contained in the delivered product. Enter a BAdI definition as filter value in the Properties tab (the name will be used as a dummy value to begin with).

       2.      Create a screen (in a function group or a module pool). The screen contains, for example, a text field with the name Sort Value and an input field.

       3.      Choose the Subscreens tab of the BAdI implementation and enter the called program and the screen number.

       4.      Choose the Interface tab. The IF_EX_BADI_LAYER interface contains the following methods:

Page 19: Defining a Business Add-In - skynet.beusers.skynet.be/am261047/SAP/ABAP/Defining a Business Add... · Web viewUse An application developer who wishes to have a Business Add-In in

In addition to methods for data transmission of the sort value and for changing the BAdI implementation, the interface also contains a sort method that sorts a table of values in any specified order.

A standard table is passed to this method as a changing parameter. The table contains values only; it does not contain any implementation names. This table contains, for example, inputs for the Sort Value field when you create implementations. The user can maintain any fields as required and sort them according to any specified criteria at runtime.

       5.      Program the method SORT_DATA. Here is an example of simple sorting of numeric values:

Page 20: Defining a Business Add-In - skynet.beusers.skynet.be/am261047/SAP/ABAP/Defining a Business Add... · Web viewUse An application developer who wishes to have a Business Add-In in

       6.      Program the methods for data transmission in the following form (see also Screen Enhancements).

       7.      Program the call for implementations from the application program. The IF_EX_BADI_LAYER interface contains a parameter-free method called TEST for test purposes.

Page 21: Defining a Business Add-In - skynet.beusers.skynet.be/am261047/SAP/ABAP/Defining a Business Add... · Web viewUse An application developer who wishes to have a Business Add-In in

The implementations are executed (for example, in numeric sequence).

Switching Off Sort FunctionTo switch off the sort for the execution of BAdI implementations, choose Utilities ® Sort and finally No Sort. The implementations will now run in an arbitrary sequence in this case. The edit field that was displayed using a subscreen during the execution of a BAdI implementation now disappears. Sorting of BAdI implementations can be switched on again at any time. This does not count as a modification to the standard version. The BAdI definition is not changed. Switching off or making a change, on the other hand, counts as a modification.  


Recommended