12-09-2008 8:03 AM
Hi experts, any one knows how to create internal table storing instances of ABAP class or alternative to implement such function?
12-09-2008 8:04 AM
Hi Jropckman,
Go through this link it will help u https://www.sdn.sap.com/irj/scn/advancedsearch?query=oops&cat=sdn_all
and
https://www.sdn.sap.com/irj/scn/advancedsearch?query=internaltablesortingusingclasses&cat=sdn_all
Regards,
Flavya
12-09-2008 8:52 AM
hi, Flavya, thanks for your information, but i didn't get answer yet. can you give me more concrete the example.
12-09-2008 8:57 AM
Why exactly do you need to store object references.As per my knowledge it can't be done as object references are defined at run time and they gets destroyed after the execution of a program. That is why its object oriented programming. We can definitely store attributes of an object in a dictionary table.
12-09-2008 9:04 AM
Does it mean, ABAP doesn't support "collection" such as Vector or List which are supported in other OO language?
12-09-2008 9:22 AM
Hi
Please see below example from ABAPDOCU, this might help you.
Internal Table cnt_tab is used to store class objects.
Regards,
Vishal
REPORT demo_objects_references.
CLASS counter DEFINITION.
PUBLIC SECTION.
METHODS: set IMPORTING value(set_value) TYPE i,
increment,
get EXPORTING value(get_value) TYPE i.
PRIVATE SECTION.
DATA count TYPE i.
ENDCLASS.
CLASS counter IMPLEMENTATION.
METHOD set.
count = set_value.
ENDMETHOD.
METHOD increment.
ADD 1 TO count.
ENDMETHOD.
METHOD get.
get_value = count.
ENDMETHOD.
ENDCLASS.
DATA: cnt_1 TYPE REF TO counter,
cnt_2 TYPE REF TO counter,
cnt_3 TYPE REF TO counter,
cnt_tab TYPE TABLE OF REF TO counter.
DATA number TYPE i.
START-OF-SELECTION.
CREATE OBJECT: cnt_1,
cnt_2.
MOVE cnt_2 TO cnt_3.
CLEAR cnt_2.
cnt_3 = cnt_1.
CLEAR cnt_3.
APPEND cnt_1 TO cnt_tab.
CREATE OBJECT: cnt_2,
cnt_3.
APPEND: cnt_2 TO cnt_tab,
cnt_3 TO cnt_tab.
CALL METHOD cnt_1->set EXPORTING set_value = 1.
CALL METHOD cnt_2->set EXPORTING set_value = 10.
CALL METHOD cnt_3->set EXPORTING set_value = 100.
DO 3 TIMES.
CALL METHOD: cnt_1->increment,
cnt_2->increment,
cnt_3->increment.
ENDDO.
LOOP AT cnt_tab INTO cnt_1.
CALL METHOD cnt_1->get IMPORTING get_value = number.
WRITE / number.
ENDLOOP.
12-09-2008 9:25 AM
thanks guys, i have found sap standard class for implementing this.
08-13-2015 5:00 AM