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: 

Class with Attribute "type table of"

Former Member
0 Kudos

Hi,

how can I define a class A that has a member that is a table

that holds pointers to instances of A?

In Java, I would have written

class A {
  private List<A> followers = new ArrayList<A>();
.....

hope this helps to understand the question.

Thanks in advance,

Stefan

3 REPLIES 3

Former Member
0 Kudos

Hi,

Just have a look at the code excerpt below.

Create a class like

CLASS LCL_CLASS DEFINITION.

**put here your components.

ENDCLASS.

Implement your class.

then in your main program

write

data plane_list TYPE TABLE OF REF to lcl_airplane.

*this creates a ref variable which stores all the instances of that class.

use this may be this can be helpful.

Regards,

Khushboo

Former Member
0 Kudos

Hello,

Please read this [https://www.sdn.sap.com/irj/sdn/go/portal/prtroot/docs/library/uuid/0a33479c-0b01-0010-7485-dc8c09d6bc69], it's a good workshop that have good expanations concerning ABAP Objects with figures that can help you to associate ABAP OO with Java.

And [https://www.sdn.sap.com/irj/sdn/go/portal/prtroot/docs/library/uuid/25a3df90-0201-0010-10b6-9712397c22fd] is a text that compares the two technologies.

Regards,

former_member183804
Active Contributor
0 Kudos

Hello Stefan,

you need to declare a type that is an internal table of the class type. In newer releases you may define such a type within the class-pool itself. In older releases you need to stress the data dictionary.

Regards

Klaus


program z_Sample.

class lcl_Sample definition.
  public section.
     types:
        ty_Samples type standard table of ref to lcl_Sample with default key.

    methods:
      get_Aggregated_Samples
         returning
            value(result) type ty_Samples.

  private section.
     data: f_Samples type ty_Samples.
endclass.