Skip to content

ABAP Keyword Documentation →  ABAP - Reference →  Program structure →  Modularization Statements →  Procedures →  Function Modules →  FUNCTION →  Function Module Interface 

Properties of Interface Parameters

When an interface parameter p1, p2... is defined in Function Builder, properties are determined for the parameter which are reflected in the syntax of parameters and table_parameters.

Other versions: 7.31 | 7.40 | 7.54

Syntax


... { VALUE(p1) | p1 } 
         [ {TYPE [REF TO] type} | like_structure
           [OPTIONAL|{DEFAULT def1}] ]
    { VALUE(p2) | p2 }
         [ {TYPE [REF TO] type} | like_structure
           [OPTIONAL|{DEFAULT def2}] ]
    ...

The syntax and semantics of VALUE, TYPE, OPTIONAL, and DEFAULT are mainly the same as in the definition of method interfaces by [CLASS-]METHODS. The obsolete option like_structure also exists, which uses LIKE or STRUCTURE to type interface parameters.

Type of Parameter Passing

There are two types of parameter passing: pass by reference and pass by value. Pass by value is selected in Function Builder by selecting pass by value and differs from pass by reference in the above syntax by VALUE( ) being specified.

  • In pass by reference, the formal parameter points directly to the actual parameter, so that changes to the formal parameters have an immediate effect on the actual parameter.
  • In pass by value, when the function module is called, the formal parameter is created as a copy of the actual parameter (in IMPORTING and CHANGING parameters), or initial (in EXPORTING parameters) in the stack. In CHANGING and EXPORTING parameters, the formal parameter is copied to the actual parameter when returning from the function module.

Note the following for the different types of parameter:

  • In IMPORTING, EXPORTING, and CHANGING parameters, pass by reference and pass by value are possible, in TABLES parameters, only pass by reference is possible.
  • IMPORTING parameters passed by reference must not be overwritten in the function module.
  • An EXPORTING parameter passed by reference behaves like a CHANGING parameter, which means that EXPORTING parameters passed by reference are not initialized when the function module is called. For this reason, no read access to these parameters should be permitted before the first write access. In addition, be careful when adding content to such parameters as, for example, when inserting rows into internal tables.

Typing of Interface Parameters

The parameter interface of a function module is public across the system. Interface parameters can therefore only be typed with reference to data types from ABAP Dictionary or from the public visible section of global classes. In Function Builder, interface parameters can be typed selecting either TYPE or TYPE REF TO or by entering LIKE.

Typing with TYPE [REF TO] is the recommended typing for interface parameters of function modules. It takes place when TYPE or TYPE REF TO is selected in Function Builder. For IMPORTING, EXPORTING, and CHANGING parameters, any predefined ABAP type (complete or generic), or any data type from ABAP Dictionary or from the public visibility section of a global class can be specified after TYPE. After TYPE REF TO, the generic data type data, a non-generic data type, or an object type can be specified and the interface parameter is typed as a reference variable. The typing check is performed in the same way as for methods.


Note

Without an explicit typing, a formal parameter is typed implicitly with the fully generic type any.

Optional Parameters

IMPORTING, CHANGING, and TABLES parameters can be made optional by the selection of optional in Function Builder. EXPORTING parameters are always optional. IMPORTING and CHANGING parameters can be assigned a replacement parameter (default value in the Function Builder). In the above syntax, this is expressed using the additions OPTIONAL or DEFAULT. For an optional parameter, no actual parameter must be entered when the function module is called. While a formal parameter with the addition OPTIONAL is then initialized according to its type, a formal parameter with the addition DEFAULT assumes the value and type of the replacement parameter def1 def2 ....

If no actual parameter is specified for a generically typed formal parameter with the addition OPTIONAL when it is called, the type of the formal parameter is completed according to fixed rules.


Note

Within a function module, the logical expression IS SUPPLIED can be used to check if an optional formal parameter was assigned an actual parameter when it was called.