[英]SAP GUI script: read table or data from ALV Grid
I'm currently creating an automation script where data from excel will be searched in SAP table.我目前正在创建一个自动化脚本,其中将在 SAP 表中搜索来自 excel 的数据。
I tried to record the steps in SAP but it only gives me this:我试图在 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
Which I know that it tells me the current cell address.我知道它告诉我当前的单元格地址。
When I tried to check the table name (F1), it gives me the name of "RFPOSXEXT".当我尝试检查表名 (F1) 时,它给了我“RFPOSXEXT”的名称。
I'm not sure how I can proceed for me to search the values that I need in the SAP table.我不确定如何继续搜索 SAP 表中所需的值。
My question is, how will I set the table and loop through the rows of the table until I find the text that I'm looking for?我的问题是,如何设置表格并遍历表格的行,直到找到我要查找的文本?
I believe it will also only allow me to search for the visible rows.我相信它也只会让我搜索可见的行。
Below is the table that I have in SAP.下面是我在 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.我将循环到作业、文档编号和数量的行,如果它与 Excel 中的“textToFind”匹配,那么我将能够为匹配的每个项目编辑文本。
Let's assume you display the data in a ALV Grid and you have the session ready as you write in your post.假设您在 ALV 网格中显示数据,并且在您撰写帖子时已准备好会话。 Then the following code will copy the data from SAP into excel.然后下面的代码会将数据从 SAP 复制到 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
The above code will fail if you don't use griv view control.如果不使用 griv 视图控件,上面的代码将失败。 "Session" must be a valid SAP Guisession pointing to FBL3N with the grid view open. “会话”必须是指向 FBL3N 且网格视图打开的有效 SAP Guisession。 In the link I provided above you will see hot to do that.在我上面提供的链接中,您会看到这样做很热。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.