2005 Aug 05 11:31 AM
Hello,
please, look at this simple scenario:
DATA:
my_class type ref to zcl_xyz.
create object my_class.
In that case I have just created one instance. Now I need a mechanism to create and identify any number of instance of the type zcl_xyz. <b>That means, I dont know exactly, if I need 5 or 200 instances.</b> Any feasible idea, how to handle that?
Thanks and regards.
2005 Aug 05 11:42 AM
You can have an internal table which will store the reference to this object.
eg:
data:
my_class type table of ref to zcl_xyz.
do N times.
create object my_class_tmp.
append my_class_temp to my_class.
enddo.
Remember 2 reward points to replies that answered ur question.
2005 Aug 05 11:42 AM
You can have an internal table which will store the reference to this object.
eg:
data:
my_class type table of ref to zcl_xyz.
do N times.
create object my_class_tmp.
append my_class_temp to my_class.
enddo.
Remember 2 reward points to replies that answered ur question.
2005 Aug 05 11:44 AM
Hi,
Why don't you use internal table to store the instances of the class.
types: my_class type ref to zcl_xyz,
my_table type standard table of my_class.
Svetlin
2005 Aug 05 12:03 PM
Hi,
Declare one static attribute in the class.
Here is the sample code to trap the number of instance created for an object type.
CLASS C1 DEFINITION.
PUBLIC SECTION.
CLASS-DATA CREATE_COUNT TYPE I.
METHODS CONSTRUCTOR.
ENDCLASS.
DATA: O1 TYPE REF TO C1,
O2 LIKE O1,
O3 LIKE O1.
CREATE OBJECT: O1,
O2,
O3.
WRITE: 'Number of created objects:', C1=>CREATE_COUNT.
CLASS C1 IMPLEMENTATION.
METHOD CONSTRUCTOR.
CREATE_COUNT = CREATE_COUNT + 1.
ENDMETHOD.
ENDCLASS.
Hope this hint helps you.