Show TOC Entering content frame

Process documentation Calling Function Modules From Your Programs Locate the document in its SAP Library structure

You can call a function module from within any ABAP program by using the following ABAP statement:

CALL FUNCTION <function module>

     [EXPORTING  f1 = a1.... fn = an]
     [IMPORTING  f1 = a1.... fn = an]
     [CHANGING   f1 = a1.... fn = an]
     [TABLES     f1 = a1.... fn = an]
     [EXCEPTIONS e1 = r1.... en = rn
                 [ERROR_MESSAGE = rE]
                 [OTHERS = ro]].

You enter the name of the function module <function module> as a literal. You pass parameters by explicitly assigning the actual parameters to the formal parameters in lists following the EXPORTING, IMPORTING, CHANGING, and TABLESoptions.

Note

You assign parameters in the form    <formal parameter> = <actual parameter>
If you assign more than one parameter within an option, separate them with spaces (or by starting a new line).

 

·        The EXPORTING option passes the actual parameter ai to the formal input parameter.fi. The formal parameters must be declared as import parameters in the function module. The parameters may have any data type. If you specify a reference field, the system checks the parameter.

·        The IMPORTING option passes the formal output parameter fi  of the function module to the actual parameter ai.  The formal parameters must be declared as export parameters in the function module. The parameters may have any data type.

·        The CHANGING option passes the actual parameter ai to the formal parameter fi.After the function module has been processed, the system returns the (changed) values of the formal parameters fi  to the actual parameters fi. The formal parameters must be declared as CHANGING parameters in the function module. These parameters, too, may have any data type.

·        The TABLES option passes internal tables between the actual and formal parameters. The internal tables are always passed by reference. The parameters in this option must always reference internal tables.

·        The EXCEPTIONS option allows you to react to errors in the function module. Exceptions are provided as special parameters in order to be able to react to possible error events during processing of the function module. When an exception occurs, function module processing terminates. Example: If exception ei is triggered, the system stops processing the function module and does not pass any values back to the program. The calling program receives the exception ei by assigning the value ri as a return code to the system field SY-SUBRC. This functions as a return code. ri must be a numeric literal. You can then evaluate the system field in the calling program.

You can change the error handling in the function module by specifying an ERROR_MESSAGE in the EXCEPTIONS list. Normally, messages should only be called in exception handling (using the statements MESSAGE.....RAISING or RAISE within the function module). For more information, refer to the section Overview of Coding for Function Modules.

Using ERROR_MESSAGE, you can have the system treat messages that are called in the function module, by exception, without this explicit treatment as follows:

¡        Messages of classes S, I, and W are ignored (but entered in the log if you are running the program in the background).

¡        Messages of classes E and A cause the function module to terminate as though the ERROR_MESSAGE exception had been triggered (SY-SUBRC is set to rE).

If you enter OTHERS in the EXCEPTION list, you can allow for all exceptions, even though they are not listed. It acts as a default exception.

 

Note

You can use the same number ri for different exceptions, as long as the system does not require further specification of the exceptions.

 

You can use the function Pattern in the ABAP editor to call a function from within your coding. Perform the following steps:

...

       1.      Position the cursor at the point in your coding where you want to call the function.

       2.      Choose Pattern.

       3.      In the dialog box that then appears, mark the selection field in front of CALL FUNCTION.

This graphic is explained in the accompanying text

 

       4.      Enter the name of the function module in the input field.

If you do not know the name, you can search using the input help key.

       5.      Choose Continue.

The system inserts the function module with the interface into your coding.

       6.      Maintain the appropriate parameters and handle the exceptions.

Example

In our example, the function module is displayed as follows:

 

This graphic is explained in the accompanying text

 

       7.      If you need more information about the function module, you can call this up through the information icon. The Help dialog box appears. Select Function module, and enter the function module name. Choose Continue.
The system displays the interface definition for the function module. From there, you can display all of the other function module elements.

Note

Parameters not marked as commentary elements must be supplied with values by your program. For this purpose, you can use fixed values or parameters.

The import interface is commented out. In your coding, remove the asterisk (*) before IMPORTING and pass the required data of the function module to variables.

 

There are other parameters that you can use with the CALL FUNCTION statement if the function is to run in an update task or on a remote host.

When a function module runs in the update task, the system processes it asynchronously. This call is not executed immediately. Instead, the system waits until the next database update is triggered by COMMIT WORK. Running a function module on a remote host means that you call a function module within another SAP system or a non-SAP system.

For further information about how to call function modules from programs, see the Function Modules section of the Structure linkABAP User’s Guide

 

 

Leaving content frame