繁体   English   中英

SAP GUI 脚本:从 ALV Grid 读取表或数据

[英]SAP GUI script: read table or data from ALV Grid

我目前正在创建一个自动化脚本,其中将在 SAP 表中搜索来自 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

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

当我尝试检查表名 (F1) 时,它给了我“RFPOSXEXT”的名称。

屏幕领域技术信息

我不确定如何继续搜索 SAP 表中所需的值。

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

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

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

SAP ABAP 总账科目行项目显示清单

假设您在 ALV 网格中显示数据,并且在您撰写帖子时已准备好会话。 然后下面的代码会将数据从 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 视图控件,上面的代码将失败。 “会话”必须是指向 FBL3N 且网格视图打开的有效 SAP Guisession。 在我上面提供的链接中,您会看到这样做很热。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM