SAP — Read tree
SAP — Read tree
Section titled “SAP — Read tree”Type: sap-tree-read · Package: SAP Activities v1.0.5 · Output: List<Dictionary<string,object>>
Lists the nodes of an SAP tree (such as the SAP Easy Access menu or the navigation trees of many transactions) with their key, text and level. It is how you find the keys the other tree activities need, and it also lets you read a tree’s content as data.
How it works
Section titled “How it works”Waits for SAP to finish whatever it is processing, finds the tree by its selector and walks its nodes. For each node it returns an item with three fields:
| Field | Content |
|---|---|
key | Node key. It is the one used by SAP — Expand tree node and SAP — Select tree node. |
text | Visible text of the node. |
level | Depth of the node in the tree, as text. |
In SAP trees, nodes are identified by their key, not by their text or position. The key is assigned by the SAP program and is stable; the text changes with the session language, and the position changes as soon as another branch is expanded. Keys also tend to carry significant spaces (for example " 1"), so the safest thing is to take them from this activity’s output instead of typing them by hand.
If the control is not a tree, the activity fails and says so. If the tree is not on the screen yet, it waits for it up to the configured limit (timeout or the scope’s elementTimeout, 30 seconds by default).
Required parameters
Section titled “Required parameters”| Parameter | Type | Default | Description |
|---|---|---|---|
selector | selector | — | The tree. Captured selector or SAP id, for example wnd[0]/usr/cntlTREE/shellcont/shell. |
Optional parameters
Section titled “Optional parameters”| Parameter | Type | Default | Description |
|---|---|---|---|
session | ZoanSapSession | — | SAP session. Omit it inside the body of an SAP — Attach or SAP — Log on. |
timeout | number | — | 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. |
Output
Section titled “Output”Returns a List<Dictionary<string,object>>: a list with one item per loaded node, in the order SAP returns them, each with key (string), text (string) and level (the depth, as a string). If SAP can’t give a node’s text or level, that field is "". The log shows how many nodes were read.
Common errors
Section titled “Common errors”| Message | Cause and fix |
|---|---|
The control did not answer GetAllNodeKeys; is it really a GuiTree? | The selector does not point to a tree. Capture the tree’s shell. |
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.
Example
Section titled “Example”Find a node by its text and open it:
SAP — Read tree selector = "wnd[0]/usr/cntlTREE/shellcont/shell" → output: nodes
For Each items = nodes itemVariable = node └─ activities: If condition = node["text"] == "Monthly reports" └─ then: SAP — Select tree node selector = "wnd[0]/usr/cntlTREE/shellcont/shell" nodeKey = node["key"]Related activities
Section titled “Related activities”- SAP — Expand tree node — expand a branch to see its children.
- SAP — Select tree node — select or open a node.