Calling Function Modules From Your Programs 

You can call a function module from within any ABAP program by using the following 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 as a string. You pass parameters by assigning the actual parameters to the formal parameters in lists following the EXPORTING , IMPORTING , CHANGING , and TABLES options.

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

 

 

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.

 

You can use the same number r i for different exceptions, as long as the exceptions do not have to be more specific.

 

You can call a function module from an ABAP program by using the Insert Statement function in the ABAP Editor as follows:

  1. Position the cursor at the point where you want to insert the CALL FUNCTION statement.
  2. Choose Pattern.
  3. In the Insert Statement dialog box, select CALL FUNCTION.
  4.  

     

  5. Enter the name of the function module.
  6. If you do not know the name, you can search using the possible values help.

  7. Choose Continue.
  8. The system inserts the CALL FUNCTION statement, complete with the interface of your chosen function module.

  9. Add the parameters, and program any exception handling.
  10. In our example, the function module is inserted into the ABAP Editor as follows:

     

  11. If you need more information about the function module, you can use the ABAP Editor help (F1). 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.

You must enter values for any parameters do not appear as comment lines in the ABAP Editor (constants or parameters).

The importing interface is commented out. Remove the asterisks (*) before the IMPORTING addition and the relevant parameters, and enter variables against the parameters from which you want to receive values from the function module.

 

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

When a function module runs in the update task, the system processes it asynchronously. Instead of processing it straight away, the system waits for the next database update to be triggered by a COMMIT WORK statement. 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 ABAP User’s Guide