ALV网格仅加载前64行,如何更改默认加载 [英] ALV grid only loads first 64 rows, how to change default load

查看:68
本文介绍了ALV网格仅加载前64行,如何更改默认加载的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经为SAP GUI脚本创建了查找功能.
如果网格行在特定列中具有特定值,则将其双击(这将触发加载特定的从属数据).
我的网格只有不到300行,因此加载如此多的数据不会对现代计算机造成压力.

I have created a lookup functionality for SAP GUI scripting.
If a grid row has specific values in specific columns, then it is double clicked (this triggers loading specific dependent data).
My grid has less than 300 rows, so loading so much data shouldn't strain a modern computer.

我遇到的问题是,它从SAPGrid第64行返回".对于每个单元格.如果我进入调试状态并在ALV网格中向下滚动,则网格行将加载并找到结果.

The issue I have is that from SAPGrid Row 64 it returns "" for each cell. If I enter debugging and scroll down in the ALV grid then the grid row loads and the results are found.

我可以更改默认情况下加载的行数吗?
是否有提取完整记录集的方法?
其他选项包括使用脚本上下滚动或设置过滤器.

Can I change how many rows are loaded on default?
Is there a method for pulling the full recordset?
The alternative options include scrolling up and down using scripting or setting up filters.

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,条件(0,j).

Updated code

Code updated based on correct answer from @Asger.
Since lookups mostly work with primary keys, I went for the safe solution of SAPGrid.GetCellValue(k, criteria(0, j)) = "" but the solution is in fact 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网格控件:对于大量数据,仅在滚动后才进行内容的重新加载,否则可能仅会出现一个空字符串返回结果-即使没有引起异常.

GuiGridView / ALV Grid Control: For large amounts of data, reloading of the content takes place only after scrolling, otherwise it is likely that only one empty string will be returned as the result - even without causing an exception.

因此,应始终使用 SetCurrentCell 集中并加载要读取的数据集.

Therefore SetCurrentCell should always be used to focus and load the dataset to be read.

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

也许每个新的64行都足够加载(我无法对其进行测试):

Maybe it's sufficient to load every new 64 rows (I can't test it):

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

这篇关于ALV网格仅加载前64行,如何更改默认加载的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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