半年前我写的一篇博客:
一步一步教你用SAP NCO3.0调用RFC(菜鸟必看)http://blog.csdn.net/szlaptop/article/details/8059480
是介绍了如何把外部的数据通过RFC写入SAP里。
这次是写将SAP的数据通过RFC写到外部系统。
配置NCO,配置app.config请参照原来的博客。
直接上代码:
public static void getXml(DataTable dt)
{
RfcDestination SapRfcDestination = RfcDestinationManager.GetDestination("DEV");
try
{
RfcRepository SapRfcRepository = SapRfcDestination.Repository;
IRfcFunction myfun = SapRfcRepository.CreateFunction("ZRFC_EXPRESS_DD");
myfun.Invoke(SapRfcDestination); //执行函数
IRfcTable table = myfun.GetTable("IP_EXPRE");//获取相应的内表
dt.Columns.Add("orderID");//表格添加一列
dt.Columns.Add("logisticsName");
dt.Columns.Add("logisticsTel");
dt.Columns.Add("logisticsOrderID");
for (int i = 0; i < table.RowCount; i++)
{
table.CurrentIndex = i;//当前内表的索引行
DataRow dr= dt.NewRow();
dr[0] = table.GetString("TID"); //获取表格的某行某列的值
dr[1] = table.GetString("COMPANY_NAME");
dr[2] = table.GetString("SELLER_PHONE");
dr[3] = table.GetString("OUT_SID");
dt.Rows.Add(dr);
}
}
catch (System.Exception ex)
{
throw ex;
}
finally
{
RfcSessionManager.EndContext(SapRfcDestination);
SapRfcDestination = null;
}
}
}