Function Module Interfaces
A function module interface is defined by decisions on different levels:
- There are four kinds of parameters: IMPORTING, EXPORTING, CHANGING,and TABLES.
- IMPORTING parameters are pure inbound parameters. When they are called, a value is transferred and the value of the actual parameter stays the same.
- EXPORTING parameters are pure outbound parameters.
The value of the actual parameter when it is called is not important and after the parameter returns from being called, the actual parameter contains the value of the formal parameter.
- CHANGING parameters are both inbound and outbound
parameters. When they are called, a value is transferred and after the parameter returns from being called, the actual parameter contains the value of the formal parameter.
-
TABLES parameters are like CHANGING
parameters both inbound and outbound parameters, but can only be used for transferring standard tables
(Internal Tables). In this case the internal table always has a header, from the formal parameter's viewpoint.
- There are two types of parameter passing: pass by reference and pass by value.
- Pass by reference points the formal parameter directly to the actual parameter so that changes to the formal parameter immediately affect the actual parameter.
- Pass by value creates the formal parameter either as a copy of the actual parameter when the function
module is called (at
IMPORTING value and CHANGING
value parameters) or creates it initially on the stack (at EXPORTING
value parameters). With
CHANGING value and EXPORTING
value parameters, the formal parameter is copied to the actual parameter when it returns from the function module call.
-
Pay attention to the following when combining the four types of parameters (
IMPORTING, EXPORTING, CHANGING, and TABLES parameters) with the two types of passing (pass by reference and pass by value):
- You can use either "pass by value" or "pass by reference" with IMPORTING,
EXPORTING, and CHANGING parameters, whereas you can only use "pass by reference" with TABLES parameters.
- Internal tables should be passed by reference whenever possible to avoid unnecessary copying costs.
-
IMPORTING
reference parameters are read-only; trying to alter them triggers either the syntax error "Field "<x>"
may not be changed" or the runtime error MOVE_TO_LIT_NOTALLOWED.
- Reading access to the formal parameter is not allowed with EXPORTING
reference parameters before the initial write, even though this restriction is not presently monitored by syntax checks or the runtime system.
- You can assign types to function module parameters by entering either a reference type or reference
field. If a type error occurs at runtime when the function module is called, the program terminates with the runtime error CALL_FUNCTION_CONFLICT_TYPE.
- Typing using a reference field differs somewhat from typing using a reference type and is weaker:
- The following is true for IMPORTING, EXPORTING, and CHANGING
parameters: When an elementary reference field is entered the decimal places in type P fields are disregarded;
if a reference structure is input, the system only checks the entire structure for corresponding length
(with pass by reference the system checks for adequate alignment to the actual parameter) and not for structural similarity.
- The following is true for TABLES parameters: You must
enter a reference structure, which is then checked against the line type of the actual parameter. The
type check only checks to see if the total structural length of the actual parameter is not smaller
than the total structural length of the formal parameter and that the actual parameter fulfills the
alignment requirements of the formal parameter (TABLES parameters are always passed by reference).
- IMPORTING, CHANGING, and TABLES parameters can be
deemed optional. If an optional parameter is left out during a call, the formal parameter is filled
with a suggested (default) value using MOVE logic. Default
values for optional parameters can be explicitly defined (and must be able to be converted to the formal
parameter type using the MOVE logic in this case). If
default values are not specified, then the initial value of the formal parameter according to type is used as a default value.
- If parameters are omitted when called, the formal parameter assumes the default value (when the
type is generic or does not exist, this parameter also assumes the default type and length, whether they are explicitly entered or implicitly constructed).
- By using the logical expression IS REQUESTED you can check
a function module to see if an actual parameter was set for a formal parameter during a CALL FUNCTION call.
For further information refer to
Creating Function Modules