使用NCO3.0调用SAP RFC

相比.net connector 2.0,易用性上降低了,但是功能上强大了。

1.安装sap .net connector 3.0,在C:\Program Files\SAP\SAP_DotNetConnector3_x86你会得到四个dll文件:sapnco_utils.dll sapnco.dll rscp4n.dll libicudecnumber.dll
2.使用vs2010 我们创建一个项目,添加对上面四个dll文件的引用,实际上只有三个是可以引用成功的,libicudecnumber.dll的引用会失败,注意在这里,你看上去是引用成功的,其实你后面的程序是不能运行的。这个需要你在程序属性中做一些小修改才可以:修改“项目属性”-“应用程序”-“目标框架” ,由“.NET Framework 4 Client Profile”修改为“.NET Framework 4”,最后引用 .NET 4.0 的 System.Web.dll 。只有这样sapnco.dll才可以被正常引用;否则就会提示:“SAP.Middleware.Connector.RfcConfigParameters”的类型初始值设定项引发异常。

3.using SAP.Middleware.Connector;这个不用多说

4.代码:我们实现运行一个 RFC 取出值放入到一个list中
//连接 sap
 RfcConfigParameters rfc = new RfcConfigParameters();
 rfc.Add(RfcConfigParameters.Name, "mycon");
 rfc.Add(RfcConfigParameters.AppServerHost, "IP address");
 rfc.Add(RfcConfigParameters.Client, "200");
 rfc.Add(RfcConfigParameters.User, "username");
 rfc.Add(RfcConfigParameters.Password, "password");
 rfc.Add(RfcConfigParameters.SystemNumber, "00");
 rfc.Add(RfcConfigParameters.Language, "en");
 rfc.Add(RfcConfigParameters.PoolSize, "5");
 rfc.Add(RfcConfigParameters.MaxPoolSize, "10");
 rfc.Add(RfcConfigParameters.IdleTimeout, "500");
 RfcDestination rfcdest = RfcDestinationManager.GetDestination(rfc);
 //RFC调用函数
 RfcRepository rfcrep = rfcdest.Repository;
 IRfcFunction myfun = null;
 myfun = rfcrep.CreateFunction("RFCname");
 //赋值import  AAA
 myfun.SetValue("AAA", "值");
 //执行
 myfun.Invoke(rfcdest);
 //得到export结果struct
IRfcStructure mystruct = myfun.GetStructure("AAA_detail");
 string mystruct_1 = mystruct.GetString("detail_1");
 //得到内表 itab的结果
 IRfcTable outtable = myfun.GetTable("Itab");
  for (int i = 0; i < outtable.Count; i++)
            {
                outtable.CurrentIndex = i;
               listBox1 .Items.Add (outtable.CurrentRow.GetString("字段1").ToString());
            }

 
    看看其实也很简单,只是没有nco 2.0那样方便而已。至于易用性上,大多数应用情况都是去调RFC,弄懂了这些也足够应付了。

posted @ 2012-10-17 14:53  神经衰弱  阅读(2297)  评论(0编辑  收藏  举报