‎2007 Feb 06 7:47 AM
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
‎2007 Feb 06 8:37 AM
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
‎2007 Feb 06 8:37 AM
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
‎2007 Feb 06 8:47 AM