ALV网格仅加载前64行,如何更改默认负载



情况

我创建了用于SAP GUI脚本的查找功能。
如果网格行在特定的列中具有特定值,则双击它(这触发了加载特定的相关数据)。
我的电网的数量少于300行,因此加载太多数据不应使现代计算机劳累。

问题

我遇到的问题是,从Sapgrid Row 64返回"。对于每个单元格。如果我在ALV网格中输入调试并向下滚动,则找到网格行负载和结果。

可能的解决方案

我可以更改默认值加载多少行?
是否有一种拉动完整记录集的方法?
替代选项包括使用脚本或设置过滤器上下滚动。

代码

Sub FindGridLine(SAPGrid As Object, criteria() As String)
SAPGrid.ClearSelection 'first it deselects what has been selected
For k = 0 To (SAPGrid.RowCount - 1) 'for each grid row
    For i = 1 To UBound(criteria, 1) ' for each criteria row except for the first (should be only 1)
        For j = LBound(criteria, 2) To UBound(criteria, 2) 'and for each column
            tempstr = SAPGrid.GetCellValue(k, criteria(0, j))
            If tempstr <> criteria(i, j) Then 'if the criterion doesn't match
                GoTo nextrow 'then go to the next row
            End If
        Next j
    Next i
    'if it passed the criteria then doubleclick it
    SAPGrid.DoubleClick k, criteria(0, 0)
    Exit Sub
nextrow:
Next k
'in case no results were found
MsgBox "No line was found in grid!"
End Sub

更新的代码

根据@asger的正确答案更新的代码。
由于查找主要与主键一起使用,因此我选择了SAPGrid.GetCellValue(k, criteria(0, j)) = ""的安全解决方案,但该解决方案实际上是SAPGrid.SetCurrentCell k, criteria(0, j)

Sub FindGridLine(SAPGrid As Object, criteria() As String)
'    SAPGrid.SelectAll 'first it selects everything as to load the full grid
    SAPGrid.ClearSelection 'first it deselects what has been selected
    
    For k = 0 To (SAPGrid.RowCount - 1) 'for each grid row
        For i = 1 To UBound(criteria, 1) ' for each criteria row except for the first (should be only 1)
            For j = LBound(criteria, 2) To UBound(criteria, 2) 'and for each column
                tempstr = SAPGrid.GetCellValue(k, criteria(0, j))
                If tempstr = "" Then SAPGrid.SetCurrentCell k, criteria(0, j) 'this solution only works if the search is done in a non-empty field
                tempstr = SAPGrid.GetCellValue(k, criteria(0, j))
                If tempstr <> criteria(i, j) Then 'if the criterion doesn't match
                    GoTo nextrow 'then go to the next row
                End If
            Next j
        Next i
        'if it passed the criteria then doubleclick it
        SAPGrid.DoubleClick k, criteria(0, 0)
        Exit Sub
nextrow:
    Next k
'in case no results were found
For i = 0 To UBound(criteria, 1) ' for each criteria row except for the first (should be only 1)
    For j = LBound(criteria, 2) To UBound(criteria, 2) 'and for each column
        tempstr = tempstr & "|" & criteria(i, j)
    Next j
    If i <> UBound(criteria, 1) Then
        tempstr = tempstr & vbNewLine
    End If
Next i
MsgBox "No line was found in grid!" & vbNewLine & "Please select line" & tempstr & vbNewLine & "manually and press 'OK'" & vbNewLine & "or enter debug mode."
End Sub

guigridview/alv网格控制:对于大量数据,仅在滚动后才进行内容重新加载,否则可能只有一个空字符串在结果时返回 - 即使不引起例外。

因此,SetCurrentCell应始终用于聚焦并加载要读取的数据集。

请测试e。G。SAPGrid.SetCurrentCell(k, 1)

也许足以加载每条新的64行(我无法测试):

If k Mod 64 = 63 Then ' at least if 1 row before each 64 rows
    SAPGrid.SetCurrentCell (k, criteria(0, LBound(criteria, 2)))
End If

最新更新