我正在开发一个Windows应用程序,在这里我想从SAP系统中提取数据并在datagridview中显示...
我已经仅提取了列名称,如名称、城市等...
我不知道如何从这些列中提取数据,有没有人可以帮我提供代码?
我正在使用RFC_READ_TABLE函数模块和RFC目标管理器。
谢谢提前!!!
我正在开发一个Windows应用程序,在这里我想从SAP系统中提取数据并在datagridview中显示...
我已经仅提取了列名称,如名称、城市等...
我不知道如何从这些列中提取数据,有没有人可以帮我提供代码?
我正在使用RFC_READ_TABLE函数模块和RFC目标管理器。
谢谢提前!!!
尚未测试,但基本工作原理如下:
首先创建连接。
RfcDestination destination = mDestinationManager.GetDestination("MYDESTINATION");
创建函数
IRfcFunction readTable = destination.Repository.CreateFunction("RFC_READ_TABLE");
在调用函数之前设置参数。
// we want to query table KNA1
readTable.SetValue("QUERY_TABLE", "KNA1");
// fields will be separated by semicolon
readTable.SetValue("DELIMITER", ";");
参数是通过从函数中检索表、使用Append()函数添加行并使用SetValue()来设置该行中每个列的值来创建的。// Parameter table FIELDS contains the columns you want to receive
// here we query 2 fields, KUNNR and NAME1
IRfcTable fieldsTable = readTable.GetTable("FIELDS");
fieldsTable.Append();
fieldsTable.SetValue("FIELDNAME", "KUNNR");
fieldsTable.Append();
fieldsTable.SetValue("FIELDNAME", "NAME1");
// the table OPTIONS contains the WHERE condition(s) of your query
// here a single condition, KUNNR is to be 0012345600
// several conditions have to be concatenated in ABAP syntax, for instance with AND or OR
IRfcTable optsTable = readTable.GetTable("OPTIONS");
optsTable.Append();
optsTable.SetValue("TEXT", "KUNNR = '0012345600'");
readTable.Invoke(destination);
处理数据
IRfcTable dataTable = readTable.GetTable("DATA");
foreach(var dataRow in dataTable)
{
string data = dataRow.GetValue("WA");
string[] columns = data.Split(';');
}