Skip to content

SAP — Expand tree node

Type: sap-tree-expand  ·  Package: SAP Activities v1.0.5

Expands a node of an SAP tree so its children become visible, or collapses it if you turn on collapse. Use it to reach a node inside a closed branch, or before reading the tree with SAP — Read tree so the read includes those children.

Waits for SAP to finish whatever it is processing, finds the tree by its selector and expands the node whose key is nodeKey (or collapses it, with collapse = true). Then it waits for SAP to load the content.

The node is given by its key, not by its text. The key is assigned by the SAP program and usually carries significant spaces; that is why it is best to take it from the output of SAP — Read tree instead of typing it by hand. If the tree does not accept the key, the activity fails with a message that reminds you of this.

If the tree is not on the screen yet, the activity waits for it up to the configured limit (timeout or the scope’s elementTimeout, 30 seconds by default).

ParameterTypeDefaultDescription
selectorselector—The tree (GuiTree). Captured selector or SAP id, for example wnd[0]/usr/cntlTREE/shellcont/shell.
nodeKeystring—Node key. Get it with SAP — Read tree: it is not the visible text. Ex: " 1".
ParameterTypeDefaultDescription
sessionZoanSapSession—SAP session. Omit it inside the body of an SAP — Attach or SAP — Log on.
collapseboolfalseCollapse the node instead of expanding it. Also accepts an expression that returns true or false.
timeoutnumber—Seconds to wait for the tree to appear. Overrides the scope’s elementTimeout. Empty uses the scope value (30 by default); 0 fails on the first try. Decimals allowed.

This activity does not return a value.

MessageCause and fix
The tree did not accept the key '…'. Keys are assigned by the ABAP program and carry significant spaces; get them with sap-tree-read instead of typing them by hand. (…)The key doesn’t exist in the tree, or has missing or extra spaces. Take it from the output of SAP — Read tree.
Component '…' does not exist in the SAP session. Waited … s for it to appear. The current screen is … dynpro … (transaction …). …The element did not appear in time. The message says which screen the session is on: it is almost always a different one than expected (a dialog in front, a step that didn’t happen). If the screen is slow, raise timeout.

Plus the errors common to all activities.

Expand a folder and read the tree with its children now visible:

SAP — Read tree selector = "wnd[0]/usr/cntlTREE/shellcont/shell" → output: nodes
SAP — Expand tree node selector = "wnd[0]/usr/cntlTREE/shellcont/shell" nodeKey = nodes[0]["key"]
SAP — Read tree selector = "wnd[0]/usr/cntlTREE/shellcont/shell" → output: nodes