ABAP Keyword Documentation → ABAP − Reference → Calling and leaving program units → Calling Processing Blocks → Calling Procedures → CALL FUNCTION
CALL FUNCTION - parameter_list
Other versions: 7.31 | 7.40 | 7.54
Syntax
... [EXPORTING p1 = a1 p2 = a2 ...]
[IMPORTING p1 = a1 p2 = a2 ...]
[TABLES t1 = itab1 t2 = itab2 ...]
[CHANGING p1 = a1 p2 = a2 ...]
[EXCEPTIONS [exc1 = n1 exc2 = n2 ...]
[error_message = n_error]
[OTHERS = n_others]].
Extras
1. ... EXPORTING p1 = a1 p2 = a2 ...
2. ... IMPORTING p1 = a1 p2 = a2 ...
3. ... TABLES t1 = itab1 t2 = itab2 ...
4. ... CHANGING p1 = a1 p2 = a2 ...
5. ... EXCEPTIONS exc1 = n1 exc2 = n2 ... OTHERS = n_others
6. ... EXCEPTIONS ... error_message = n_error ...
Effect
With the exception of the addition EXCEPTIONS
, these additions assign the
actual parameters a1
, a2
, ... to the formal parameters
p1
, p2
, ... or t1
, t2
, ... of the called function module. All data objects (and some expressions) whose data type
matches the
typing of the appropriate formal
parameter can be specified as actual parameters. With the exception of calculation expressions specified
for input parameters, each formal parameter inherits all properties of the assigned actual parameter
when called. Non-class-based exceptions can be handled using the addition EXCEPTIONS
. The order of the additions is fixed.
A handleable exception is raised whenever a formal parameter is incorrect and the name of the function module is specified by a constant or as a character literal. Unlike method calls, formal parameters are not checked by the syntax check. A static check only takes place in the extended program check. If the name of the function module is specified by a variable, the specification of an incorrect formal parameter is ignored at runtime.
Notes
- The formal parameters and non-class-based exceptions of a function module are defined as its parameter interface in Function Builder.
-
A system field should
never be used an actual parameter.
Addition 1
... EXPORTING p1 = a1 p2 = a2 ...
Effect
This addition assigns actual parameters to the
input parameters of the called function module. EXPORTING
can be used
to assign actual parameters to the optional input parameters. It must be used to assign actual parameters to the non-optional input parameters. If
pass by reference is used, a reference to an actual parameter is passed when the call is made. If
pass by value is used, the content of an actual parameter is assigned to the corresponding formal parameter.
a1
, a2
, ... are
general expression positions, which means that, alongside data objects, functions and expressions can also be passed as actual parameters.
Special rules apply in this case.
Notes
-
Substring access is not possible after an actual parameter
of type
string
orxstring
specified afterEXPORTING
. -
Unlike in method calls, types cannot be specified generically (
#
) when a constructor expression is specified. This is because the typing of the parameters is not determined until runtime.
Addition 2
... IMPORTING p1 = a1 p2 = a2 ...
Effect
This addition assigns actual parameters to the
output parameters of the called function module. IMPORTING
can be used to assign actual parameters to all output parameters, but this is not mandatory. If
pass by reference is used, a reference is passed to an actual parameter when the call is made. If
pass by value is used,
the content of an output parameter is assigned to the actual parameter in question only if the function module is completed without errors.
Addition 3
... TABLES t1 = itab1 t2 = itab2 ...
Effect
This addition assigns actual parameters to the
table parameters of the called function module. If TABLES
is used, internal
tables itab1
, itab2
, ... must be assigned to all
non-optional table parameters t1
, t2
, ... of the
called function module. These internal tables are optional for all optional table parameters. For itab1
, itab2
, ... , only
standard tables can be specified. The data is passed using a reference
(except RFC) . If a specified table itab1
, itab2
, ... has a
header line, this is also
passed. Otherwise, the header line of the corresponding table parameter t1
, t2
, ... is initial after the call.
Addition 4
... CHANGING p1 = a1 p2 = a2 ...
Effect
This addition assigns actual parameters to the
input/output parameters of the called function module. CHANGING
can be
used to assign actual parameters to the optional input/output parameters. It must be used to assign actual parameters to the non-optional input/output parameters. If
pass by reference is used, a reference to an actual parameter is passed when the call is made. If
pass by value is used, the content of an actual parameter is assigned to the corresponding formal parameter. If
pass by value is used,
the modified content of an input/output parameter is assigned to the actual parameter in question only if the function module is completed without errors.
Addition 5
... EXCEPTIONS exc1 = n1 exc2 = n2 ... OTHERS = n_others
Effect
EXCEPTIONS
can be used to assign return codes to
non-class-based exceptions exc1
exc2 ... declared in the parameter interface. Each exception exc1 exc2 ...
that the caller wants to handle must be assigned to a directly specified number n1 n2 ...
All numbers between 0 and 65535 can be specified. The behavior outside of this range is undefined.
OTHERS
can be specified as the last entry after EXCEPTIONS
to assign a common return code to all exceptions not specified explicitly in exc1
exc2.... This is done by assigning a number n_others
. The same return
code can be assigned to different exceptions (including OTHERS
). The behavior when an exception is raised is as follows:
-
If the statement
RAISE
orMESSAGE RAISING
is used to raise an exceptionexc1 exc2 ...
(to which a return code is assigned), the statement is ended immediately, any procedure parameters passed by value are not filled, and the numbern1 n2 ...
assigned to the exception is available to be evaluated insy-subrc
. -
If the call of an exception raised by
RAISE
does not assign a return code, the program terminates with a runtime error. -
If the call of an exception raised by
MESSAGE RAISING
does not assign a return code, the message is sent and the system resumes in accordance with the message type.
If no exception is raised, a call sets sy-subrc
to 0.
The addition EXCEPTIONS
cannot be specified in the call if RAISING
is used to declare
class-based exceptions in the parameter interface of the called procedure.
When the program is running, a specified exception is not checked when a function module is called. The extended program check returns an error if a specified exception is not declared in its interface.
Notes
-
For the addition
EXCEPTIONS
,CALL FUNCTION
also has an obsolete short form, in which the return code = n can be omitted after a specified exception. If an exception is raised, the value 1 is assigned tosy-subrc
implicitly. The return code must always be specified explicitly, however. - If the value 0 is assigned to an exception, this indicates that the caller wants to ignore this exception. If the exception is raised in the function module, no runtime error occurs, but the exception cannot be handled.
-
Information about the behavior of class-based exceptions in function modules can be found in Class-Based Exceptions in Procedures.
Addition 6
... EXCEPTIONS ... error_message = n_error ...
Effect
If the predefined exception error_message
is specified after EXCEPTIONS
,
all messages sent in the following ways in function module processing are affected as stated below:
-
Messages sent using the statement
MESSAGE without the addition
RAISING
, -
Messages sent using the statement
MESSAGE RAISING
because no return code is assigned to them -
that are sent by the ABAP runtime environment
during function module processing are affected as follows:
- Messages of the type S, I, or W are not sent but are flagged in the log in background processing .
-
Messages of the type E and A raise the exception
error_message
and set sy-subrc ton_error
. The message class, message type, message number, and the contents of possible placeholders for theMESSAGE
statement are in the fieldssy-msgid
,sy-msgno
,sy-msgty
, andsy-msgv1
, ...sy-msgv4
. In the case of messages of type A, the statementROLLBACK WORK
is also executed explicitly. For information about behavior in background processing, see messages in background processing. -
Messages of the type X are not affected. As always, they cause a program termination with a short dump.
Notes
-
When messages are handled with the predefined exception
error_message
, it does not make a difference whether the message is sent in the current function module or in a module that is called by this function module. Unlike the exceptions raised by the statementRAISE
, messages sent using the statementMESSAGE
are propagated across call levels. - Only messages from the current internal session are handled. Messages from programs called when the function module is processed are not handled.
-
The following situations can arise for the statement
MESSAGE RAISING
within the called function module:
- If a return code is assigned to the exception specified after
RAISING
, the exception is handled independently oferror_message
andsy-subrc
is set to this value.
- If no return code is assigned to the exception specified after
RAISING
anderror_message
is specified, the sent message is affected as specified above.
- If no return code is assigned to the exception specified after
RAISING
anderror_message
is not specified, the message is sent in accordance with its type.
-
When a program is resumed after handling a type A message, it must be ensured that a full
ROLLBACK WORK
is performed and not just a database rollback. -
The statement
ROLLBACK WORK
is executed when messages of type A are caught usingerror_message
, and is therefore forbidden in updates and when processing subroutines afterPERFORM ON COMMIT
orPERFORM ON ROLLBACK
, It also produces runtime errors. -
When programs are executed, the ABAP runtime environment can also send messages, for example when the
automatic checks on screen input are performed. These messages are caught using
error_message
in the same way as messages sent usingMESSAGE
.
Example
Calls the function module GUI_DOWNLOAD to save the content of an internal table to a file on the current presentation server. The name of the function module is specified as a character literal, which is the most frequent type of specification in static parameter assignment.
CONSTANTS path TYPE string VALUE `c:\temp\`.
DATA: line TYPE c LENGTH 80,
text_tab LIKE STANDARD TABLE OF line,
fleng TYPE i.
...
CALL FUNCTION 'GUI_DOWNLOAD'
EXPORTING
filename = path && `text.txt`
filetype = 'ASC'
IMPORTING
filelength = fleng
TABLES
data_tab = text_tab
EXCEPTIONS
file_write_error = 1
invalid_type = 2
no_authority = 3
unknown_error = 4
OTHERS = 10.
CASE sy-subrc.
WHEN 1.
...
...
ENDCASE.