‎2009 Sep 02 2:46 PM
Hallo Guru,
I'm looking for a way to append newly created objects of a class "XYZ" in an internal table.
Best Regards,
Kais
‎2009 Sep 02 2:55 PM
Declare a field in the table with
oref type ref to ZCL_MY_CLASS,
and store your object in it.
‎2009 Sep 02 2:49 PM
Hi,
Can you elaborate your query in details?
Regards,
Ankur Parab
‎2009 Sep 02 2:54 PM
Hi Ankur,
I've created a new class.
And now I created a Progam which 2 or 3 instances of this class has been created, using CREATE OBJECT.
I put some information on it.
Now, I want to use an internal table, which ref to my class.
And I want to save every instance with its information in the internal table.
So, later I'm going to loop over the internal table to print out the information.
Regards,
Kais
‎2009 Sep 02 2:55 PM
Declare a field in the table with
oref type ref to ZCL_MY_CLASS,
and store your object in it.
‎2009 Sep 02 3:10 PM
Hi Rainer,
Thanks for your Respond.
What I actually looking for is how to insert the object in the table.
This's how it looks like.
DATA : it_employees TYPE TABLE OF REF TO lcl_employee WITH HEADER LINE,
r_employee TYPE REF TO lcl_employee.
START-OF-SELECTION.
CREATE OBJECT r_employee
EXPORTING
im_name = '******'
im_firstname = '*****'
im_base_salary = 1000
im_dob = '******'.
r_employee->set_address( im_address = '*******' ).
*???? How to insert the Object in The table
LOOP AT it_employees.
it_employees->print( ).
ENDLOOP.
Regards,
Kais
‎2009 Sep 02 3:15 PM
Hi
U need to append the object in the table like a normal workarea:
CLASS LC_MY_CLASS DEFINITION.
PUBLIC SECTION.
METHODS: CONSTRUCTOR
IMPORTING P_NAME TYPE CHAR20,
WRITE_NAME.
PRIVATE SECTION.
DATA: NAME TYPE CHAR20.
ENDCLASS. "LC_MY_CLASS DEFINITION
CLASS LC_MY_CLASS IMPLEMENTATION.
METHOD CONSTRUCTOR.
NAME = P_NAME.
ENDMETHOD. "CONSTRUCTOR
METHOD WRITE_NAME.
WRITE: / NAME.
ENDMETHOD. "WRITE_NAME
ENDCLASS. "LC_MY_CLASS IMPLEMENTATION
TYPES: TY_OBJ TYPE REF TO LC_MY_CLASS.
DATA: MY_OBJ TYPE REF TO LC_MY_CLASS,
T_OBJ TYPE TABLE OF TY_OBJ.
START-OF-SELECTION.
CREATE OBJECT MY_OBJ
EXPORTING
P_NAME = 'MAX'.
APPEND MY_OBJ TO T_OBJ.
CREATE OBJECT MY_OBJ
EXPORTING
P_NAME = 'MAX 2'.
APPEND MY_OBJ TO T_OBJ.
LOOP AT T_OBJ INTO MY_OBJ.
CALL METHOD MY_OBJ->WRITE_NAME.
ENDLOOP.Max
‎2009 Sep 02 3:21 PM
‎2009 Sep 02 2:58 PM
Hello Kais
If you already on ECC 6.0 then you may have a look at the iterator class SWF_UTL_OBJECT_TAB. An appropriate table type for you would be SWF_UTL_OBJECT_TAB.
Regards
Uwe