cancel
Showing results for 
Search instead for 
Did you mean: 

SAPGUI Scripting: How to search hierarchy for a node

Former Member
0 Kudos

Hi, I am working on a project in SAP BW. I want to use a script to search for a certain object in the tree of InfoProviders.When I use the recorder to search for a certain node (and then expand it) it generates this code for me:


REM start transaction
session.findById("wnd[0]/tbar[0]/okcd").text = "/nrsa1"

session.findById("wnd[0]").sendVKey 0


REM Search in the tree for object "ZCSG01"

session.findById("wnd[0]/shellcont[0]/shell/shellcont[1]/shell/shellcont[1]/shell").topNode = "          1"

session.findById("wnd[0]/shellcont[1]/shell/shellcont[0]/shell/shellcont[1]/shell/shellcont[1]/shell").topNode = "          1"

session.findById("wnd[0]/shellcont[1]/shell/shellcont[0]/shell/shellcont[1]/shell/shellcont[0]/shell").pressButton "%AWB_TREE_SEARCH"

session.findById("wnd[1]/usr/txtRSAWBN_S_DYNPRO_0500-SEARCH_TERM").text = "ZCSG01"

session.findById("wnd[1]/usr/txtRSAWBN_S_DYNPRO_0500-SEARCH_TERM").caretPosition = 6

session.findById("wnd[1]").sendVKey 0


REM "ZCSG01" is found as node 37

session.findById("wnd[0]/shellcont[1]/shell/shellcont[0]/shell/shellcont[1]/shell/shellcont[1]/shell").expandNode "         37"

session.findById("wnd[0]/shellcont[1]/shell/shellcont[0]/shell/shellcont[1]/shell/shellcont[1]/shell").topNode = "          1"

session.findById("wnd[0]/shellcont[1]/shell/shellcont[0]/shell/shellcont[1]/shell/shellcont[1]/shell").selectItem "         38","COL1"

session.findById("wnd[0]/shellcont[1]/shell/shellcont[0]/shell/shellcont[1]/shell/shellcont[1]/shell").ensureVisibleHorizontalItem "         38","COL1"

The generated code finds the node, but then (in the rest of the script) uses the absolute position "     37". This means that my script stops working when I insert a new object between node 1 and node 37. I would like to know if I can search for the name of the node so that I can dynamically determine the line number of the node.

Also, I am not able to find any proper documentation about how to work with hierarchies and the commands that are available. If anyone could help me in that respect that would be great too.

Accepted Solutions (0)

Answers (1)

Answers (1)

Former Member
0 Kudos

I found the solution: See the changes that I marked in BOLD.


twan.jans-beken wrote:

Hi, I am working on a project in SAP BW. I want to use a script to search for a certain object in the tree of InfoProviders.When I use the recorder to search for a certain node (and then expand it) it generates this code for me:

REM start transaction
session.findById("wnd[0]/tbar[0]/okcd").text = "/nrsa1"

session.findById("wnd[0]").sendVKey 0


REM Search in the tree for object "ZCSG01"

session.findById("wnd[0]/shellcont[0]/shell/shellcont[1]/shell/shellcont[1]/shell").topNode = "          1"

session.findById("wnd[0]/shellcont[1]/shell/shellcont[0]/shell/shellcont[1]/shell/shellcont[1]/shell").topNode = "          1"

session.findById("wnd[0]/shellcont[1]/shell/shellcont[0]/shell/shellcont[1]/shell/shellcont[0]/shell").pressButton "%AWB_TREE_SEARCH"

session.findById("wnd[1]/usr/txtRSAWBN_S_DYNPRO_0500-SEARCH_TERM").text = "ZCSG01"

session.findById("wnd[1]/usr/txtRSAWBN_S_DYNPRO_0500-SEARCH_TERM").caretPosition = 6

session.findById("wnd[1]").sendVKey 0


Dim strKey

Dim strTxt1, strTxt2

strKey = session.findById("wnd[0]/shellcont[1]/shell/shellcont[0]/shell/shellcont[1]/shell/shellcont[1]/shell").GetFocusedNodeKey

strTxt1 = Right("           " & Cstr(strKey), 11)

strTxt2 = Right("           " & Cstr(strKey + 1), 11)


REM "ZCSG01" is found as node 37

session.findById("wnd[0]/shellcont[1]/shell/shellcont[0]/shell/shellcont[1]/shell/shellcont[1]/shell").expandNode strTxt1

session.findById("wnd[0]/shellcont[1]/shell/shellcont[0]/shell/shellcont[1]/shell/shellcont[1]/shell").topNode = "          1"

session.findById("wnd[0]/shellcont[1]/shell/shellcont[0]/shell/shellcont[1]/shell/shellcont[1]/shell").selectItem strTxt2,"COL1"

session.findById("wnd[0]/shellcont[1]/shell/shellcont[0]/shell/shellcont[1]/shell/shellcont[1]/shell").ensureVisibleHorizontalItem strTxt2,"COL1"

The generated code finds the node, but then (in the rest of the script) uses the absolute position "     37". This means that my script stops working when I insert a new object between node 1 and node 37. I would like to know if I can search for the name of the node so that I can dynamically determine the line number of the node.

Also, I am not able to find any proper documentation about how to work with hierarchies and the commands that are available. If anyone could help me in that respect that would be great too.

So the short answer is: The command to use is
session.findById("wnd[0]/...").GetFocusedNodeKey