如何使用SAP .NET连接器从SAP系统中获取数据? [英] How to fetch data from SAP system using sap .net connector?

查看:175
本文介绍了如何使用SAP .NET连接器从SAP系统中获取数据?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I am developing an windows application, here I wanna extract data from sap system and show it in a datagridview... I have extracted the column names alone like name, city and so on..

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

I don't know how to extract the data from the columns, can anyone help me with the code?

I正在使用RFC_READ_TABLE功能模块和rfc设计管理器

I am using RFC_READ_TABLE function module and rfc destiantion manager

预先感谢!

推荐答案

未经测试,但这实际上是这样工作的:

untested, but this is essentially how it works:

首先创建连接

RfcDestination destination = mDestinationManager.GetDestination("MYDESTINATION");

创建函数

IRfcFunction readTable = destination.Repository.CreateFunction("RFC_READ_TABLE");

在调用函数之前设置参数

set parameters before invoking the function

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

表参数是通过从函数中检索表,并使用Append()函数添加一个行,并使用SetValue()设置该行中各个列的值

table parameters are created by retrieving the table from the function, using the Append() function to add a row and using SetValue() to set values for individual columns in that row

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

这篇关于如何使用SAP .NET连接器从SAP系统中获取数据?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆