0

I'm writing a script that adds elements to a list in a SAP GUI screen. Now, it seems that when using SAP GUI, nothing "exists" unless it is actually on screen, so the first step involves finding the end of the list.

I accomplished this by scrolling though each element, and checking if it was blank.

Do While Not blank
If session.findById("wnd[1]/usr/tblSAPLCZDITCTRL_4010/ctxtMAPL-MATNR[2,0]").Text = "" Then blank = True
session.findById("wnd[1]/usr/tblSAPLCZDITCTRL_4010").verticalScrollbar.Position = i
i = i + 1
Loop

However, for very large existing lists, this takes a long time. I'm trying to figure out a way to find the end more quickly. Some truths/limitations I know:

  1. I'm assuming I have no knowledge of the list length.
  2. I cannot command the verticalScrollbar.position too far beyond the end of
    the list. For ex. if the list contains 62 elements, .verticalScrollbar.Position = 100 will not work.
  3. In the case of the above example, SAP does NOT throw an error. Nothing happens at all, and then next line of code executes.
  4. All references to elements are with respect to their position on the screen. Ex, if I scroll down 5 positions, the 6th element of the overall list would actually indexed as 1.
  5. On the other hand, verticalScrollbar.Position is absolute

I'm thinking of doing the following (in very psuedocode):

i = 0
do while scrolled = true
    scrolled = false
    a = GUIlist[0]
    verticalScrollbar.Position = i + 1000
    b = GUIlist[0]
    'check to see the first element shown has changed
    if a <> b then 
        scrolled = true
        i = i + 1000
    end if
loop

do while scrolled = true
    scrolled = false
    a = GUIlist[0]
    verticalScrollbar.Position = i + 500
    b = GUIlist[0]
    if a <> b then 
        scrolled = true
        i = i + 500
    end if
loop

...and so on until I'm iterating i by one.

Is there a generally accepted better way of doing this kind of 'search'? Any input is appreciated. Thanks

bbadgett
  • 70
  • 1
  • 7

2 Answers2

3

My suggestion:

session.findById("wnd[0]").sendVKey 83 
myPosition = session.findById("wnd[1]/usr/tblSAPLCZDITCTRL_4010").verticalScrollbar.Position
do 
if session.findById("wnd[1]/usr/tblSAPLCZDITCTRL_4010/ctxtMAPL-MATNR[2,0]").Text = ""  then exit do
myPosition = myPosition + 1
session.findById("wnd[1]/usr/tblSAPLCZDITCTRL_4010").verticalScrollbar.Position = myPosition
loop 
msgbox myPosition

Regards, ScriptMan

ScriptMan
  • 1,580
  • 1
  • 9
  • 9
3

Just to go to the end

max_scrollbar = session.findById("wnd[1]/usr/tblSAPLCZDITCTRL_4010").verticalScrollbar.Maximum ' Get the maximum scrollbar value
session.findById("wnd[1]/usr/tblSAPLCZDITCTRL_4010").verticalScrollbar.Position = max_scrollbar  ' Go to the end 
PankajKushwaha
  • 878
  • 2
  • 11
  • 25