Recently I received suggestion to dig in the problem of pop up table-windows in SAP, which content is bigger than its size. The funniest thing is that, it’s not issue only in SAP scripting, but also such software like Winshutle is having some troubles with that. In this article I’m going to get throught this problem and present You 2 ways of how to automate scrolling in SAP table.
What is the problem?
Let’s take for example table-window from VA01 transaction. Click on the button showed in the screen (pointed with arrow) to go to Order Type table.
Here You can see 31 rows of data under the headline. The last row is 88th.
How do I know that?
First things first. Lets record, using SAP script recorder, opening of this table and select, for example, the last visible position of data.
session.findById("wnd").maximize session.findById("wnd").sendVKey 4 session.findById("wnd/usr/lbl[6,32]").setFocus session.findById("wnd/usr/lbl[6,32]").caretPosition = 5
Thanks to that we can check all the properties of the table – treating that as a parent of selected position:
or just get the table name from ID above:
Add this to Watches.
Here we got 2 very interesting properties: Children & VerticalScrollBar.
So Children property got the Count value 64, which is nowhere near 31 rows of data, but twice as much as row position of last selected value (32).
So I checked few first Items and found out that every single value in the table is treated like table cell – item. The first two are the headers and the rest of them are the values under the headerline.
(headers + visible data) * columns = children (1 + 31) * 2 = 64
Additionally I noticed that there is no such position like 2nd row. First 2 Items are in the first row, but 3rd & 4th Item skipped 2nd row having the 3rd row in rows position.
To check that by yourself see the position in the table of AA value in the first column (DisplayedText property) on the second screenshot in this article.
VerticalScrollBar property is fortunately much shorter to look through.
We can see here the range of motion (Minimum & Maximum), actual position of the bar (Position) – so it is in its Minimum position and the amount of data rows (PageSize & Range).
Why it doesn’t take the header to counter?
Probably because You can’t scroll the header, only the data under the headline. And that’s why we see only 31.
Unfortunately, in both properties there was no info about other records higher that 31 row. Even if we scroll further and check the properties of SAP object, we will be able to see info only about rows, which are visible. No more.
So how to deal with this?
I prepared for You a classic solution, which is commonly used also in Winshuttle and my solution, especially for VBA.
1 METHOD- PAGE DOWN button
In SAP automation, to get the value from the bottom of the list, the classic solution is to use PageDown button. In case of Winshutle, You need to record exact amount of times You need to press that button to get to the specified value – make it visible in the table-window.
In VBA & Sap Scripting You don’t have to behave like that. It’s much easier. You can use pros of programming – loops. So, in short, You need to loop through the visible values list until You find the value. When the lists ends, press PageDown button. If the vertical scroll bar reached the max position, leave the loop.
So first of all let’s take the:
Dim pageSize As Long, maximum As Long, i As Long, firstElement As Long, lastElement As Long pageSize = session.findById("wnd/usr/lbl[6,32]").Parent.verticalscrollbar.pageSize maximum = session.findById("wnd/usr/lbl[6,32]").Parent.verticalscrollbar.maximum Const FIRST_ELEMENT = 3 Const PAGE_DOWN = 82 lastElement = FIRST_ELEMENT + pageSize - 1
pageSize – the amount of rows with scrollable data,
maximum – the max position of vertical scrollbar (which will be useful for the condition to exit the loop),
FIRST_ELEMENT – as the number of first row with data,
PAGE_DOWN – number for the PageDown button as the .sendVKey action,
lastElement – last row position of table data.
i = FIRST_ELEMENT Do While Trim(session.findById("wnd/usr/lbl[6," & i & "]").displayedText) <> "Project return" If i = lastElement Then If session.findById("wnd/usr").verticalscrollbar.Position = maximum Then Exit Do End If session.findById("wnd").sendVKey PAGE_DOWN i = FIRST_ELEMENT - 1 End If i = i + 1 Loop
Then set the iterator to FIRST_ELEMENT and loop while your specified value (in my example Project return) is different then .displayedText of the next Item in the table. When meeting the lastElement of the visible content and the vertical scroll bar position is not equal to its maximum, then press the PageDown button and start checking from the beginning to the end of the visible list again.
session.findById("wnd/usr/lbl[6," & i & "]").SetFocus session.findById("wnd").sendVKey 2
After that You need to select the row, where the loop found your specified value, and confirm that.
2 METHOD – VERTICAL SCROLLBAR POSITION
When I was having fun with the scroll bar automation, I discovered, that You can actually go further with the position of the bar than its maximum. It is not possible manually, but it is possible doing it with VBA.
Despite seeing the property maximum of the vertical scroll bar set to 88, we can go beyond that. Thanks to the revelation we can just check the first position of the list and scroll the bar until we reach the last value of whole table list.
Do While Trim(session.findById("wnd/usr/lbl[6," & FIRST_ELEMENT & "]").displayedText) <> "Project return" session.findById("wnd/usr").verticalscrollbar.Position = session.findById("wnd/usr").verticalscrollbar.Position + 1 Loop
So like I said – loop while the .displayedText of the selected item is different than the specified value. If it is, just change the position of the vertical scroll bar by 1.
session.findById("wnd/usr/lbl[6," & FIRST_ELEMENT & "]").SetFocus session.findById("wnd").sendVKey 2
If it’s not, select (SetFocus) on the first row and confirm.
That were 2 methods of how to automate scrolling in SAP table! Of course You could add some conditions in case of any error appeared or anything You wish. I just wanted to give You a nice perspective of what is possible in SAP automation and how it is possible. I hope You like that!