I've created a macro to read data from SAP Table using the BAPI BBP_RFC_READ_TABLE
.
It successfully compiles and runs for a single parameter if I use the FILTER VIEW:
objOptTab(objOptTab.RowCount, "TEXT") = "EBELN EQ '12345'"
However, the goal of the code is to be able to pass an array of strings as the textfilter, therefore the ekknPurchaseOrders
variable exists. As SAP uses SQL Queries and share a lot of syntax with general SQL language, I would assume I could pass below as a TEXT FILTER:
ekknPurchaseOrders = "('12345', '67890', '101112')"
This is why the below line is there in the first place:
"EBELN IN " & ekknPurchaseOrders'
Running the code/executing BAPI with EBELN IN "
.. results in an SQL_PARSE error, because the syntax is invalid.
Any suggestions as to what syntax I may utilize to pass a collection of multiple values to the EBELN TEXT FILTER?
Take note that the TEXT FILTER syntax is changed from 'EQ' to 'IN' when the error occurs. Passing multiple values using ekknPurchaseOrders
and not changing syntax to 'IN' returns the value for the first element in ekknPurchaseOrders
.
Public Const worksheetName As String = "EKKN"
Public Sub GetEKPOtable()
Dim funcs As SAPFunctions
Dim ws As Worksheet
Set ws = ThisWorkbook.Worksheets(worksheetName)
'LOG IN TO SAP
Set sapConn = CreateSapFunctions()
If sapConn Is Nothing Then
Exit Sub
End If
'DECLEARE FUNCTION EXPORTS
Set objRfcFunc = sapConn.Add("BBP_RFC_READ_TABLE")
Set objQueryTab = objRfcFunc.Exports("QUERY_TABLE")
Set objDelimiter = objRfcFunc.Exports("DELIMITER")
Set objRowCount = objRfcFunc.Exports("ROWCOUNT")
'SET VALUES
objRowCount.Value = "99999999"
Set objOptTab = objRfcFunc.Tables("OPTIONS")
Set objFldTab = objRfcFunc.Tables("FIELDS")
Set objDatTab = objRfcFunc.Tables("DATA")
objQueryTab.Value = "EKPO" 'TABLE
objDelimiter.Value = "|" 'DELIMITER
objOptTab.FreeTable
'OPTION FIELD SAP STATEMENT
objOptTab.AppendRow
objOptTab(objOptTab.RowCount, "TEXT") = "EBELN IN " & ekknPurchaseOrders 'FILTERS FOR VIEW
objFldTab.FreeTable
'OUTPUT FIELDS
objFldTab.AppendRow
objFldTab(objFldTab.RowCount, "FIELDNAME") = "EBELN"
objFldTab.AppendRow
objFldTab(objFldTab.RowCount, "FIELDNAME") = "EBELP"
objFldTab.AppendRow
objFldTab(objFldTab.RowCount, "FIELDNAME") = "EMATN"
objFldTab.AppendRow
objFldTab(objFldTab.RowCount, "FIELDNAME") = "ELIKZ"
'IF CALL FAILES, EXIT
If objRfcFunc.Call = False Then
MsgBox objRfcFunc.Exception
End If
Dim objDatRec As Object
Dim objFldRec As Object
'WRITE RESULT TO WS
Dim lo As ListObject
Set lo = ws.ListObjects(outputTable)
Call ClearTableData(lo)
For Each objDatRec In objDatTab.Rows
For Each objFldRec In objFldTab.Rows
ws.Cells(objDatRec.Index + 8, objFldRec.Index + 7) = Mid(objDatRec("WA"), objFldRec("OFFSET") + 1, objFldRec("LENGTH"))
Next
Next
End Sub