Application Development Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 

How to create internal table storing instances of ABAP class

Former Member
0 Kudos

Hi experts, any one knows how to create internal table storing instances of ABAP class or alternative to implement such function?

7 REPLIES 7

Former Member
0 Kudos

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

0 Kudos

hi, Flavya, thanks for your information, but i didn't get answer yet. can you give me more concrete the example.

former_member212653
Active Contributor
0 Kudos

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.

0 Kudos

Does it mean, ABAP doesn't support "collection" such as Vector or List which are supported in other OO language?

0 Kudos

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.

0 Kudos

thanks guys, i have found sap standard class for implementing this.

0 Kudos

Hi, jrockman.

could you please share the standard class name?