cancel
Showing results for 
Search instead for 
Did you mean: 

abstract classes vs. "real" classes

Former Member
0 Kudos
153

Hello, all.  I am pretty weak with OO - as will be made evident by the quesiton I am about to ask, so I ask for your patience as I am sure a knowledgable OO person can likely answer this pretty easily.

I am implementing a BAdi - PLM_AUDIT_ACT_LINK - that is used in transaction PLMD_AUDIT.  To give a brief description of PLMD_AUDIT, it is a tool for managing an "audit" which is comprised of a freely definable multi-node structure, where the structure nodes can be, for example, "question lists", "questions", and "follow up actions".  The structure if the audit is displayed as a tree on the upper left side of the screen.  My requirement involves being able to retrieve the top node of the tree - the audit name - from within the BAdi method which is invoked at a lower follow up action node.

Within the BAdi specified above, I am employing method CREATE_OBJECT_AT_RELEASE.  This, in turn, has an input parameter named IM_OBJECT, TYPE REF'd TO CL_CGPL_PROJECT.  Class CL_CGPL_PROJECT has a method that I can call to get details about the node above - GET_OUTLINE_PARENT.  Here is where my issue/question begins (I think).

GET_OUTLINE_PARENT returns an object TYPE REF'd TO CL_CGPL_HIERARCHY_NODE.  However, CL_CGPL_HIERARCHY_NODE is an abstract class - as defined in SE24.  I am not sure what this means exactly, except that I can't get the data I need!  When I debug the code, the value that is returned from GET_OUTLINE_PARENT is actually typed to CL_CGPL_TASK.  Class CL_CGPL_TASK is a private class referencing CL_CGPL_HIERARCHY_NODE as its superclass.

Class CL_CGPL_TASK has an attribute PARENT_PROJECT, itself TYPE REF'd TO CL_CGPL_PROJECT, and drilling into that, I can get down to a attribute PROJECT_ATTRIBUTES-EXTERNAL_ID, which is what I need.

The thing is, I cannot specify an object typed to CL_CGPL_TASK as a result when calling GET_OUTLINE_PARENT - although I know the actual result has that type.  So, my question is, how do I get to this PROJECT_ATTRIBUTES-EXTERNAL_ID attribute??  Or is there some other more simple way to get to this field?

Any and all insight is greatly appreciated.

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Bump.

Any OO gurus out there that can offer some insight?

Former Member
0 Kudos

For any who are interested, I have found my missing link.  I need to use the downward casting assignment operator - ?=.  So, the solution is to call the GET_OUTLINE_PARENT method specifying the object variable TYPE REF'd TO CL_CGPL_HIERARCHY_NODE (which is an abstract class) and then downward cast it to an object variable TYPE REF'd to  CL_CGPL_TASK (a "real" class).

Here's the code:

  DATA: l_extid                   TYPE cgpl_extid.

  DATA: l_parent           TYPE REF TO cl_cgpl_hierarchy_node,
        l_parent_task      TYPE REF TO cl_cgpl_task,
        l_parent_project   TYPE REF TO cl_cgpl_project.

  CALL METHOD im_object->get_outline_parent
     RECEIVING
       re_outline_parent = l_parent.

  l_parent_task    ?= l_parent.
  l_parent_project ?= l_parent_task->parent_project.
  l_extid           = l_parent_project->project_attributes-external_id.

Answers (0)