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

ABAP Objects creation during runtime

Former Member
0 Likes
540

Hi ABAP Objects Experts,

I like to create several ABAP Object Instances of the same class during the runtime.

How can I create the objects dynamically?

e.g:

do X times.

concatenate 'object' sy-index into variable.

data: (variable) type ref to cl_xyz.

create object (variable).

enddo.

Thank you very much in advance for you response.

Kind regards

Axel

1 ACCEPTED SOLUTION
Read only

seshatalpasai_madala
Product and Topic Expert
Product and Topic Expert
0 Likes
444

Hi,

The best way is to create an internal table and then just create objects and push it on to this internal table.

See the below code.

DATA: it_obj_tab type table ref to cl_xyz,

wa_obj type ref cl_xvy.

Do X times.

create object wa_obj.

append wa_obj to it_obj_tab.

ENDDO.

If you want to create object of different type then take the class name in a vairabe like this.

DATA: class_name type string value 'CL_XYZ'.

create object wa_obj type class_name.

Regards,

Sesh

2 REPLIES 2
Read only

seshatalpasai_madala
Product and Topic Expert
Product and Topic Expert
0 Likes
445

Hi,

The best way is to create an internal table and then just create objects and push it on to this internal table.

See the below code.

DATA: it_obj_tab type table ref to cl_xyz,

wa_obj type ref cl_xvy.

Do X times.

create object wa_obj.

append wa_obj to it_obj_tab.

ENDDO.

If you want to create object of different type then take the class name in a vairabe like this.

DATA: class_name type string value 'CL_XYZ'.

create object wa_obj type class_name.

Regards,

Sesh

Read only

0 Likes
444

Works fine.

Thank you very much Sesh.

Regards

Axel