Skip to content

ABAP Keyword Documentation →  ABAP − Reference →  Calling and leaving program units →  Calling Processing Blocks →  Calling Procedures →  CALL FUNCTION 

CALL FUNCTION func

Quick Reference

Other versions: 7.31 | 7.40 | 7.54

Syntax


CALL FUNCTION func { parameter_list 
                   | parameter_tables }.

Effect

This statement calls the function module specified in func. The name func must be a character-like data object. When the statement is executed, this data object must contain the name of a function module permitted by the package check in uppercase. Each function module in AS ABAP has a unique name, which is why the function group does not need to be specified. The following can be specified for func:

  • Literal or constant
If the data object func is specified as a character literal or as a constant, it is evaluated as a statically specified object by tools such as for the extended program check or for the where-used list.
  • Variable
If the data object func is specified as a variable, it is specified only dynamically and the content is not evaluated statically.

When the statement is executed, func is not evaluated until runtime (in both cases). More specifically, the types of the parameters are not known until runtime. In both cases, incorrectly specified function modules or parameters produce runtime errors and not syntax errors

The additions parameter_list or parameter_tables are used to assign (statically or dynamically) actual parameters to the formal parameters of the function module and return codes to the non-class-based exceptions.

Security Note

If the name of a program unit is specified dynamically when it is called, and this name is passed to a program from outside, the result is a serious security risk. Any names passed to a program from outside must be checked thoroughly before being used in calls. The system class CL_ABAP_DYN_PRG, for example, can be used to do this. See Dynamic Calls.


Note

func is not evaluated until runtime, which means that, unlike in static method calls, no writable expressions and no inline declarations can be specified as actual parameters in function module calls.


Example

Call of function modules READ_SPFLI_INTO_TABLE and READ_SPFLI_INTO_TABLE_NEW with parameter passing and handling of non-classified and/or class-based exceptions.

DATA itab TYPE spfli_tab. 

CALL FUNCTION 'READ_SPFLI_INTO_TABLE' 
  EXPORTING 
    id        = 'LH' 
  IMPORTING 
    itab      = itab 
  EXCEPTIONS 
    not_found = 4. 
IF sy-subrc <> 0. 
   ... 
ENDIF. 

TRY. 
    CALL FUNCTION 'READ_SPFLI_INTO_TABLE_NEW' 
      EXPORTING 
        id   = 'LH' 
      IMPORTING 
        itab = itab. 
  CATCH cx_no_flight_found INTO DATA(exc). 
    ... 
ENDTRY.

Executable Example

Calling Function Modules

Exceptions

Handleable Exceptions

CX_SY_NO_HANDLER

CX_SY_DYN_CALL_ILLEGAL_FUNC

  • Cause: The called function is known but not active.
    Runtime error: CALL_FUNCTION_NOT_ACTIVE
  • Cause: The called function is unknown.
    Runtime error: CALL_FUNCTION_NOT_FOUND

CX_SY_DYN_CALL_ILLEGAL_TYPE

  • Cause: The type of the actual parameter does not meet the requirements of the function interface.
    Runtime error: CALL_FUNCTION_CONFLICT_GEN_TYP
  • Cause: The actual parameter does not have the length expected by the function.
    Runtime error: CALL_FUNCTION_CONFLICT_LENG
  • Cause: The actual parameter does not have the type expected by the function.
    Runtime error: CALL_FUNCTION_CONFLICT_TYPE
  • Cause: Only valid functions can be called in the update.
    Runtime error: CALL_FUNCTION_NO_VB
  • Cause: An actual parameter does not meet the alignment requirements of the corresponding formal parameter.
    Runtime error: CALL_FUNCTION_WRONG_ALIGNMENT

CX_SY_DYN_CALL_PARAM_MISSING

  • Cause: The function expects a parameter not specified by the caller.
    Runtime error: CALL_FUNCTION_PARM_MISSING

CX_SY_DYN_CALL_PARAM_NOT_FOUND

  • Cause: The caller specified a parameter not recognized by the function.
    Runtime error: CALL_FUNCTION_PARM_UNKNOWN

Continue

Calling Function Modules