SAP: SAPGUI Parse GuiUserArea

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

+7
source share
2 answers

Your code seems erroneous and slow for the following reasons:

  • intItemsShown is set, then you use it as a step in the loop and end up changing it in the loop.
  • You have a nested loop that just does Debug.Print, which can slow down your application further
  • Since you seem to cross the hierarchy of objects, it would be more appropriate for me to use recursive calls to
    handle children, children of children ... Analysis of output SAP structures may work, but are not clean and are likely to become a nightmare in the future.

My recommended alternatives

The first option requires ABAP from SAP. Two other options suggest that you have a web server integrated with SAP.

 For i = 0 To intVerticalScrollEndPoint Step intItemsShown ' <--intItemsShown is being used here .findById("wnd[0]/usr").VerticalScrollbar.Position = i intItemsShown = objSession.findById("wnd[0]/usr").Children.Count - 1 ' and modified here For n = 0 To intItemsShown ' and used here again Debug.Print .findById("wnd[0]/usr").Children.ElementAt(n).Text Next n Next i 
+2
source

First of all, thanks for submitting your question. Your efforts to try to solve your problem help me with mine.

Just found out some information that could help you handle horizontal and vertical scrollbars

In my case, I am working with PFCGGuiUserArea, which is an object of the GuiUserArea class. This class, as you indicated in your example, has two parameters: a horizontal panel and a vertical panel. From these two parameters (they were created on the basis of the class), you also have the minimum, maximum and page parameters.

In case of vertical:

 VerticalScrollbar Maximum: 349 '==> Total Rows of the GuiUserArea VerticalScrollbar Minimum: 0 '==> First Row of the GuiUserArea VerticalScrollbar Position: 1 '==> Position of the Cursor VerticalScrollbar Page Size: 34 '==> Total Rows per Page 

In the case of horizontal

 HorizontalScrollbar Maximum: 190 '==> Total of Columns available HorizontalScrollbar Minimum: 0 '==> First Column Available HorizontalScrollbar Position: 0 '==> Position of the cursor HorizontalScrollbar Page Size: 255 '==> Total Columns per Page 

So, you can improve your code pointing to these properties to solve a wide horizontal scroll. This will allow you to get accurate information from the system, so you do not need to transfer 1000 to a position.

Best regards, Cayo

0
source

All Articles