Skip to Content
0
Aug 12, 2016 at 02:30 PM

OO : Using generic attribute in Superclass

73 Views

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.