Entering content frameProcess 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 TABLES options.

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).

 

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:

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.
  4. This graphic is explained in the accompanying text

     

  5. Enter the name of the function module in the input field.
  6. If you do not know the name, you can search using the input help key.

  7. Choose Continue.
  8. The system inserts the function module with the interface into your coding.

  9. Maintain the appropriate parameters and handle the exceptions.
  10. Example

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

     

    This graphic is explained in the accompanying text

     

  11. 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