Show TOC

Background documentationCurrent Node Locate this document in the navigation structure

 

Exactly one node of the tree structures of the current template can be set as the current node at any place within a Simple Transformation (statically and during program execution). The current node shades the data roots in the sense that a reference ""name does not refer to a root "name", but to the component "name" of the current node (see Addressing Subnodes). If the current node is defined, it is the implicit operand of many ST commands, but you can also address it explicitly using $ref.

This section shows how you can set the current node explicitly with [tt:]ref. In addition, the tt:loop statement for transforming internal tables also sets the current node.

Note Note

At positions where the current node is not set explicitly, it is undefined and cannot be addressed using $ref. At these positions, the data roots are not shaded and you can address them with "name".

End of the note.
Setting the Current Node

The following options are available to set the current node explicitly:

By Command

The following ST command can be used to set the current node:

Syntax Syntax

  1. <tt:ref name="node">
  2. ...
  3. </tt:ref>
End of the code.

The tt:ref command sets the current node to the node specified in node. Any addressable data node can be specified for node. If no valid node is specified, the current node is undefined (see above).

The tt:ref command can be nested. It builds a context in which the currently set node is valid. Outside the corresponding XML element, the current outermost node is still valid. On the top level, the current node is always undefined.

The tt:ref command itself has no operational effect; it only influences the impact of the commands nested within it.

Note Note

As a result of the addressing rules, only a subnode of the current node can be set as the new current node, unless you are setting a data root.

End of the note.
By Command Attribute

In many ST commands, the current node can be specified as an attribute, as indicated below:

Syntax Syntax

  1. <tt:instructionref="node">
  2. ...
  3. </tt:instruction>
End of the code.

In this context, instruction is an ST command that can contain the ref attribute. The same rules apply to node as when you set it with the tt:ref command. If no attribute ref is specified, the command applies to the current node of the context.

The currently set node is valid only within the context of the ST command.

By Attribute of a Literal XML Element

In the literal XML elements of a template, you can set the current node as follows:

Syntax Syntax

  1. <element... tt:ref="node">
  2. ...
  3. </element>
End of the code.

In the example, element is a literal XML element. The special attribute tt:ref (in the namespace of the ST commands) sets the current node. The same rules apply to node as when you set it with the tt:ref command.

The currently set node is valid only within the context of the XML element.

Example

The following ST program can be used to serialize a nested ABAP structure:

Syntax Syntax

  1. <tt:transform xmlns:tt="http://www.sap.com/transformation-templates">
  2.   <tt:root name="ROOT"/>
  3.   <tt:template>
  4.     <X tt:ref="ROOT">
  5.       <X1>
  6.         <tt:value ref="COL1" />
  7.       </X1>
  8.       <X2>
  9.         <tt:value ref="COL2" />
  10.       </X2>
  11.       <X3 tt:ref="STRUC2">
  12.         <X1>
  13.           <tt:value ref="COL1" />
  14.         </X1>
  15.         <X2>
  16.           <tt:value ref="COL2" />
  17.         </X2>
  18.       </X3>
  19.     </X>
  20.   </tt:template>
  21. </tt:transform>
End of the code.

The current node is changed as follows:

  • At the beginning of the (nameless) main template, the current node is undefined. You can address the data root ROOT directly using "ROOT".

  • The current node is set to the data root for the entire element X. Within X, only ".ROOT" could be used for addressing the data root directly.

  • In the context of the two subsequent tt:value commands, the current node is set consecutively to the subnodes COL1 and COL2 of ROOT. The commands serialize or deserialize the ABAP data object that is bound to the current node.

  • The current node for literal element X3, which is nested in X, is set to another subnode STRUC2 of ROOT.

  • In the context of the two subsequent tt:value commands, the current node is set consecutively to the subnodes COL1 and COL2 of STRUC2.

  • Each time an element is exited, the current node is set back to that of the surrounding element.

Also see the example for calling a transformation in the Structures section.