How to fetch data from SAP system using sap .net connector?

泪湿孤枕 提交于 2019-12-03 16:37:39

untested, but this is essentially how it works:

first create the connection

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

create the function

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", ";");

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'");

call the function

readTable.Invoke(destination);

process the data

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

foreach(var dataRow in dataTable)
{
    string data = dataRow.GetValue("WA");
    string[] columns = data.Split(';');
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!