cancel
Showing results for 
Search instead for 
Did you mean: 

Selecting Item in Tree by Text

Former Member
0 Kudos

Hello all, thanks in advance for the assistance!

I am trying to write a script for SAP that I call from Excel, and I know from working with this for a few days now that finding the right syntax for things is not easy. Currently, I am working with transaction IH01 and have a tree (? I hope this is the right word for it) pulled up. Ideally, a user in Excel would type in or select something in English like "Bundler" and the item in the SAP tree with text "Bundler" would be selected. When I try to record a macro to find out what this item is called in SAP scripting, I get something like:


session.findById("wnd[0]/usr/cntlTREE_CONTAINER/shellcont/shell").selectItem "         24","1"


Does anybody know an alternative syntax so I do not have to manually build a database of these and use a lookup table in Excel? I'd ideally like to make this program reapplicable to different sets of "trees" and not have to go through the 300 entries in this tree and write down the  "         24","1" for each one!


Thanks!


Alex




Accepted Solutions (0)

Answers (1)

Answers (1)

thomas_brutigam2
Active Participant
0 Kudos

Hi Alex.

had the same Problem - so i wrote a Function that alternates through the tree using a simple for next Loop and looks for the text you are searching for:

here is the Code:


Public Function ermitteln(was)

Set Tree = sapsession.findById("wnd[0]/usr/cntlTree_Container/shell/shellcont/shell")

ermitteln = "0"

For x = 0 To 300

adummy = 11

bdummy = adummy - Len(CStr(x))

a = Space(bdummy) & CStr(x)

  

On Error Resume Next

    Tree.selectItem a, "2"

    If Err.Number = 0 Then

        If Tree.GetItemText(a, "2") = was Then

            ermitteln = a

            Exit For

        End If

    End If

Next

End Function

the Selection Routine looks as follows:


node = ermitteln("Bundler")

session.findById("wnd[0]/usr/cntlTREE_CONTAINER/shellcont/shell").selectItem " & node,"1"

For Explanation:

The Text i was looking for is in Item "2"

so perhaps you have to Change it ...

If there should be any Questions - go ahead ...

hand

Thomas B

Former Member
0 Kudos

Thomas,

Thank you so much for your assistance, this is a great idea!

A few questions: Line 02 on the selection routine gives a syntax error, and the macro stops at line 2 in the function saying "Object required"

Thanks again!

Alex

thomas_brutigam2
Active Participant
0 Kudos

hi,should be lik ethis:

session.findbyId("wnd[0]/usr/cntlTREE_CONTAINER/shellcont/shell").SelectItem node,"1"

Former Member
0 Kudos

What should I do about line 2 which says that there is an "Object Required"?

I tried changing to Set Tree = session.findbyId("wnd[0]/usr/cntlTree_Container/shell/shellcont/shell") and I also tried "wnd[0]/usr/cntlTREE_CONTAINER/shellcont/shell", but neither did work.

Thank you for working me through this!