5

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

我不知道如何从列中提取数据,有人可以帮我写代码吗?

我正在使用 RFC_READ_TABLE 功能模块和 rfc 目标管理器

提前致谢!!!

4

2 回答 2

9

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

首先创建连接

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(';');
}
于 2014-03-19T15:28:44.037 回答
0

对于 RFC_READ_TABLE,您可能还需要考虑 sourceforge.net 上的免费 .net ExtracTable 工具。它使用 RFC_READ_TABLE 并将报告到 Excel 或 CSV 文件中。由于 RFC_READ_TABLE 可能会给您带来超过 512 个字符的记录的问题,所以上面的工具会很小心。或者,您必须为此类 SAP 表编写自己的 split&join 例程。但这样总是有利有弊。

于 2020-12-21T16:05:12.390 回答