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

Instanciate class dynamically

Former Member
0 Likes
593

Hi all,

I want to instanciate a class dynamically at runtime...

e. g. DATA: object type ref to <class name>.

I tried the following:

data: lv_class_name(60) type c.

lv_class_name = 'ZCL_BATCH_INPUT'.

data: lref_obj type ref to object.

CREATE OBJECT lref_obj TYPE (lv_class_name).

CALL METHOD lref_obj->bdc_transaction

EXPORTING

i_tcode = 'MM02'

i_mode = 'A'

  • IMPORTING

  • et_messages =.

The problem is that the object lref_obj (type object) does not know the method bdc_transaction (from type ZCL_BATCH_INPUT)

Any ideas?

regards

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
552

Hi

Try to call the method dymaically:

 data: lv_class_name(60) type c.
data: method(60) type c.
data: lref_obj type ref to object.


lv_class_name = 'ZCL_BATCH_INPUT'.
method        = 'BDC_TRANSACTION'.
  
CREATE OBJECT lref_obj TYPE (lv_class_name).

CALL METHOD lref_obj->(METHOD)
EXPORTING
i_tcode = 'MM02'
i_mode = 'A'.

Max

1 REPLY 1
Read only

Former Member
0 Likes
553

Hi

Try to call the method dymaically:

 data: lv_class_name(60) type c.
data: method(60) type c.
data: lref_obj type ref to object.


lv_class_name = 'ZCL_BATCH_INPUT'.
method        = 'BDC_TRANSACTION'.
  
CREATE OBJECT lref_obj TYPE (lv_class_name).

CALL METHOD lref_obj->(METHOD)
EXPORTING
i_tcode = 'MM02'
i_mode = 'A'.

Max