ABAP Keyword Documentation →  ABAP − Reference →  Calling and leaving program units →  Calling Processing Blocks →  Calling Procedures →  Method Calls →  Dynamic Method Call → 

CALL METHOD  Syntax Diagram

Short Reference

Syntax

CALL METHOD dynamic_meth { parameter_list
                           | parameter_tables }.

Effect

This statement calls the method dynamically specified in dynamic_meth(Dynamic Invoke). Actual parameters are assigned to formal parameters of the method, either statically using parameter_list or dynamically using parameter_tables. The syntax of parameter_list is the same as that in the explicit parameter specification for the static method call.

Notes

Security Note

If used wrongly, dynamic calls of program units can present a serious security risk. Names of program units that are passed to a program from the outside must be checked thoroughly before being used in dynamic calls. The system class CL_ABAP_DYN_PRG, for example, can be used to do this. See Dynamic Calls.

System Fields

The system field sy-subrc is set to 0 when a method is called. If a non-class-based exception is raised that was handled by the assignment of a value, then sy-subrc is set to this value.

Example

Dynamic call of the static method gui_download of global class cl_gui_frontend_services for storing the content of an internal table in a file on the current presentation server. The names of the class and method are specified in the strings class and meth. The interface parameters are passed in the internal table ptab and return values are assigned to the exceptions of the method are assigned using table etab. Exceptions that occur at the method call itself are handled in a TRY control structure with statement CATCH.

DATA: line     TYPE c LENGTH 80,
      text_tab LIKE STANDARD TABLE OF line,
      filename TYPE string,
      filetype TYPE c LENGTH 10,
      fleng    TYPE i.

DATA: meth  TYPE string,
      class TYPE string,
      ptab TYPE abap_parmbind_tab,
      etab TYPE abap_excpbind_tab.

DATA: exc_ref TYPE REF TO cx_sy_dyn_call_error.

class    = 'CL_GUI_FRONTEND_SERVICES'.
meth     = 'GUI_DOWNLOAD'.
filename = 'c:\temp\text.txt'.
filetype = 'ASC'.

ptab = VALUE #( ( name  = 'FILENAME'
                  kind  = cl_abap_objectdescr=>exporting
                  value = REF #( filename ) )
                ( name  = 'FILETYPE'
                  kind  = cl_abap_objectdescr=>exporting
                  value = REF #( filetype ) )
                ( name  = 'DATA_TAB'
                  kind  = cl_abap_objectdescr=>changing
                  value = REF #( text_tab ) )
                ( name  = 'FILELENGTH'
                  kind  = cl_abap_objectdescr=>importing
                  value = REF #( fleng ) ) ).

etab = VALUE #( ( name = 'OTHERS' value = 4 ) ).

TRY.
    CALL METHOD (class)=>(meth)
      PARAMETER-TABLE
        ptab
      EXCEPTION-TABLE
        etab.
    CASE sy-subrc.
      WHEN 1.
        ...
      ...
    ENDCASE.
  CATCH cx_sy_dyn_call_error INTO exc_ref.
    MESSAGE exc_ref->get_text( ) TYPE 'I'.
ENDTRY.

Exceptions

Catchable Exceptions

CX_SY_DYN_CALL_EXCP_NOT_FOUND

CX_SY_DYN_CALL_ILLEGAL_CLASS

CX_SY_DYN_CALL_ILLEGAL_METHOD

CX_SY_DYN_CALL_ILLEGAL_TYPE

CX_SY_DYN_CALL_PARAM_MISSING

CX_SY_DYN_CALL_PARAM_NOT_FOUND

CX_SY_REF_IS_INITIAL

Non-Catchable Exceptions




Continue
CALL METHOD - dynamic_meth