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

How to create class object at run time?

Former Member
0 Likes
552

Hello Experts,

variable v_classname type seoclsname will contain class name 'ZCL_TEST'

and method name will be stored in variable v_cls_mth = 'GET_DATA'

I want to create a object of class ZCL_SAMPLE at run time and once object is created it corresponding method stored in variable v_cls_mth will be called.

Please note that class is implemented in SE24.

i had done something like this:

data:v_classname TYPE seoclsname value 'ZCL_TEST',

v_ref type ref to object.

start-of-selection.

create object v_ref type (v_classname).

call method v_ref->GET_DATA().

Its not working.

Please help me in correcting above code. Many thanks in advance.

- Nilesh

Edited by: Nilesh Pawar on Aug 13, 2009 4:21 AM

1 ACCEPTED SOLUTION
Read only

uwe_schieferstein
Active Contributor
0 Likes
474

Hello Nilesh

You need to call the method dynamically as well:


data:
  gd_classname TYPE seoclsname value 'ZCL_TEST',
  gd_method       TYPE seoclsname VALUE 'GET_DATA',
  go_ref              TYPE REF TO object.

start-of-selection.
create object go_ref type (v_classname).
call method go_ref->(gd_method).

Regards

Uwe

Hello Experts,

variable v_classname type seoclsname will contain class name 'ZCL_TEST'

and method name will be stored in variable v_cls_mth = 'GET_DATA'

I want to create a object of class ZCL_SAMPLE at run time and once object is created it corresponding method stored in variable v_cls_mth will be called.

Please note that class is implemented in SE24.

i had done something like this:

data:v_classname TYPE seoclsname value 'ZCL_TEST',

v_ref type ref to object.

start-of-selection.

create object v_ref type (v_classname).

call method v_ref->GET_DATA().

Its not working.

Please help me in correcting above code. Many thanks in advance.

- Nilesh

Edited by: Nilesh Pawar on Aug 13, 2009 4:21 AM

2 REPLIES 2
Read only

uwe_schieferstein
Active Contributor
0 Likes
475

Hello Nilesh

You need to call the method dynamically as well:


data:
  gd_classname TYPE seoclsname value 'ZCL_TEST',
  gd_method       TYPE seoclsname VALUE 'GET_DATA',
  go_ref              TYPE REF TO object.

start-of-selection.
create object go_ref type (v_classname).
call method go_ref->(gd_method).

Regards

Uwe

Read only

0 Likes
474

Aaah !!! putting variabe name for method went out of my mind !!!

Thanks Uwe !!

- Nilesh