访问SAP的RFC
.NET
环境
Xp(sp3) vs2010, win2003 EN 32bit(sp2)
winform,webform
引用sapnco.dll,sapnco_utils.dll(自动引用)
配置文件需要改成混合模式
- <?xml version="1.0"?>
- <configuration>
- <startup>
- <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0" />
- </startup>
- <startup useLegacyV2RuntimeActivationPolicy="true">
- <supportedRuntime version="v4.0" />
- </startup>
- </configuration>
代码
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using SAP.Middleware.Connector;
- using System.IO;
- namespace RMBreakSync
- {
- //登陆SAP前的准备工作
- public class MyBackendConfig : IDestinationConfiguration
- {
- public RfcConfigParameters GetParameters(String destinationName)
- {
- if ("PRD_xxx".Equals(destinationName))
- {
- RfcConfigParameters parms = new RfcConfigParameters();
- parms.Add(RfcConfigParameters.AppServerHost, "10.**.**.***"); //SAP主机IP
- parms.Add(RfcConfigParameters.SAPRouter, "/H/2*8.??.**.***/H/"); //SAP主机IP
- parms.Add(RfcConfigParameters.SystemNumber, ""); //SAP实例
- parms.Add(RfcConfigParameters.User, "xxx"); //用户名
- parms.Add(RfcConfigParameters.Password, "xxx"); //密码
- parms.Add(RfcConfigParameters.Client, ""); // Client
- parms.Add(RfcConfigParameters.Language, "ZH"); //登陆语言
- return parms;
- }
- else return null;
- }
- public bool ChangeEventsSupported()
- {
- return false;
- }
- public event RfcDestinationManager.ConfigurationChangeHandler ConfigurationChanged;
- public static bool IsAlive = false;
- private static RfcDestination _RfcDest = null;
- /// <summary>
- /// 获取验证票
- /// </summary>
- /// <returns></returns>
- public static RfcDestination GetRfcDest()
- {
- if (_RfcDest == null || IsAlive==false)
- {
- lock (typeof(string))
- {
- if (_RfcDest == null || IsAlive == false)
- {
- IDestinationConfiguration ID = new MyBackendConfig();
- RfcDestinationManager.RegisterDestinationConfiguration(ID);
- RfcDestination prd = RfcDestinationManager.GetDestination("PRD_xxx");
- RfcDestinationManager.UnregisterDestinationConfiguration(ID);
- _RfcDest = prd;
- IsAlive = true;
- }
- }
- }
- return _RfcDest;
- }
- }
- public class SAPWrap
- {
- /// <summary>
- /// 更新服务器状态
- /// </summary>
- /// <param name="planId"></param>
- /// <param name="batno"></param>
- /// <param name="FGPartno"></param>
- public static void UpdateServerStatus(List<p_prodplanImport> list)
- {
- var prd = MyBackendConfig.GetRfcDest();
- RfcRepository repo = prd.Repository;
- IRfcFunction companyBapi = repo.CreateFunction("ZTPP_TO_MFG_FLAG"); //调用函数名
- IRfcTable rfcTable = companyBapi.GetTable("ITAB");
- // companyBapi.SetValue("EX_WERKS", "3003"); //设置Import的参数 ,即:输入参数
- //多行
- foreach (var plan in list)
- {
- rfcTable.Insert();
- rfcTable.CurrentRow.SetValue("PLANID", plan.PlanID);
- rfcTable.CurrentRow.SetValue("FGPARTNO", plan.P8code);
- rfcTable.CurrentRow.SetValue("BATNO", plan.batno.ToString());
- rfcTable.CurrentRow.SetValue("FLAG", "X");
- }
- companyBapi.Invoke(prd); //执行函数
- }
- public static List<RMBreakImport> DownItems(p_prodplanImport plan)
- {
- var prd = MyBackendConfig.GetRfcDest();
- RfcRepository repo = prd.Repository;
- IRfcFunction companyBapi = repo.CreateFunction("ZTPP_TO_MFG_ITEM"); //调用函数名
- IRfcTable rfcTable = companyBapi.GetTable("ITAB");
- //单行
- rfcTable.Insert();
- rfcTable.CurrentRow.SetValue("PLANID", plan.PlanID);
- rfcTable.CurrentRow.SetValue("FGPARTNO", plan.P8code);
- rfcTable.CurrentRow.SetValue("BATNO", plan.batno.ToString().Trim());
- companyBapi.Invoke(prd); //执行函数
- IRfcTable table = companyBapi.GetTable("ZITEM"); //获取相应的品号内表
- var list = new List<RMBreakImport>();
- for (int i = ; i < table.RowCount; i++)
- {
- table.CurrentIndex = i; //当前内表的索引行
- var item = new RMBreakImport();
- item.PlanId = table.GetString("PLANID");
- item.PlanId = item.PlanId.TrimStart("".ToCharArray());
- item.FGpartno = table.GetString("FGPARTNO"); //前导零
- item.FGpartno = item.FGpartno.TrimStart("".ToCharArray());
- item.p_yw = table.GetString("P_YW");
- item.p_FGName = table.GetString("P_FGNAME");
- item.batno = decimal.Parse(table.GetString("BATNO"));
- item.Poutput = table.GetDecimal("POUTPUT");
- item.productdate =DateTime.Parse( table.GetString("ProductDate")).ToString("yyyy-MM-dd");
- item.partno = table.GetString("PartNO");
- item.partno = item.partno.TrimStart("".ToCharArray());
- item.p_partnoName = table.GetString("P_PartNoName");
- item.partnoqty = table.GetDecimal("PartNoQty");
- item.partnototalqty = table.GetDecimal("PartNoTotalQty");
- item.UM = table.GetString("UM");
- item.p_brand = table.GetString("P_BRAND");
- item.p_supplier = table.GetString("NORMT");
- item.BreakDate =DateTime.Parse(table.GetString("BreakDate")).ToString("yyyy-MM-dd");
- item.Breaker = table.GetString("BREAKER");
- //设置默认值
- item.TicketStatus = "已审核";
- item.IsOut = "否";
- item.p_type = string.Empty;
- list.Add(item);
- }
- return list;
- }
- /// <summary>
- /// 下载计划列表
- /// </summary>
- /// <returns></returns>
- public static List<p_prodplanImport> DownPlan()
- {
- var prd = MyBackendConfig.GetRfcDest();
- RfcRepository repo = prd.Repository;
- IRfcFunction companyBapi = repo.CreateFunction("ZTPP_TO_MFG"); //调用函数名
- companyBapi.SetValue("EX_WERKS", ""); //设置Import的参数 ,即:输入参数
- companyBapi.Invoke(prd); //执行函数
- string MAKTX = companyBapi.GetValue("EX_WERKS").ToString(); //获取字段
- IRfcTable table = companyBapi.GetTable("ITAB"); //获取相应的品号内表
- var list=new List<p_prodplanImport>();
- for (int i = ; i < table.RowCount; i++)
- {
- table.CurrentIndex = i; //当前内表的索引行
- var plan=new p_prodplanImport();
- plan.PlanID = table.GetString("PLANID");
- plan.PlanID = plan.PlanID.TrimStart("".ToArray());//前导零
- plan.P8code = table.GetString("FGPartNO");
- plan.P8code = plan.P8code.TrimStart("".ToArray());
- plan.Pname = table.GetString("pname"); //计划名称
- plan.PlanType = table.GetString("PlanType");
- plan.Ppname = table.GetString("P_FGName");
- plan.Psetting = table.GetString("PSetting");
- if (plan.Psetting.Length > ) plan.Psetting = plan.Psetting.Substring(, );
- plan.batno =decimal.Parse( table.GetString("batno"));
- plan.P_yw = table.GetString("P_YW");
- plan.Poutput = table.GetDecimal("Poutput");
- plan.Pdate =DateTime.Parse( table.GetString("ProductDate")).ToString("yyyy-MM-dd");
- //设置默认列
- plan.Pweek1 = plan.Pdate;
- plan.Pplanner = "";
- plan.Pmanger = "";
- plan.Pcheckreust = "通过";
- plan.Pcheckdate = plan.Pdate;
- plan.Ptype = "新制";
- plan.Pday1 = plan.Poutput;
- list.Add(plan);
- }
- return list;
- }
- }
- }
Java
使用JCO,jco里面有4个版本,需要选择正确的版本,测试Jco是否正确可以使用 java -jar d:\jco\sapjco3.jar ,如果没有报错表示正常了
- public static List<String> callRfcExample() {
- // 获取RFC 对象
- JCoFunction function = RfcManager.getFunction("xxxx_V1");
- // 设置import 参数
- JCoParameterList importParam = function.getImportParameterList();
- importParam.setValue("I_WERKS", "www1");
- JCoTable tablename = function.getTableParameterList().getTable("R_GSTRP");
- tablename.deleteRow();
- tablename.deleteAllRows();
- tablename.clear();
- tablename.firstRow();
- tablename.appendRow();
- tablename.firstRow();
- tablename.setValue("SIGN", "I");
- tablename.setValue("OPTION", "BT");
- tablename.setValue("LOW", "2013-06-25");
- tablename.setValue("HIGH", "2013-06-25");
- // 执行RFC
- RfcManager.execute(function);
- // 获取RFC返回的字段值
- // JCoParameterList exportParam = function.getExportParameterList();
- // String exParamA = exportParam.getString("field_A");
- // String exParamB = exportParam.getString("field_B");
- // 遍历RFC返回的表对象
- List<String> list=new ArrayList<String>();
- JCoTable tb = function.getTableParameterList().getTable("ZAFKO");
- for (int i = ; i < tb.getNumRows(); i++) {
- tb.setRow(i);
- list.add(tb.getString("ORDER_NUMBER"));
- System.out.println(tb.getString("ORDER_NUMBER"));
- //System.out.println(tb.getString("field02"));
- }
- return list;
- }
详细请参考这里:http://www.cnblogs.com/geun/archive/2012/11/12/2765793.html#2714359
另外win2003,32或64 bit的需要安装对应的
Microsoft Visual C++ 2005 Service Pack 1 Redistributable Package (KB973544)
话说win2003,32bit上安装了七把次都没成功:(
//============
完成代码参考网盘内容
访问SAP的RFC的更多相关文章
- 用JavaScript访问SAP云平台上的服务遇到跨域问题该怎么办
关于JavaScript的跨域问题(Cross Domain)的讨论, 网上有太多的资源了.国内的程序猿写了非常多的优秀文章,Jerry这里就不再重复了. 直入主题,最近我正在做一个原型开发:通过SA ...
- 访问SAP的Domain的Value Range
访问Domain的Value Range有两种方法: 1.直接访问表 dd07l和dd07T select * from dd07l where domname = ...
- 如何实现SAP的RFC函数调用(原创)
连接sap系统需要通过sap javaconnect来连接,对于sapjco.jar系列文件有32位与64位之分[32位用的JAR版本是 2.1.10 (2011-05-10) ,64位用的JAR版本 ...
- SAP 调用RFC 的时候记录异常报错方式
DATA: lv_error TYPE char100. CALL FUNCTION 'ZRFC_WM_ZEL001' DESTINATION lv_desc EXPORTING process_fl ...
- SAP ABAP RFC接口通用日志工具:abap fm logger
很早之前就想写个能记录函数模块日志的通用工具,最早尝试时,没有想清楚插入代码的体积问题.在一些群友的提醒下,了解到可以用宏来处理这一问题.不过当时比较忙,就没有动笔.最近又想起这件事,花了2天完成了一 ...
- RfcDestinationManager.UnregisterDestinationConfiguration时报错cannot unregister the given destination configuration
在使用NCO访问SAP的RFC时,我的程序代码是这么写的: string destinationName = "EWM_700_GROUP"; IDestinationConfig ...
- SAP学习日志--RFC REMOTE FUNCTION CALL
RFC Remote function Call 远程功能调用, 是SAP系统之间以及非SAP系统之间程序通信的基本接口技术. 例如BAPI , ALE都是基于RFC实现的 SAP系统提供了三种外部 ...
- 一个完整的SAP RFC调用接口封装
因为经常需要访问sap操作数据,就封装了一个类方便调用,运行条件需要安装sap客户端,在sap客户端安装之后会带有一个com接口,本接口就通过这个com访问sap,因为com的后期绑定问题故使用了vb ...
- .net 调用SAP RFC的几种方法
转自:http://www.cherpservice.com/pub/newsdetail.asp?Newsid=3613 第一种方式采用SAP.net Connector: 最新版本是3.,不开源, ...
随机推荐
- ROS HTB限速失败原因分析和需注意事项
要想做限速,必须要知道以下几点: 首先要知道自己要限制什么的速度,谁的速度,于是需要用的标记,即Mangle. 其次要知道怎么限速,是限制上传,还是下载? 最后要知道所做的限速是否成功,即需要知道如何 ...
- node中的require
/*在node中,可以使用require()函数来加载模块. * require函数使用一个参数,参数值可以带有完整路径的模块的文件名,也可以为模块名.当使用node中提供的模块时,在require函 ...
- 解决 service iptables start 无法启动的问题
解决方式: iptables -F // 初始化iptables. service iptables save // 保存 service iptables restart // 重启
- php Reflection
<?php function title($title, $name) { return sprintf("%s. %s\r\n", $title, $name); } $f ...
- python找寻合适的日志库logging Handler——Handler自定义实现
最近在用python tornado开发一个app的服务端.投产的系统肯定需要包含日志功能,这里就自然想到了用python自带的logging库. logging中日志内容的输出都交由Handle ...
- HALCON中的算子大全(中英对照)
HALCON中的算子大全(中英对照) Chapter 1 :Classification1.1 Gaussian-Mixture-Models1.add_sample_class_gmm功能:把一个训 ...
- SpringData
1.什么是SpringData?Spring Data 项目的目的是为了简化构建基于 Spring 框架应用的数据访问计数,包括非关系数据库.Map-Reduce 框架.云数据服务等等:另外也包含对关 ...
- linux系统构架 - LB集群之LVS的DR设置
在lvs的nat模式的基础上 1.清空ipvsadm规则 ipvsadm -C 查看 ipvsadm -ln 2.清空iptables规则 iptables -t nat -F 3.修改rs的网卡配置 ...
- UINavigation,UiView,ModalView Controller之间的关系
如果当前是个VC,那么就太简单了,直接就可以push到下一个vc AddShopViewController *controller = [[AddShopViewController alloc] ...
- Django实现支付宝付款和微信支付
支付宝支付和微信支付是当今互联网产品常用的功能,我使用Django Rest Framework实现了网页上支付宝支付和微信支付的一个通用服务,提供rpc接口给其他服务,包括获取支付宝支付页面url的 ...