0

I'm creating a code to download some material information, by first asking SAP to get a certain plant information. Then I'm switching the drill down to the Business Area (BA) and lastly I have to Drilldown each BA by Material Code.

Where I'm running into issues is when I'm making the Drilldown by Material Code (the second "for"), since each of the plants has a different number of Business Areas. Could you tell how can I know the number of rows of the first Business Area table?

The code also has to export the Material Code data to an excel sheet, but I didn't include that in the following code.

This is the code I'm using:

If Not IsObject(application) Then
   Set SapGuiAuto  = GetObject("SAPGUI")
   Set application = SapGuiAuto.GetScriptingEngine
End If
If Not IsObject(connection) Then
   Set connection = application.Children(0)
End If
If Not IsObject(session) Then
   Set session    = connection.Children(0)
End If
If IsObject(WScript) Then
   WScript.ConnectObject session,     "on"
   WScript.ConnectObject application, "on"
End If

'Startup
session.findById("wnd[0]").maximize

'Variables
filepath = "30-06-2022" 'Poner la fecha del dia de descarga
CurrentDate = "07/2022" 'Poner el mes del analisis
PlantList = Array(NameOfAllThePlants)

'Search for MCBA
session.findById("wnd[0]/tbar[0]/okcd").text = "MCBA"
session.findById("wnd[0]").sendVKey 0

For i = 0 To 23 Step 1
'MCBA Parameters
    session.findById("wnd[0]/usr/ctxtSL_WERKS-LOW").text = PlantList(i)
    session.findById("wnd[0]/usr/ctxtSL_SPMON-LOW").text = "07/2022"
    session.findById("wnd[0]/usr/ctxtSL_SPMON-HIGH").text = "07/2022"
    session.findById("wnd[0]/usr/ctxtSL_SPMON-HIGH").setFocus
    session.findById("wnd[0]/usr/ctxtSL_SPMON-HIGH").caretPosition = 7
    session.findById("wnd[0]/tbar[1]/btn[8]").press

'Analysis Currency
    session.findById("wnd[0]/tbar[1]/btn[31]").press
    session.findById("wnd[1]/usr/sub:SAPLSPO4:0300/ctxtSVALD-VALUE[0,21]").text = "usd"
    session.findById("wnd[1]/usr/sub:SAPLSPO4:0300/ctxtSVALD-VALUE[2,21]").text = "07/04/2022"
    session.findById("wnd[1]/usr/sub:SAPLSPO4:0300/ctxtSVALD-VALUE[2,21]").setFocus
    session.findById("wnd[1]/usr/sub:SAPLSPO4:0300/ctxtSVALD-VALUE[2,21]").caretPosition = 10
    session.findById("wnd[1]/tbar[0]/btn[0]").press

'Change drilldown to Business Area
    session.findById("wnd[0]/tbar[1]/btn[7]").press
    session.findById("wnd[1]/tbar[0]/btn[0]").press
    
    

    For j = 0 To LastRowOfTheBusinessAreaTable

'Drilldown by MaterialCode
        session.findById("wnd[0]/usr/lbl[1,"&Cstr(j+6)&"]").setFocus
        session.findById("wnd[0]/usr/lbl[1,"&Cstr(j+6)&"]").caretPosition = 3
        session.findById("wnd[0]").sendVKey 8
        session.findById("wnd[1]/usr/sub:SAPLMCS2:0201/radLMCS2-MRKKZ[4,0]").select
        session.findById("wnd[1]/usr/sub:SAPLMCS2:0201/radLMCS2-MRKKZ[4,0]").setFocus
        session.findById("wnd[1]/tbar[0]/btn[0]").press

'back to Business Area view
        session.findById("wnd[0]/tbar[0]/btn[3]").press
        session.findById("wnd[0]/usr/lbl[1,7]").setFocus
        session.findById("wnd[0]/usr/lbl[1,7]").caretPosition = 7
        session.findById("wnd[0]").sendVKey 8
        'session.findById("wnd[1]/usr/sub:SAPLMCS2:0201/radLMCS2-MRKKZ[4,0]").setFocus
        session.findById("wnd[1]/tbar[0]/btn[0]").press
    Next
'back
    session.findById("wnd[0]/tbar[0]/btn[3]").press
'don't save
    session.findById("wnd[1]/usr/btnSPOP-OPTION2").press
Sandra Rossi
  • 11,934
  • 5
  • 22
  • 48
  • So, according to `wnd[0]/usr/lbl[1,7]`, I can say it's an object `GuiUserArea` (an ABAP List). You can see in the SAP GUI Scripting documentation, there's the property `VerticalScrollbar` of object `GuiScrollbar`, which has the property `Maximum`. – Sandra Rossi Jul 07 '22 at 16:59
  • 1
    Does this answer your question? [SAPGUI Parse GuiUserArea](https://stackoverflow.com/questions/16974871/sapgui-parse-guiuserarea) – Sandra Rossi Jul 07 '22 at 17:00

0 Answers0