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) | REFERENCE(p1) }
[ {TYPE [REF TO] type} | like_structure
[OPTIONAL|{DEFAULT def1}] ]
{ VALUE(p2) | REFERENCE(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 (indicated by REFERENCE(
)) by VALUE( )
being specified. If only one name p1 p2 ...
is specified, the parameter is passed by reference by default.
- 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
andCHANGING
parameters), or initial (inEXPORTING
parameters) in the stack. In CHANGING andEXPORTING
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
, andCHANGING
parameters, pass by reference and pass by value are possible, inTABLES
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 aCHANGING
parameter, which means thatEXPORTING
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.
Note
The time the function module was last edited specifies whether a parameter passed by reference is displayed with or without REFERENCE(
). REFERENCE( )
is displayed for function modules modified in Release 7.31 and later.
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 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
predicate expression IS SUPPLIED
can be used to check whether an optional formal parameter was assigned an actual parameter when it was called.