‎2007 Apr 10 11:02 AM
Hello,
I'm a former JAVA Developer and trying to use the Features of ABAP Objects as much as possible. Now I got the problem that I have to store several instances of the same class. The number of instances is dynamic and I have to access these instances in a loop merely at the end of the program for logging purposes. Is this possible? I'm working on release 4.6c.
Thank you in advance for your help.
‎2007 Apr 10 1:25 PM
Hello Steffen
If class <b>CL_SWF_UTL_ITERATOR</b> is available on 4.6c (available on 6.20 and higher) then you can use this iterator class for storing your instances. Alternatively, you could define your own data type for storing instances, e.g.:
TYPES: BEGIN OF ty_s_iterator.
TYPES: instance TYPE REF TO object.
TYPES: END OF ty_s_iterator.
TYPES: ty_t_iterator TYPE STANDARD TABLE OF ty_s_iterator
WITH DEFAULT KEY.
DATA:
ls_list TYPE ty_s_iterator,
lt_list TYPE ty_t_iterator.You can add any reference type to this list. When reading the list you need to do the appropriate casting.
Regards
Uwe
‎2007 Apr 10 1:25 PM
Hello Steffen
If class <b>CL_SWF_UTL_ITERATOR</b> is available on 4.6c (available on 6.20 and higher) then you can use this iterator class for storing your instances. Alternatively, you could define your own data type for storing instances, e.g.:
TYPES: BEGIN OF ty_s_iterator.
TYPES: instance TYPE REF TO object.
TYPES: END OF ty_s_iterator.
TYPES: ty_t_iterator TYPE STANDARD TABLE OF ty_s_iterator
WITH DEFAULT KEY.
DATA:
ls_list TYPE ty_s_iterator,
lt_list TYPE ty_t_iterator.You can add any reference type to this list. When reading the list you need to do the appropriate casting.
Regards
Uwe
‎2007 Apr 12 9:45 AM
Hello again,
thanks for your very fast responses. The class CL_SWF_UTL_ITERATOR isn't available on our system. The type definition is working, but how can I declare this as an global class attribute in Class Builder SE24? I can obviously only use 'Like', 'Type' and 'Type Ref To'?
‎2007 Apr 12 9:56 AM
Hi Steffen ,
I think you can do it by creating your own types in SE11 .
You can create a table type with reference of your class .
Regards
‎2007 Apr 12 10:03 AM
Hello Steffen
If you want to have the object list as public attribute you need a <b>DDIC </b>type. Have a look at the following sample report (created on our 4.6c system):
*&---------------------------------------------------------------------*
*& Report ZUS_INSTANCE_LIST *
*& *
*&---------------------------------------------------------------------*
*& *
*& *
*&---------------------------------------------------------------------*
REPORT zus_instance_list .
DATA:
go_docking TYPE REF TO cl_gui_docking_container,
gs_list TYPE zus_instance,
gt_list TYPE zus_instance_ttyp.
" NOTE: ZUS_INSTANCE has been defined as structure with:
" component componenttype
" INSTANCE OBJECT
" ZUS_INSTANCE_TTYP is a table type with line type ZUS_INSTANCE
START-OF-SELECTION.
" Add instances to list
DO 10 TIMES.
CREATE OBJECT go_docking.
gs_list-instance = go_docking.
APPEND gs_list TO gt_list.
ENDDO.
" Read instances from list
LOOP AT gt_list INTO gs_list.
go_docking ?= gs_list-instance.
ENDLOOP.
END-OF-SELECTION.Regards
Uwe
‎2007 Apr 12 11:41 AM
I found a way by defining a local type in the class. With the Shortcut CTRL + F5 it is possible to define the types directly in the source code.
‎2007 Apr 10 11:04 PM
Hi Steffen,
You can create an array of instances of a class by using the keyword
'TYPE TABLE OF REF TO'.
For eg: say <b>ZSP_CLASS</b> is the class, for which you have to create an array of instances.
Let <b>inst_tab</b> be the int.table storing the array of instances.
Declaration of inst_tab should be like this.
data: inst_tab <b>type table of ref to</b> ZSP_CLASS.
Hope this helps you.
Regards,
SP.
‎2007 Apr 11 1:11 AM
And the loop would then look like this.
data: inst_tab type table of ref to ZSP_CLASS,
oref type ref to ZSP_CLASS.
loop at inst_tab into oref.
endloop.cheers
Thomas