Show TOC

BAdI: Customer-Defined Functions in the Formula BuilderLocate this document in the navigation structure

Use

You can integrate self-defined functions in the transformation library of the formula builder. This also allows you to make special functions not contained in the transformation library available for frequent use. The Business Add-In RSAR_CONNECTOR is available for this. In this BAdI, you define which class or method your function was implemented in and under which entry the function will be offered in the Formula Builder. The actual implementation of the function takes place in the specified class or method. For more information about using Business Add-Ins (BAdIs), see Business Add-Ins.

Procedure

Implementing the BAdI

  1. To implement a BAdI, follow the instructions in the BAdI documentation. The specific things to look out for when implementing BAdI RSAR_CONNECTOR are described below.

  2. Call transaction SE19. Enter RSAR_CONNECTOR as the name for the Add-In, for which you want to create the implementation.

  3. By double-clicking the method (GET), the class builder appears. You can enter your coding for implementing the enhancement. You can define which entry your function will be displayed with and which category it will be displayed under in the Formula Editor. You also define the class or method that the function was implemented in. For more information, see Structure of Implementing a Function and Implementing a Category.

    Example

    The following sample coding defines that the function C_TIMESTAMP_TO_DATE is displayed in the Formula Editor under the category Custom: Date/Time Functions.

    METHOD IF_EX_RSAR_CONNECTOR~GET.

    Data: l_function type SFBEOPRND.

    CASE i_key.

    WHEN space.

    l_function-descriptn = 'Custom: Date/Time Functions'.

    **** Description of the category ***

    l_function-tech_name = 'C_TIME'.

    *** Name of the category in uppercase ***

    APPEND l_function TO c_operands.

    *** Coding for the function ***

    WHEN 'C_TIME'.

    CLEAR l_function.

    l_function-tech_name = 'C_TIMESTAMP_TO_DATE'.

    l_function-descriptn = 'Convert Timestamp (Len 15) to Date'.

    l_function-class = 'ZCL_IM_CUSTOM_FUNCTIONS'.

    l_function-method = 'C_TIMESTAMP_TO_DATE'.

    APPEND l_function TO c_operands.

    ENDCASE.

    ENDMETHOD.

    Note

    A function does not have a type. Therefore, the TYPE field of structure SFBEOPRND cannot be filled.

  4. Save and activate your implementation.

Naming Conventions

The technical name of a self-defined function:

  • cannot be empty

  • must be consistent

  • must begin with 'C_'

  • can only contain alphanumeric characters, that is, 'ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_' (small letters, blank spaces and special characters are not allowed)

  • can have a maximum of 61 characters

Implementing the Methods

The ABAP methods specified in the function description under class and method (in the BADI implementation) are called later in maintenance and formula evaluation. You define which processing is performed by the function. Therefore, the customer-defined functions must additionally be implemented as methods for BAdI implementation in an additional class. These methods must have the following properties:

  • They are declared static and public.

  • They can only have importing, exporting, and returning parameters. Changing parameters are not permitted.

  • They can only have one exporting or returning parameter.

  • Exporting parameters cannot have a generic type.

In the methods, you can use ABAP code to implement the function.

Caution

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 the function is used in the formula builder.

Example

Coding example for a simple customer-defined function in which a timestamp is entered in function RS_TBBW_CONVERT_TIMESTAMP and converted into a date:

Method C_TIMESTAMP_TO_DATE.

**** Enter code here *******

CALL FUNCTION 'RS_TBBW_CONVERT_TIMESTAMP'

EXPORTING

i_timestamp = i_timestamp

IMPORTING

E_data = e_dat.

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

ENDMETHOD.

Result

The functions you have defined are available in the transformation library in the Customer-Defined Functions selection.