调用 SAP 时索引错误 RFC_READ_TABLE
Bad Index when calling SAP RFC_READ_TABLE
我不断收到以下代码的坏索引错误..
Sub GetDocumentedGoodsMovement()
Dim funcs As SAPFunctions
Dim ws As Worksheet
Set ws = ThisWorkbook.Worksheets("Sheet3")
Set sapConn = CreateSapFunctions()
If sapConn Is Nothing Then
Exit Sub
End If
Set objRfcFunc = sapConn.Add("RFC_READ_TABLE")
Set objQueryTab = objRfcFunc.Exports("QUERY_TABLE")
Set objDelimiter = objRfcFunc.Exports("DELIMITER")
Set objRowCount = objRfcFunc.Exports("ROWCOUNT")
objRowCount.Value = "99999999"
Set objOptTab = objRfcFunc.Tables("OPTIONS")
Set objFldTab = objRfcFunc.Tables("FIELDS")
Set objDatTab = objRfcFunc.Tables("DATA")
objQueryTab.Value = "AUFM" 'TABLE
objDelimiter.Value = "|" 'DELIMITER
objOptTab(objOptTab.RowCount, "TEXT") = "AUFNR EQ '000009999999"' AND BWART EQ '261'" 'FILTERS FOR VIEW.
objFldTab.FreeTable
objFldTab.AppendRow
objFldTab(objFldTab.RowCount, "FIELDNAME") = "AUFNR" 'FIELD TO DISPLAY
objFldTab.AppendRow
objFldTab(objFldTab.RowCount, "FIELDNAME") = "MBLNR" 'FIELD TO DISPLAY
objFldTab.AppendRow
objFldTab(objFldTab.RowCount, "FIELDNAME") = "MATNR" 'FIELD TO DISPLAY
objFldTab.AppendRow
objFldTab(objFldTab.RowCount, "FIELDNAME") = "LGORT" 'FIELD TO DISPLAY
objFldTab.RAppendRow
objFldTab(objFldTab.RowCount, "FIELDNAME") = "BWART" 'FIELD TO DISPLAY
objFldTab.AppendRow
objFldTab(objFldTab.RowCount, "FIELDNAME") = "SHKZG" 'FIELD TO DISPLAY
If objRfcFunc.Call = False Then
MsgBox objRfcFunc.Exception
End If
Dim objDatRec As Object
Dim objFldRec As Object
For Each objDatRec In objDatTab.Rows
For Each objFldRec In objFldTab.Rows
ws.Cells(objDatRec.Index + 1, objFldRec.Index) = Mid(objDatRec("WA"), objFldRec("OFFSET") + 1, objFldRec("LENGTH"))
Next
Next
End Sub
行发生错误:
objOptTab(objOptTab.RowCount, "TEXT") = "AUFNR EQ '000009999999"' AND BWART EQ '261'"
报错如下:
"Run-time error '-2147352565 (8002000b)':
Bad index
是否有关于为什么会出现此错误的任何指示?已经完成以下故障以尝试找到错误的来源(到目前为止没有任何运气):
- 我有所需的授权。打电话给 RFC_READ_TABLE.
- 值 '000009999999' 是正确的,并且存在于 table AUFM 中。
- 有给定订单号的条目,移动类型 (BWART) 261。
- SAP 登录正常工作,没有任何错误。
- 我在 SE37 中测试了完全相同的条目。它给了我想要的结果。
为了回答我自己的问题,错误是由于 objOptTab
中缺少行而发生的。
为了修复错误,我添加了这一行:
objOptTab.AppendRow
完成,工作代码:
Sub GetDocumentedGoodsMovement()
Dim funcs As SAPFunctions
Dim ws As Worksheet
Set ws = ThisWorkbook.Worksheets("Sheet3")
Set sapConn = CreateSapFunctions()
If sapConn Is Nothing Then
Exit Sub
End If
Set objRfcFunc = sapConn.Add("RFC_READ_TABLE")
Set objQueryTab = objRfcFunc.Exports("QUERY_TABLE")
Set objDelimiter = objRfcFunc.Exports("DELIMITER")
Set objRowCount = objRfcFunc.Exports("ROWCOUNT")
objRowCount.Value = "99999999"
Set objOptTab = objRfcFunc.Tables("OPTIONS")
Set objFldTab = objRfcFunc.Tables("FIELDS")
Set objDatTab = objRfcFunc.Tables("DATA")
objQueryTab.Value = "AUFM" 'TABLE
objDelimiter.Value = "|" 'DELIMITER
objOptTab.AppendRow
objOptTab(objOptTab.RowCount, "TEXT") = "AUFNR EQ '000009999999' AND BWART EQ '261'" 'FILTERS FOR VIEW.
objFldTab.FreeTable
objFldTab.AppendRow
objFldTab(objFldTab.RowCount, "FIELDNAME") = "AUFNR" 'FIELD TO DISPLAY
objFldTab.AppendRow
objFldTab(objFldTab.RowCount, "FIELDNAME") = "MBLNR" 'FIELD TO DISPLAY
objFldTab.AppendRow
objFldTab(objFldTab.RowCount, "FIELDNAME") = "MATNR" 'FIELD TO DISPLAY
objFldTab.AppendRow
objFldTab(objFldTab.RowCount, "FIELDNAME") = "LGORT" 'FIELD TO DISPLAY
objFldTab.RAppendRow
objFldTab(objFldTab.RowCount, "FIELDNAME") = "BWART" 'FIELD TO DISPLAY
objFldTab.AppendRow
objFldTab(objFldTab.RowCount, "FIELDNAME") = "SHKZG" 'FIELD TO DISPLAY
If objRfcFunc.Call = False Then
MsgBox objRfcFunc.Exception
End If
Dim objDatRec As Object
Dim objFldRec As Object
For Each objDatRec In objDatTab.Rows
For Each objFldRec In objFldTab.Rows
ws.Cells(objDatRec.Index + 1, objFldRec.Index) = Mid(objDatRec("WA"), objFldRec("OFFSET") + 1, objFldRec("LENGTH"))
Next
Next
End Sub
我不断收到以下代码的坏索引错误..
Sub GetDocumentedGoodsMovement()
Dim funcs As SAPFunctions
Dim ws As Worksheet
Set ws = ThisWorkbook.Worksheets("Sheet3")
Set sapConn = CreateSapFunctions()
If sapConn Is Nothing Then
Exit Sub
End If
Set objRfcFunc = sapConn.Add("RFC_READ_TABLE")
Set objQueryTab = objRfcFunc.Exports("QUERY_TABLE")
Set objDelimiter = objRfcFunc.Exports("DELIMITER")
Set objRowCount = objRfcFunc.Exports("ROWCOUNT")
objRowCount.Value = "99999999"
Set objOptTab = objRfcFunc.Tables("OPTIONS")
Set objFldTab = objRfcFunc.Tables("FIELDS")
Set objDatTab = objRfcFunc.Tables("DATA")
objQueryTab.Value = "AUFM" 'TABLE
objDelimiter.Value = "|" 'DELIMITER
objOptTab(objOptTab.RowCount, "TEXT") = "AUFNR EQ '000009999999"' AND BWART EQ '261'" 'FILTERS FOR VIEW.
objFldTab.FreeTable
objFldTab.AppendRow
objFldTab(objFldTab.RowCount, "FIELDNAME") = "AUFNR" 'FIELD TO DISPLAY
objFldTab.AppendRow
objFldTab(objFldTab.RowCount, "FIELDNAME") = "MBLNR" 'FIELD TO DISPLAY
objFldTab.AppendRow
objFldTab(objFldTab.RowCount, "FIELDNAME") = "MATNR" 'FIELD TO DISPLAY
objFldTab.AppendRow
objFldTab(objFldTab.RowCount, "FIELDNAME") = "LGORT" 'FIELD TO DISPLAY
objFldTab.RAppendRow
objFldTab(objFldTab.RowCount, "FIELDNAME") = "BWART" 'FIELD TO DISPLAY
objFldTab.AppendRow
objFldTab(objFldTab.RowCount, "FIELDNAME") = "SHKZG" 'FIELD TO DISPLAY
If objRfcFunc.Call = False Then
MsgBox objRfcFunc.Exception
End If
Dim objDatRec As Object
Dim objFldRec As Object
For Each objDatRec In objDatTab.Rows
For Each objFldRec In objFldTab.Rows
ws.Cells(objDatRec.Index + 1, objFldRec.Index) = Mid(objDatRec("WA"), objFldRec("OFFSET") + 1, objFldRec("LENGTH"))
Next
Next
End Sub
行发生错误:
objOptTab(objOptTab.RowCount, "TEXT") = "AUFNR EQ '000009999999"' AND BWART EQ '261'"
报错如下:
"Run-time error '-2147352565 (8002000b)':
Bad index
是否有关于为什么会出现此错误的任何指示?已经完成以下故障以尝试找到错误的来源(到目前为止没有任何运气):
- 我有所需的授权。打电话给 RFC_READ_TABLE.
- 值 '000009999999' 是正确的,并且存在于 table AUFM 中。
- 有给定订单号的条目,移动类型 (BWART) 261。
- SAP 登录正常工作,没有任何错误。
- 我在 SE37 中测试了完全相同的条目。它给了我想要的结果。
为了回答我自己的问题,错误是由于 objOptTab
中缺少行而发生的。
为了修复错误,我添加了这一行:
objOptTab.AppendRow
完成,工作代码:
Sub GetDocumentedGoodsMovement()
Dim funcs As SAPFunctions
Dim ws As Worksheet
Set ws = ThisWorkbook.Worksheets("Sheet3")
Set sapConn = CreateSapFunctions()
If sapConn Is Nothing Then
Exit Sub
End If
Set objRfcFunc = sapConn.Add("RFC_READ_TABLE")
Set objQueryTab = objRfcFunc.Exports("QUERY_TABLE")
Set objDelimiter = objRfcFunc.Exports("DELIMITER")
Set objRowCount = objRfcFunc.Exports("ROWCOUNT")
objRowCount.Value = "99999999"
Set objOptTab = objRfcFunc.Tables("OPTIONS")
Set objFldTab = objRfcFunc.Tables("FIELDS")
Set objDatTab = objRfcFunc.Tables("DATA")
objQueryTab.Value = "AUFM" 'TABLE
objDelimiter.Value = "|" 'DELIMITER
objOptTab.AppendRow
objOptTab(objOptTab.RowCount, "TEXT") = "AUFNR EQ '000009999999' AND BWART EQ '261'" 'FILTERS FOR VIEW.
objFldTab.FreeTable
objFldTab.AppendRow
objFldTab(objFldTab.RowCount, "FIELDNAME") = "AUFNR" 'FIELD TO DISPLAY
objFldTab.AppendRow
objFldTab(objFldTab.RowCount, "FIELDNAME") = "MBLNR" 'FIELD TO DISPLAY
objFldTab.AppendRow
objFldTab(objFldTab.RowCount, "FIELDNAME") = "MATNR" 'FIELD TO DISPLAY
objFldTab.AppendRow
objFldTab(objFldTab.RowCount, "FIELDNAME") = "LGORT" 'FIELD TO DISPLAY
objFldTab.RAppendRow
objFldTab(objFldTab.RowCount, "FIELDNAME") = "BWART" 'FIELD TO DISPLAY
objFldTab.AppendRow
objFldTab(objFldTab.RowCount, "FIELDNAME") = "SHKZG" 'FIELD TO DISPLAY
If objRfcFunc.Call = False Then
MsgBox objRfcFunc.Exception
End If
Dim objDatRec As Object
Dim objFldRec As Object
For Each objDatRec In objDatTab.Rows
For Each objFldRec In objFldTab.Rows
ws.Cells(objDatRec.Index + 1, objFldRec.Index) = Mid(objDatRec("WA"), objFldRec("OFFSET") + 1, objFldRec("LENGTH"))
Next
Next
End Sub