ABAP Keyword Documentation → ABAP - Reference → Calling and leaving program units → Calling Processing Blocks → Calling procedures → CALL METHOD
CALL METHOD (meth_name)
Other versions: 7.31 | 7.40 | 7.54
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 without parentheses, either statically using
parameter_list or dynamically using
parameter_tables. The syntax of parameter_list is the same as that for the static method call.
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,
ptab_line TYPE abap_parmbind,
etab TYPE abap_excpbind_tab,
etab_line TYPE abap_excpbind.
DATA: exc_ref TYPE REF TO cx_sy_dyn_call_error,
exc_text TYPE string.
class = 'CL_GUI_FRONTEND_SERVICES'.
meth = 'GUI_DOWNLOAD'.
filename = 'c:\temp\text.txt'.
filetype = 'ASC'.
ptab_line-name = 'FILENAME'.
ptab_line-kind = cl_abap_objectdescr=>exporting.
GET REFERENCE OF filename INTO ptab_line-value.
INSERT ptab_line INTO TABLE ptab.
ptab_line-name = 'FILETYPE'.
ptab_line-kind = cl_abap_objectdescr=>exporting.
GET REFERENCE OF filetype INTO ptab_line-value.
INSERT ptab_line INTO TABLE ptab.
ptab_line-name = 'DATA_TAB'.
ptab_line-kind = cl_abap_objectdescr=>changing.
GET REFERENCE OF text_tab INTO ptab_line-value.
INSERT ptab_line INTO TABLE ptab.
ptab_line-name = 'FILELENGTH'.
ptab_line-kind = cl_abap_objectdescr=>importing.
GET REFERENCE OF fleng INTO ptab_line-value.
INSERT ptab_line INTO TABLE ptab.
etab_line-name = 'OTHERS'.
etab_line-value = 4.
INSERT etab_line INTO TABLE etab.
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.
exc_text = exc_ref->get_text( ).
MESSAGE exc_text TYPE 'I'.
ENDTRY.