Problem!
Currently in the place where I work. We are trying to perform some kind of repetitive task automatically using SAPGui, Excel and VBA. Usually, most of the reports that we collect from SAP TCodes are displayed using GuiUserArea, which is not easy, accurate and quick to parse.
Decision!
In any case, I managed to parse such reports depending on certain types of requirements. So, the first time I tried to parse any report (shown as GuiUserArea), I came up with the idea that it would be easy to save the report as unformatted text, and then go and parse it using VBA (Regexes, Splits, Text Length, .. .) instead of using GuiUserArea methods and properties.
Please note that using this procedure (saving files) is easier and faster to parse information. But what's the point of using the SAPGUI object only to save files, and not to perform more complex tasks, such as parsing information ...
Working with GuiUserArea I came up with the following solution:
Sub ParseSAPGUI() Dim objSAPGui As Object Dim objApplication As Object Dim objConnection As Object Dim objSession As Object If (objSAPGui Is Nothing) Then Set objSAPGui = GetSAPGuiObject() Set objApplication = GetSAPGuiScriptEngine(objSAPGui) End If If (objConnection Is Nothing) Then Set objConnection = GetSAPGuiConnection(objApplication) End If If (objSession Is Nothing) Then Set objSession = GetSAPGuiSession(objConnection) End If With objSession Dim intItemsShown As Integer Dim intVerticalScrollEndPoint As Integer Dim intHorizontalScrollEndPoint As Integer ' Move to the end of the GuiUserArea .findById("wnd[0]/usr").HorizontalScrollbar.Position = 10000 .findById("wnd[0]/usr").VerticalScrollbar.Position = 10000 ' Store end points intVerticalScrollEndPoint = .findById("wnd[0]/usr").VerticalScrollbar.Position intHorizontalScrollEndPoint = .findById("wnd[0]/usr").HorizontalScrollbar.Position ' Move to the start of the GuiUserArea .findById("wnd[0]/usr").HorizontalScrollbar.Position = 0 .findById("wnd[0]/usr").VerticalScrollbar.Position = 0 ' Items per page being shown intItemsShown = objSession.findById("wnd[0]/usr").Children.Count - 1 Dim i As Integer Dim n As Integer For i = 0 To intVerticalScrollEndPoint Step intItemsShown .findById("wnd[0]/usr").VerticalScrollbar.Position = i intItemsShown = objSession.findById("wnd[0]/usr").Children.Count - 1 For n = 0 To intItemsShown Debug.Print .findById("wnd[0]/usr").Children.ElementAt(n).Text Next n Next i End With End Sub
The code shown above works just fine, except for the following statements:
It almost analyzes all GuiUserArea reports, with the exception of those that have a wide horizontal window. I am working to fix this problem, but there is a lack of documentation for the SAPGUI object.
Slow and very slow for a large amount of data (as expected, since we use VBA for COM objects). I tried to work with .NET objects and SAPGUI without any success in order to speed up the process.
But at the end of the path, it seems that the SAPGUI object was not intended for such tasks.
Questions!
- Do you have another method to try to parse GuiUserArea?
- Have you tried using a high-level programming language (or even a scripting language) to interact with SAP instead of VBA?
- Do you know if there is another way to interact with SAP and not with the SAPGUI object (have you tried the SAP.NET connector?)
~ Eder Quiñones
Eder
source share