Hi All. I am back with this new post. Many times this
question has been asked on many forums. However, there are hardly any suitable/complete
answer. One of my reader has requested me to post on this topic. I took some
time out of my schedule and am posting my findings. I hope you find it useful.
Below code is a sample code which I have written. This uses a descriptive programming which means it will work for any SAPGuiTree. No need to bother about objects. This code
searches for a particular node and
activates it. This function also gives the total node count and navigates through
each one of them. Please leave your comment if you find it useful.
'************************************************************************
'Function Name: SAP_Search_And_Activate_Node_In_SAPGuiTree
'Description: Searches and activates a node in SAPGuiTree using the search node text parameter.
'Parameter: Search node text, enter a value that you want to search,
' For example if you are looking for Outbound
delivery no, you can enter the full text or just delivery for search key
'Return Value: Returns True/False
'Author: Ankesh
'Creation Date:
'**********************************************************************
Function SAP_Search_And_Activate_Node_In_SAPGuiTree(strSearchNodeText)
'get all the objects of SAPGUITree
'Descriptive programming has been used
Set ObjSAPGuiTree =
SAPGuiSession("micclass:=SAPGuiSession").SAPGuiWindow("micclass:=SAPGuiWindow").SAPGuiTree("micclass:=SAPGuiTree").Object
'Get the node keys , a key is a number/position in the
'A key value starts from 1.
Set ObjKeyValues = ObjSAPGuiTree.GetAllNodeKeys
'get the total count
''This count indicates the number of items/nodes in the Tree
intNodeCount = ObjKeyValues.Count
blnFlag=False
'Iterate through the nodes of the tree
For i = 0 to intNodeCount-1
'Get the node text
strNodeText=ObjSAPGuiTree.GetNodeTextByKey(ObjKeyValues(i))
'Check if the match was found for the key that you are looking for
'if yes then activate the item
If Instr(strNodeText,strSearchNodeText)>0 Then
'Select the node and double click on it
'This is equivalent to ActivateItem
ObjSAPGuiTree.SelectNode ObjKeyValues(i)
ObjSAPGuiTree.DoubleClickNode ObjKeyValues(i)
blnFlag=True 'set a flag to indicate the macth was found
Exit For
End If
Next
'Chk the flag and return values to function
If blnFlag Then
SAP_Search_And_Activate_Node_In_SAPGuiTree=True
Else
SAP_Search_And_Activate_Node_In_SAPGuiTree=False
End If
'Release the objects
Set ObjKeyValues=Nothing
Set ObjSAPGuiTree=Nothing
End Function