Skip to Content

OO : Using generic attribute in Superclass

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.

Add a comment
10|10000 characters needed characters exceeded

Assigned Tags

Related questions

1 Answer

  • Best Answer
    Posted on Aug 12, 2016 at 02:33 PM

    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>.

    Add a comment
    10|10000 characters needed characters exceeded

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.