Skip to Content
author's profile photo Former Member
Former Member

Access to class attributs by coding in its mother class method definition

Hi all,

How can I retrieve information about a class attributs by coding?

And is it possible to access to the attributs of the Child class from the Mother class?

REPORT  ztest_method.
 
*----------------------------------------------------------------------*
******      CLASS mother DEFINITION

CLASS mother DEFINITION.
  PUBLIC SECTION.
    METHODS: get_data.
ENDCLASS.                    "mother DEFINITION

*----------------------------------------------------------------------*
******      CLASS child DEFINITION

CLASS child DEFINITION inheriting from mother.
ENDCLASS.                    "child DEFINITION
*----------------------------------------------------------------------*
*******      CLASS mother IMPLEMENTATION

CLASS mother IMPLEMENTATION.

  METHOD get_data.
 ***Can I access to child class attributs here?
  ENDMETHOD.                    "get_data
 
ENDCLASS.                    "mother IMPLEMENTATION
 
DATA oref TYPE REF TO CHILD.
DATA: method TYPE string.
DATA: cla_name(20).
 
START-OF-SELECTION.
  
  CREATE OBJECT oref .
 
  CALL METHOD oref->method).  "Here I want to access to this class's attribut without redefine it

Add a comment
10|10000 characters needed characters exceeded

Assigned Tags

Related questions

2 Answers

  • Posted on Oct 17, 2008 at 03:41 PM

    You can not access the attributes of the child class in the Super class.

    But, you can use the Attributes of the Child class with the reference of the Super Class if that reference has been initiated using the Child class (Narrow Casting).

    For your example, if you create a object for the Child class first and than assign it to Super Class than you can access the attributes or methods of the Child class using the Super Class reference.

    Check the example on Narrow Casting: http://help-abap.blogspot.com/2008/09/abap-objects-narrowing-cast-upcasting.html

    Regards,

    Naimesh Patel

    Add a comment
    10|10000 characters needed characters exceeded

  • Posted on Oct 30, 2008 at 09:46 AM

    But that is a link to this very thread?

    Regards,

    Thorsten

    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.