I need to use the BAPI_BILLINGDOC_GETLIST
API from SAP to get some invoices. After looking at the documentation, I only saw one parameter. But after consulting with the SAP guys, that parameter is like a collection of parameters.
So using SAP .NET Connector, this is how I would normally call an SAP BAPI:
using (var connection = new SapConnection("SAP"))
{
connection.Open();
var command = new SapCommand("BAPI_BILLINGDOC_GETLIST", connection);
command.Parameters.Add("REFDOCRANGE", salesOrderNumber);
resultDataSet = command.ExecuteDataSet();
}
But as you can imagine, it doesn't work. The actual BAPI is expecting parameters for some fields called S
, OP
, REF_DOC_LO
, and REF_DOC_HI
. As you can see here:
But I get errors if I actually use those parameters, basically telling me that they don't exist. So do I just send the data in the REFDOCRANGE
parameter? Does anyone know how that should be formatted?
The parameter REFDOCRANGE
is not a simple value parameter, it is a structure of type BAPI_REF_DOC_RANGE
. That structure has several fields, SIGN
, OPTION
, REF_DOC_LOW
and REF_DOC_HIGH
. You can set those fields by first retrieving a reference to the structure, then setting the individual field values.
It looks like the NSAPConnector doesn't really support complex parameters. I looked at the sources and you only get a basic SapParameter class that has a name and a value.
In native SAP .Net Connector 3 this would look like this (somewhat pseudocode, untested):
IRfcFunction fnc = destination.Repository.CreateFunction("BAPI_BILLINGDOC_GETLIST");
IRfcStructure param = fnc.GetStructure("REFDOCRANGE");
param.SetValue("SIGN", "BT");
param.SetValue("REF_DOC_LOW", salesOrderNumberLow);
param.SetValue("REF_DOC_HIGH", salesOrderNumberHigh);
fnc.Invoke(destination);
IRfcTable tabDetail = fnc.GetTable("BILLINGDOCUMENTDETAIL");
foreach(var row in tabDetail)
{
....
}
If I didn't miss anything and the NSAPConnector-library is indeed missing support for complex parameters, I'd suggest switching to the standard SAP .Net Connector 3. You can get it directly from SAP (SAP Marketplace account needed)