SAP GUI 脚本:从 ALV 网格读取 table 或数据

SAP GUI script: read table or data from ALV Grid

我目前正在创建一个自动化脚本,其中将在 SAP table 中搜索来自 excel 的数据。

我试图在 SAP 中记录这些步骤,但它只给我这个:

session.findById("wnd[0]").maximize
session.findById("wnd[0]/usr/lbl[18,15]").setFocus
session.findById("wnd[0]/usr/lbl[18,15]").caretPosition = 10

我知道它告诉我当前的单元格地址。

当我试图检查 table 名称 (F1) 时,它给了我名称 "RFPOSXEXT"。

我不确定如何继续在 SAP table 中搜索我需要的值。

我的问题是,如何设置 table 并遍历 table 的行,直到找到我要查找的文本?

我相信它也只会让我搜索可见的行。

下面是我在 SAP 中的 table。我将循环到作业、文档编号和数量的行,如果它与 excel 中的 "textToFind" 匹配,那么我将能够为每个匹配的项目编辑文本。

让我们假设您在 ALV 网格中显示数据,并且在您写入 post 时准备好会话。然后下面的代码将数据从 SAP 复制到 excel。您必须根据需要调整代码

    Dim wks As Worksheet
    Set wks = " your worksheet here ..."

    Dim Table As Object
    Dim cols As Long
    Dim rows As Long
    Dim i As Long, j As Long

    Set Table = Session.FindById("wnd[0]/usr/cntlGRID1/shellcont/shell/shellcont[1]/shell")

    rows = Table.RowCount - 1
    cols = Table.ColumnCount - 1

    Dim columns As Object
    Set columns = Table.ColumnOrder


    Dim arrCol() As Variant
    ReDim arrCol(cols)
    For j = 0 To cols
        arrCol(j) = (CStr(columns(j)))
    Next
    With wks
        .Range(.Cells(1, 1), .Cells(1, cols + 1)).Value = arrCol()
    End With

    For i = 0 To rows
        For j = 0 To cols
            arrCol(j) = Table.GetCellValue(i, CStr(columns(j)))                
        Next

        With wks
            .Range(.Cells(i + 2, 1), .Cells(i + 2, cols + 1)).Value = arrCol()
        End With

        If i Mod 10 = 0 Then
            Table.SetCurrentCell i, CStr(columns(0))
            DoEvents
        End If
    Next

End Sub

如果不使用griv 视图控件,上述代码将失败。 "Session" 必须是一个有效的 SAP Guisession,它指向 FBL3N,并且打开了网格视图。在我上面提供的 link 中,您会看到这样做很热。