ABAP Keyword Documentation → ABAP − Reference → Calling and leaving program units → Calling Processing Blocks → Calling Procedures → Method Calls → Dynamic Method Call → CALL METHOD
CALL METHOD - parameter_tables
Other versions: 7.31 | 7.40 | 7.54
Syntax
... [PARAMETER-TABLE ptab]
[EXCEPTION-TABLE etab].
Extras
1. ... PARAMETER-TABLE ptab
2. ... EXCEPTION-TABLE etab
Effect
In dynamic method calls, these additions assign
actual parameters and exceptions to the formal parameters and non-class-based exceptions respectively, using the special internal tables ptab
and etab
.
Addition 1
... PARAMETER-TABLE ptab
Effect
PARAMETER-TABLE
can be used to assign actual parameters to all formal parameters of a dynamically called method. ptab
expects a
hashed table of table type ABAP_PARMBIND_TAB or of row type ABAP_PARMBIND from the
type group ABAP.
When the statement CALL METHOD
is executed, the table must contain exactly
one row for each non-optional formal parameter. This row is optional for each optional formal parameter. The table columns are:
-
NAME of type
c
and length 30
Specifies the name of the formal parameter in question in uppercase. If a nonexistent formal parameter is specified, a handleable exception is raised. -
KIND of type
c
of length 1.
Specifies the category of the formal parameter. This column is used to check the interface. The category of the formal parameter is determined in the declaration of the called method. If KIND is initial, no check is executed. If KIND contains the value of a constant EXPORTING, IMPORTING, CHANGING, or RECEIVING of the class CL_ABAP_OBJECTDESCR, a check is made (from the perspective of the caller). This check determines whether the formal parameter specified in NAME is an input parameter, output parameter, input/output parameter, or a return code. If an error occurs, the handleable exception CX_SY_DYN_CALL_ILLEGAL_TYPE is raised. -
VALUE of the type
REF TO data
Used as a pointer to an appropriate actual parameter. The data object pointed to by the reference variable in VALUE is assigned to the formal parameter specified in NAME.
The column NAME is the unique key of the table ptab
.
Addition 2
... EXCEPTION-TABLE etab
Effect
EXCEPTION-TABLE
can be used to assign return codes to all
non-class-based exceptions of a dynamically called method. etab
expects a
hashed table of table type ABAP_EXCPBIND_TAB or of row type ABAP_EXCPBIND from the
type group ABAP.
When the statement CALL METHOD
is executed, this table can contain exactly one row for every non-class-based exception of the method. The table columns are:
-
NAME of type
c
and length 30
Specifies the name of the respective exception orOTHERS
in uppercase. -
VALUE of type
i
Specifies the number value available insy-subrc
after the exception specified in NAME is raised.
The column NAME is the unique key of table etab
.
Example
Dynamic method call with parameter and exception table.
CLASS cls DEFINITION.
PUBLIC SECTION.
CLASS-METHODS meth IMPORTING p TYPE string
EXCEPTIONS e.
ENDCLASS.
CLASS cls IMPLEMENTATION.
METHOD meth.
cl_demo_output=>write( p ).
RAISE e.
ENDMETHOD.
ENDCLASS.
START-OF-SELECTION.
DATA(class) = `CLS`.
DATA(meth) = `METH`.
DATA(ptab) = VALUE abap_parmbind_tab(
( name = 'P'
kind = cl_abap_objectdescr=>exporting
value = REF #( `Hello method!` ) ) ).
DATA(etab) = VALUE abap_excpbind_tab(
( name = 'E' value = 4 ) ).
CALL METHOD (class)=>(meth)
PARAMETER-TABLE ptab
EXCEPTION-TABLE etab.
IF sy-subrc <> 0.
cl_demo_output=>display( `Exception caught ...` ).
ENDIF.