Show TOC

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

If the transformations are performed in the Application Server, you can integrated user-defined functions in the Formula Editor's transformation library. This also allows you to make special functions not contained in the transformation library available for frequent use. You can use the RSAR_CONNECTOR Business Add-In to do 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 detailed information about how to use Business Add-Ins (BAdIs), see Business Add-Ins (BAdIs)..

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 that you want to create the implementation for.

  3. By double-clicking the method (GET), you open the class builder. 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 example coding defines that the C_TIMESTAMP_TO_DATE function is displayed under the category Date/Time Functions in the Formula Editor.

    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. The TYPE field of structure SFBEOPRND therefore cannot be filled.

  4. Save and activate your implementation.

Naming Conventions

The technical name of a user-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. The customer-defined functions must therefore also 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.