问题
Need help, I'm trying to get sales data from SAP Using RFC_READ_TABLE, but don't know how to pass OPTIONS and FIELDS parameters to SAP. Here sample code of my app.
Connection is working, after execution, I have an exception "DATA_BUFFER_EXCEEDED"
public void RFC_READ_TABLE()
{
try
{
ECCDestinationConfig cfg = new ECCDestinationConfig();
RfcDestinationManager.RegisterDestinationConfiguration(cfg);
RfcDestination dest = RfcDestinationManager.GetDestination("ABI_ERP");
RfcRepository repo = dest.Repository;
IRfcFunction fn = repo.CreateFunction("RFC_READ_TABLE");
fn.SetValue("QUERY_TABLE", "VBAP");
fn.GetTable("DATA");
fn.Invoke(dest);
var companyCodeList = fn.GetTable("VBAP");
var companyDataTable = companyCodeList.ToDataTable("VBAP");
dataGridView1.DataSource = companyDataTable;
}
catch (RfcBaseException x)
{
MessageBox.Show("Some problems in programe execution. Check entered data, and try again." +
"\n" +
"\n<SAP Remote Execution Error>" +
"\n" +
"\nAdditional Information on Error: " + x.Message, "Oops, Runtime Error");
}
}
回答1:
RFC_READ_TABLE
isn't the ideal function module to be using to read sales order data (it's really designed for quick-n'-dirty table reads where nothing else exists). I'd investigate the following RFC-enabled function modules:
BAPI_SALESORDER_GETLIST
- get a list of sales documentsBAPISDORDER_GETDETAILEDLIST
- read the details of a single sales document
If you look at function group 2032
or at Sales and Distribution -> Sales -> Sales Order in transaction BAPI
you'll find others that may help.
回答2:
Narrow down your query by using the 'options' and 'fields' tables options for RFC_READ_TABLE.
回答3:
You should only define the columns you really need, like after SELECT
in SQL, i.e Sales document, item and material number:
IRfcTable fieldsTable = fn.GetTable("FIELDS");
fieldsTable.Append();
fieldsTable.SetValue("FIELDNAME", "VBELN"); //Sales Document
fieldsTable.Append();
fieldsTable.SetValue("FIELDNAME", "POSNR"); // Sales Document Item
fieldsTable.Append();
fieldsTable.SetValue("FIELDNAME", "MATNR"); // Material number
If you don't do that, the invoke will fail because of Data buffer exceeded, as you mentioned. This is because DATA
structure in RFC_READ_TABLE
function is of type TAB512
, this means that each row can contain only up to 512 characters. The length of the content of all columns combined in the table you query (VBAP
) is around 1500 characters. Here you can see the length of each field.
Then you also wish to filter table, similarly as WHERE
clause in SQL.
IRfcTable options = fn.GetTable("OPTIONS");
options.Append();
options.SetValue("TEXT", "VBELN = '000000000' AND POSNR = '000000'");
options.Append();
options.SetValue("TEXT", " OR VBELN = '000000001' AND POSNR = '000001'");
Here you also need to be careful, because each option text should be max 72 characters long. If you need multiple or longer WHERE
clauses, just append new option like fileds.
I've noticed, that OR
causes some performance issues on some tables.
After setting these two properties of your function you should be able to successfully invoke it.
来源:https://stackoverflow.com/questions/27633332/rfc-read-table-passing-options-and-fields-parameters-c