当我不知道表ID时,如何在SAP脚本中获取行数?

发布于 2025-02-13 21:14:23 字数 3101 浏览 1 评论 0原文

我正在创建一个代码来下载一些物质信息,首先要求SAP获取某些植物信息。然后,我将钻头切换到业务区域(BA),最后我必须按材料代码钻取每个BA。

我遇到问题的地方是,当我通过材料代码进行钻取(第二个“ for”),因为每个工厂都有不同数量的业务领域。您能告诉我如何知道第一台业务区域表的行数吗?

该代码还必须将材料代码数据导出到Excel表格,但我没有将其包括在以下代码中。

这是我正在使用的代码:

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

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文