Get Example source ABAP code based on a different SAP table
• VALUE FUNCTION • TYPE FUNCTION • OPTIONAL FUNCTION • DEFAULT FUNCTION
Properties of Interface Parameters When an interface parameter p1>, p2>... is defined BEGIN_SECTION VERSION 5 OUT in the Function Builder, END_SECTION VERSION 5 OUT its properties are determined that are reflected in the syntax of parameters> and table_parameters>>.
ABAP_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 with $[CLASS-$]METHODS>>. In addition, there is also the obsolete option like_structure>>, which uses LIKE> or STRUCTURE> to type interface parameters.
Type of Parameter Passing There are two types of pass by parameters: pass by reference> and pass by value>. Pass by value BEGIN_SECTION VERSION 5 OUT is selected in the Function Builder by selecting pass by value> and END_SECTION VERSION 5 OUT differs from pass by reference in the above syntax, which is indicated by REFERENCE( )>, by the specification of VALUE( )>. 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, the formal parameter is created as a copy of the actual parameter (in IMPORTING> and CHANGING> parameters) or as an initial parameter (in EXPORTING> parameters) on the stack when the function module is called and for 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; for 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, that is, EXPORTING> parameters passed by reference are not initialized when the function module is called. Therefore, no read access to these parameters should take place before the first write access. In addition, care must be taken when adding content to such parameters as, for example, when inserting lines into internal tables.
Latest notes: The time the function module was last edited specifies whether a parameter passed by reference is shown with or without REFERENCE( )>. REFERENCE( )> is shown for function modules that have been modified since ABAP_RELEASE 7.31. NON_V5_HINTS ABAP_HINT_END
Typing of Interface Parameters The parameter interface of a function module is public throughout the system. Interface parameters can therefore only be typed with reference to data types from the ABAP Dictionary or from the public visibility section of global classes. Interface parameters can be typed using TYPE>, TYPE REF TO> or LIKE>>. Typing with TYPE $[REF TO$]> is the only recommended typing for interface parameters of function modules. It takes place when TYPE> or TYPE REF TO> is used BEGIN_SECTION VERSION 5 OUT in the Function Builder END_SECTION VERSION 5 OUT . For IMPORTING>, EXPORTING>, and CHANGING> parameters, any built-in ABAP type> (complete or generic), or any data type of the 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.
Latest notes: Without an explicit typing, a formal parameter is typed implicitly with the fully generic type any>. NON_V5_HINTS ABAP_HINT_END
Optional Parameters IMPORTING>, CHANGING>, and TABLES> parameters> can be made optional by using optional> BEGIN_SECTION VERSION 5 OUT in the Function Builder END_SECTION VERSION 5 OUT . EXPORTING> parameters are always optional. IMPORTING> and CHANGING> parameters can be assigned a replacement parameter BEGIN_SECTION VERSION 5 OUT (default value> in the Function Builder) END_SECTION VERSION 5 OUT . In the above syntax, this is expressed using the additions OPTIONAL> or DEFAULT>. For an optional parameter, no actual parameter must be specified when the function module is called. While a formal parameter with the addition OPTIONAL> is then initialized as a type-compliant parameter, 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>.
Latest notes: 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. NON_V5_HINTS ABAP_HINT_END