Start of Content Area

Procedure documentation BAdI: Customer-Defined Functions in the Formula Builder  Locate the document in its SAP Library structure

Use

You can integrate your own functions in the Formula Builder transformation library. This allows you to make special functions that are not contained in the transformation library available for frequent use.  Business Add-In RSAR_CONNECTOR is available for this purpose. 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.      You can find information about how to implement a BAdI under Implementation of a Business Add-In. 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 of the add-in that you want to create the implementation for.

       3.      By double-clicking the method (GET), the class builder appears. Here you can enter your coding to implement 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. More information: Structure of Implementing a Function and Implementing a Category.

Syntax

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, meaning that the TYPE field in structure SFBEOPRND cannot be filled.

       4.      Save and activate your implementation.

Naming Conventions

The technical name of a user-defined function:

      cannot be empty

      must be unique

      must begin with ‘C_’

      can only contain alphanumeric characters: '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 therefore also have to implemented as methods for BAdI implementation in an additional class. These methods must have the following properties:

      They are declared as 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.

Syntax

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.

 

 

End of Content Area