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: 

OO : Using generic attribute in Superclass

mgross1
Participant
0 Kudos

Basic OO question:

I have a global class Main with 2 global subclasses Main_sub1 and Main_sub2.

In both Main_sub1 and Main_sub2 I will be selecting data from two different custom tables into internal tables.

Is it possible to use a static generic attribute gt_data in Main that can be used to store the data in both Main_sub1 and Main_sub2?

I tried it this way:

CLASS main DEFINITION
   PUBLIC
   ABSTRACT
   CREATE PUBLIC.

PROTECTED SECTION.
CLASS-DATA gt_data TYPE REF TO data.
   METHODS get_data
   ABSTRACT.


CLASS main_sub1 DEFINITION.
   PUBLIC
   INHERITING FROM main
   CREATE public.


     METHODS GET_DATA
     REDEFINITION.


CLASS main_sub1 IMPLEMENTATION.

      METHOD GET_DATA.

          FIELD-SYMBOLS : <fs_data> TYPE ztab1.

          ASSIGN gt_data->* TO <fs_data>.
          SELECT * ztab1 INTO TABLE gt_data.


     ENDMETHOD.

But the deferencing / field symbol assigning doesn't work.

1 ACCEPTED SOLUTION

Sandra_Rossi
Active Contributor
0 Kudos

correct your code as follows:

TYPES ty_ztab1 TYPE TABLE OF ztab1.

FIELD-SYMBOLS <fs_data> TYPE ty_ztab1.

CREATE DATA gt_data TYPE TABLE OF ztab1.

ASSIGN gt_data->* TO <fs_data>.

SELECT * ztab1 INTO TABLE <fs_data>.

2 REPLIES 2

Sandra_Rossi
Active Contributor
0 Kudos

correct your code as follows:

TYPES ty_ztab1 TYPE TABLE OF ztab1.

FIELD-SYMBOLS <fs_data> TYPE ty_ztab1.

CREATE DATA gt_data TYPE TABLE OF ztab1.

ASSIGN gt_data->* TO <fs_data>.

SELECT * ztab1 INTO TABLE <fs_data>.

0 Kudos

It works thanks!

I stupidly forgot the CREATE DATA line.