加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > Windows > 正文

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

发布时间:2020-12-14 02:05:29 所属栏目:Windows 来源:网络整理
导读:我正在开发一个 Windows应用程序,在这里我想从sap系统中提取数据并在datagridview中显示它… 我已经单独提取了列名,如名称,城市等. 我不知道如何从列中提取数据,任何人都可以帮我解决这些问题吗? 我正在使用RFC_READ_TABLE函数模块和rfc destiantion manage
我正在开发一个 Windows应用程序,在这里我想从sap系统中提取数据并在datagridview中显示它…
我已经单独提取了列名,如名称,城市等.

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

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

提前致谢!!!

解决方法

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

首先创建连接

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(';');
}

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读