Skip to Content
-2

In step two are we doing down casting

Apr 02, 2017 at 08:44 PM

136

avatar image

Here is the algorithm to fill the context nodes in WD ABAP:

1. Declare variable referring to the context node:

MY_NODE type ref to IF_WD_CONTEXT_NODE.

2. Obtain the reference to the actual context node:

MY_NODE = WD_CONTEXT->GET_CHILD_NODE( ' <Name of the node> ' ).

3. Obtain the values in an internal table which is related to the type of the node

4. Bind the values to the node

MY_NODE->BIND_ELEMENTS ( <Value table> ).

Question elaboration :-

WD_CONTEXT is an attribute which is of TYPE REF TO IF_WD_CONTEXT_NODE.

So we are calling an method of the interface IF_WD_CONTEXT_NODE. GET_CHILD_NODE

So why are we decalring MY_NODE TYPE REF TO IF_WD_CONTEXT_NODE .Is it some kind of upcasting ?

or some other reason

10 |10000 characters needed characters left characters exceeded
* Please Login or Register to Answer, Follow or Comment.

4 Answers

Best Answer
harish vyas Apr 03, 2017 at 04:10 AM
-1

Hi Bodhisattwa,

In step 2, we are not downcasting, but 'NAVIGATING'.

Just to elaborate, CONTEXT NODES are of type IF_WD_CONTEXT_NODE, it may be root node (WD_CONTEXT) or any child node created under it.

Now lets say you want to read value of some attribute which is inside one of the child node of WD_CONTEXT, then you need to navigate (drill down) to get reference of that child node, and then read value of that attribute.

Statement MY_NODE = WD_CONTEXT->GET_CHILD_NODE( ' <Name of the node> ' ).

means that you are trying to navigate to a node (<Name of the node>), which is inside WD_CONTEXT (which refers to the root node of that controller).

Now lets say if there is one more node inside your child node, then to get reference of that node, you will have to write something like,

MY_CHILD_NODE_1 = WD_CONTEXT->GET_CHILD_NODE( ' CHILD_NODE_1 ' ).

MY_CHILD_NODE_2 = MY_CHILD_NODE_1->GET_CHILD_NODE( ' CHILD_NODE_2 ' ).

Hope this helps you to understand the concept.

Do let me know in case of any further concern.

Regards,

Harish


Show 3 Share
10 |10000 characters needed characters left characters exceeded

Understood , awesome explanation .I tried to up vote but its showing -1 instead of 1

0

Hi Matthew,

Thanks for the comments.

I used the word Navigating just to explain him the concepts of Nodes and how to navigate to get reference of child nodes.

I have given answer based on my understanding towards the question.

Anyways Vote doesn't matter for me, as far as we all learn something from each other :)

Regards,

Harish

1

Perhaps your mind-reading skills are better than ours, enabling you to give him the answer he wanted, but not the answer to the question he actually asked! :-)

0
Matthew Billingham
Apr 03, 2017 at 05:59 AM
3

No. It's not downcasting. Downcasting is casting to a subtype.

All you care about is that the object is a context node. The actual type of the context node is irrelevant for your purposes. The method wd_context->get_child_node returns an object that is a context node, so there's no need to have any other type.

It's what interfaces are used for. I suggest you read some articles about using interfaces and polymorphism in object oriented design. Some say that you should always use interfaces.

Share
10 |10000 characters needed characters left characters exceeded
Horst Keller
Apr 03, 2017 at 06:40 AM
3
Share
10 |10000 characters needed characters left characters exceeded
Tuncay Karaca Apr 03, 2017 at 05:59 PM
2

Hi Bodhisattwa,

I don't think there is a downcasting & upcasting here! You have a component / view / window attribute WD_CONTEXT (its type IF_WD_CONTEXT_NODE) that refers to your component / view / window context and this context has other nodes which has same type IF_WD_CONTEXT_NODE and by GET_CHILD_NODE returns this given name node.

Share
10 |10000 characters needed characters left characters exceeded