C# 使用 SAP NCO3.0 调用SAP RFC函数接口
2013-09-12 14:55
399 查看
最近使用C#调用SAP RFC函数,SAP提供了NCO3.0组件。
下载组件安装,之后引用“sapnco.dll”和“sapnco_utils.dll”两个文件。
在程序中 using SAP.Middleware.Connector;
具体看下面代码
使用app.config文件配置注册客户端连接
下载组件安装,之后引用“sapnco.dll”和“sapnco_utils.dll”两个文件。
在程序中 using SAP.Middleware.Connector;
具体看下面代码
使用app.config文件配置注册客户端连接
<?xml version="1.0"?> <configuration> <configSections> <sectionGroup name="SAP.Middleware.Connector"> <sectionGroup name="ClientSettings"> <section name="DestinationConfiguration" type="SAP.Middleware.Connector.RfcDestinationConfiguration,sapnco"/> </sectionGroup> </sectionGroup> </configSections> <SAP.Middleware.Connector> <ClientSettings> <DestinationConfiguration> <destinations> <add NAME="Conn" USER="KY_PG01" PASSWD="ky@123" CLIENT="002" SYSNR="10" ASHOST="192.168.0.22" LANG="ZH" GROUP="PUBLIC" MAX_POOL_SIZE="5"></add> </destinations> </DestinationConfiguration> </ClientSettings> </SAP.Middleware.Connector> </configuration>
private RfcDestination _rfcDestination = null; public DataTable dtr = new DataTable(); public void RegisterDestination() //注册客户端 { try { if (_rfcDestination == null) { _rfcDestination = RfcDestinationManager.GetDestination("Conn"); } } catch (Exception ex) { MessageBox.Show(ex.Message); } } public string InvokeRFCFunctionGetCompanyID(string dateBegin, string dateEnd) { IRfcFunction function = null; string str = string.Empty; try { function = _rfcDestination.Repository.CreateFunction("ZKY_FM_ZM005B");//调用服务器函数 function.SetValue("SO_FKDAT_B", dateBegin);//传入参数 function.SetValue("SO_FKDAT_E", dateEnd);//传入参数 function.SetParameterActive(0, true); function.Invoke(_rfcDestination);//执行服务器调用的函数 IRfcTable myrfcTable = function.GetTable("IT_ZM005B");//rfc server function 返回值table结构名称 int liElement = 0; for (liElement = 0; liElement <= myrfcTable.ElementCount - 1; liElement++) { RfcElementMetadata metadata = myrfcTable.GetElementMetadata(liElement); dtr.Columns.Add(metadata.Name);//循环创建列 } foreach (IRfcStructure dr in myrfcTable)//循环table结构表 { DataRow row = dtr.NewRow();//创建新行 for (liElement = 0; liElement <= myrfcTable.ElementCount - 1; liElement++) { RfcElementMetadata metadata = myrfcTable.GetElementMetadata(liElement); row[metadata.Name] = dr.GetString(metadata.Name).Trim(); } dtr.Rows.Add(row); } this.dataGridView1.DataSource = dtr; } catch (Exception ex) { MessageBox.Show(ex.ToString()); } return str; } //在事件或方法中调用 this.RegisterDestination(); this.InvokeRFCFunctionGetCompanyID("20120401", "20120901");
相关文章推荐
- C# 使用 SAP NCO3.0 调用SAP RFC函数接口
- PB调用SAP的RFC函数接口
- SAP接口编程-RFC系列04 : 动态调用SAP函数
- C#调用sap rfc 接口
- 一步一步教你用SAP NCO3.0调用RFC(菜鸟必看)
- step by step 教你用SAP NCO3.0调用RFC
- SAP接口编程-RFC系列11:C#语言调用RFC
- 一步一步教你用SAP NCO3.0调用RFC(菜鸟必看)
- C#调用VC的DLL的接口函数参数类型转换一览表
- 一个完整的SAP RFC调用接口封装
- JAVA使用JCO实现调用SAP接口方法
- C#调用VC的DLL的接口函数参数类型转换一览表
- .Net 调用SAP RFC接口来读取数据实战纪实
- 【原创】PB调用SAP的Web Service结构体数组参数方法详解(使用C#调用Web Service生成dll)
- 使用sqlite3(数据库知识)的接口函数完成一个用户注册功能模块设计 要封装成函数,在独立的main中调用测试
- C#关于静态函数与普通函数之间的调用问题,以及可变参数的使用
- C#调用VC的DLL的接口函数参数类型转换
- 使用Signature Tool自动生成P/Invoke调用Windows API的C#函数声明
- SAP接口编程-RFC系列03 : RFC调用SAP函数
- 转:在 C# 中使用 P/Invoke 调用 Mupdf 函数库显示 PDF 文档