SAP GUI脚本:从ALV网格读取表或数据 [英] SAP GUI script: read table or data from ALV Grid

查看:59
本文介绍了SAP GUI脚本:从ALV网格读取表或数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I'm currently creating an automation script where data from excel will be searched in SAP table.

我试图在SAP中记录这些步骤,但这只能给我以下内容:

I tried to record the steps in SAP but it only gives me this:

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

我知道它告诉我当前的电池地址.

Which I know that it tells me the current cell address.

当我尝试检查表名称(F1)时,它的名称为"RFPOSXEXT".

When I tried to check the table name (F1), it gives me the name of "RFPOSXEXT".

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

I'm not sure how I can proceed for me to search the values that I need in the SAP table.

我的问题是,在找到要查找的文本之前,如何设置表格并在表格的各行之间循环?

我相信它也将只允许我搜索可见的行.

I believe it will also only allow me to search for the visible rows.

下面是我在SAP中拥有的表.而且,我将循环到工作分配",文档编号"和数量"行,如果它们与excel中的"textToFind"相匹配,那么我将能够为匹配的每个项目编辑文本.

Below is the table that I have in SAP. And I will be looping to the rows of Assignment, Document number and Quantity that if it will match to the "textToFind" in excel then I will be able to edit the text for each item matched.

推荐答案

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

Let's assume you display the data in a ALV Grid and you have the session ready as you write in your post. Then the following code will copy the data from SAP into excel. You have to adjust the code according to your needs

    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.在我上面提供的链接中,您会看到这样做的热情.

The above code will fail if you don't use griv view control. "Session" must be a valid SAP Guisession pointing to FBL3N with the grid view open. In the link I provided above you will see hot to do that.

这篇关于SAP GUI脚本:从ALV网格读取表或数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆