Application Development and Automation Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

Get reference of dynamic data type

YayatiEkbote
Contributor
0 Likes
3,749

Hello all,

In our custom interface, if there is some error in process, we need to trigger the methods of classes manually. For this , I have a requirement to create a program to trigger the methods . For this, requirement, I am getting the class name and method name and I want to trigger this dynamically.

To trigger the methods dynamically, the parameter table has to be created. The problem I am facing is that the method name comes runtime, hence parameters and their data types are also know runtime. Hence to create the parameter tab, I ha written code as below -

DATA:

  t_params          TYPE abap_parmbind_tab,

  w_params         TYPE abap_parmbind.

FIELD-SYMBOLS:

<lf_dtype>     TYPE any.

LOOP AT t_params INTO w_params.

w_params-name = 'GUID'.

w_params-kind   = 'I'. "Importing parameter type

CALL METHOD go_util->get_datatype

     EXPORTING

            iv_class_name     = gv_class     "ZCL_MANUAL_PROC

            iv_meth_name     = gv_meth     "GET_INSTANCE

     IMPRTING

           ev_datatype          = lv_datatype.     "BBP_GUID

CREATE DATA dyndata TYPE (lv_datatype).

ASSIGN dyndata->* TO <lf_dtype>.

IF <lf_dtype> IS ASSIGNED.

     <lf_dtype> = p_data.

ENDIF.

GET REFERENCE OF <lf_dtype> INTO w_params-value.

MODIFY t_params FROM w_params.

CLEAR w_params.

ENDLOOP.

CALL METHOD (gv_class)=>(gv_meth)     "static public methods are called

     PARAMETER-TABLE

     t_params.

get_datatype is a custom method from custom utilities class which has a query to table ' seosubcodf ' which returns parameters of methods and their datatypes.

I am getting an exception of type 'CX_SY_DYN_CALL_ILLEGAL_TYPE' when method is called. The exception description says -

The reason for the exception is:

When dynamically calling the method "GET_INSTANCE" of the class

"ZCL_MANUAL_PROC", the parameter

"IV_GUID" was transferred with the incorrect parameter type.

Could anyone please tell me what is the wrong thing which I am doing in above coding because of which I am getting dump?

Regards,

Yayati

1 ACCEPTED SOLUTION
Read only

former_member210008
Active Participant
0 Likes
2,030

Hi.Check parameter's names of your method. You added GUID to parmbind table, but exception said that you have wrong IV_GUID param.

Also if method have IMPORTING section, you must set it parameter KIND to CL_ABAP_OBJECTDESCR=>EXPORTING, for EXPORTING section in must be CL_ABAP_OBJECTDESCR=>IMPORTING.



REPORT ztest.

CLASS class DEFINITION.
   PUBLIC SECTION.
   CLASS-METHODS m1 IMPORTING iv_1 TYPE string.
ENDCLASS.

CLASS class IMPLEMENTATION.
   METHOD M1.
     WRITE:/ iv_1.
   ENDMETHOD.
ENDCLASS.

START-OF-SELECTION.
DATA(class) = 'CLASS'.
DATA(method) = 'M1'.

DATA parmtable TYPE abap_parmbind_tab.

insert VALUE #( name = 'IV_1' kind = CL_ABAP_OBJECTDESCR=>EXPORTING value = ref #( `text` ) ) INTO TABLE parmtable.

try.
CAll METHOD (class)=>(method)
   PARAMETER-TABLE parmtable.
CATCH cx_root.
   WRITE:/ 'fail'.
ENDTRY.

3 REPLIES 3
Read only

former_member210008
Active Participant
0 Likes
2,031

Hi.Check parameter's names of your method. You added GUID to parmbind table, but exception said that you have wrong IV_GUID param.

Also if method have IMPORTING section, you must set it parameter KIND to CL_ABAP_OBJECTDESCR=>EXPORTING, for EXPORTING section in must be CL_ABAP_OBJECTDESCR=>IMPORTING.



REPORT ztest.

CLASS class DEFINITION.
   PUBLIC SECTION.
   CLASS-METHODS m1 IMPORTING iv_1 TYPE string.
ENDCLASS.

CLASS class IMPLEMENTATION.
   METHOD M1.
     WRITE:/ iv_1.
   ENDMETHOD.
ENDCLASS.

START-OF-SELECTION.
DATA(class) = 'CLASS'.
DATA(method) = 'M1'.

DATA parmtable TYPE abap_parmbind_tab.

insert VALUE #( name = 'IV_1' kind = CL_ABAP_OBJECTDESCR=>EXPORTING value = ref #( `text` ) ) INTO TABLE parmtable.

try.
CAll METHOD (class)=>(method)
   PARAMETER-TABLE parmtable.
CATCH cx_root.
   WRITE:/ 'fail'.
ENDTRY.

Read only

0 Likes
2,030

Hello Evgeniy,

Thanks for your quick reply. I understood the problem in my code using your code snippet. The method has importing parameter but when you display it in a program, it is exporting. So when type of parameter is 'I', I should pass 'E'. But I have a doubt about 'Returning' type of parameter. Should it be changed to 'I' as well?

Regards,

Yayati

Read only

0 Likes
2,030

It should be CL_ABAP_OBJECTDESCR=>RETURNING.

You can find all possible values in CL_ABAP_OBJECTDESCR class. Look at attributes with ABAP_PARMKIND type.

Also check abap help for dynamic call method. You will find there few examples.