Start of Content Area

Background documentation Direct Reference to a Context Node  Locate the document in its SAP Library structure

To enable programming in a method on the context, the context of the method in question must be known. The first step therefore always consists of passing the reference to the context node.

 

Note Exception: A supply function is always called on a context node. The reference to this node is therefore automatically passed by the framework and the application developer does not pass the reference in the source code for the method. The following parameters are automatically recognized and are listed in the method signature:

NODE of type IF_WD_CONTEXT_NODE

PARENT_ELEMENT of type IF_WD_CONTEXT_ELEMENT

.

  

In all other controller methods, the determination of the reference must be programmed explicitly. This takes place on the basis of the context root node of a controller.

 

This graphic is explained in the accompanying text

Each controller method automatically recognizes the reference to the root node of its associated context. This reference is called WD_CONTEXT and is always of the type IF_WD_CONTEXT_NODE. The GET_CHILD_NODE method now enables the generation of a reference to the required subnodes.

 

 

method EXAMPLE .  

 

data: l_node type ref to IF_WD_CONTEXT_NODE.

 

l_node = wd_context->get_child_node( 'NODE_1' ).

 

. . . . . . . . .

 

endmethod.

   

 

Caution The name of the child node must always be specified in uppercase.

 

Avoiding Syntax Errors: Constants for Context Nodes

For every node you create in the context of a controller, a constant with the name WDCTX_<node name> is automatically created in the corresponding interface IG_<Controller_Name> and IF_<Controller_Name>. In the program source code for the controller, this constant can then be used instead of a string literal for the node name by using the reference to the local controller interface (WD_THIS attribute). Example:

 

 

wd_context->get_child_node( wd_this->wdctx_node_1 ).

 

instead of

 

wd_context->get_child_node( 'NODE_1' ).

 

 

The advantage of using constants is that the compiler knows the constant and, therefore, syntax errors are reported if the name of the context node contains typing errors. However, it is also possible to pass a string literal.

Using this kind of direct reference gives you access to a subnode of the context root node. For more information on referencing deeper context nodes, see Reference Path to Deeper Context Nodes.

 

 

 

 

End of Content Area