如何使用sap .net连接器从SAP系统获取数据?

Jes*_*bil 5 .net sap sap-connector windows-applications

我正在开发一个Windows应用程序,在这里我想从sap系统中提取数据并在datagridview中显示它...我已经提取了列名,如名称,城市等等.

我不知道如何从列中提取数据,任何人都可以帮我解决这些问题吗?

我正在使用RFC_READ_TABLE函数模块和rfc destiantion manager

提前致谢!!!

Dir*_*eek 9

未经测试,但这基本上是它的工作原理:

首先创建连接

RfcDestination destination = mDestinationManager.GetDestination("MYDESTINATION");
Run Code Online (Sandbox Code Playgroud)

创建功能

IRfcFunction readTable = destination.Repository.CreateFunction("RFC_READ_TABLE");
Run Code Online (Sandbox Code Playgroud)

在调用函数之前设置参数

// we want to query table KNA1
readTable.SetValue("QUERY_TABLE", "KNA1");
// fields will be separated by semicolon
readTable.SetValue("DELIMITER", ";");
Run Code Online (Sandbox Code Playgroud)

表参数是通过从函数中检索表来创建的,使用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'");
Run Code Online (Sandbox Code Playgroud)

调用该函数

readTable.Invoke(destination);
Run Code Online (Sandbox Code Playgroud)

处理数据

IRfcTable dataTable = readTable.GetTable("DATA");

foreach(var dataRow in dataTable)
{
    string data = dataRow.GetValue("WA");
    string[] columns = data.Split(';');
}
Run Code Online (Sandbox Code Playgroud)