.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的更多相关文章

  1. 用JavaScript访问SAP云平台上的服务遇到跨域问题该怎么办

    关于JavaScript的跨域问题(Cross Domain)的讨论, 网上有太多的资源了.国内的程序猿写了非常多的优秀文章,Jerry这里就不再重复了. 直入主题,最近我正在做一个原型开发:通过SA ...

  2. 访问SAP的Domain的Value Range

    访问Domain的Value Range有两种方法: 1.直接访问表 dd07l和dd07T     select * from dd07l            where domname   = ...

  3. 如何实现SAP的RFC函数调用(原创)

    连接sap系统需要通过sap javaconnect来连接,对于sapjco.jar系列文件有32位与64位之分[32位用的JAR版本是 2.1.10 (2011-05-10) ,64位用的JAR版本 ...

  4. SAP 调用RFC 的时候记录异常报错方式

    DATA: lv_error TYPE char100. CALL FUNCTION 'ZRFC_WM_ZEL001' DESTINATION lv_desc EXPORTING process_fl ...

  5. SAP ABAP RFC接口通用日志工具:abap fm logger

    很早之前就想写个能记录函数模块日志的通用工具,最早尝试时,没有想清楚插入代码的体积问题.在一些群友的提醒下,了解到可以用宏来处理这一问题.不过当时比较忙,就没有动笔.最近又想起这件事,花了2天完成了一 ...

  6. RfcDestinationManager.UnregisterDestinationConfiguration时报错cannot unregister the given destination configuration

    在使用NCO访问SAP的RFC时,我的程序代码是这么写的: string destinationName = "EWM_700_GROUP"; IDestinationConfig ...

  7. SAP学习日志--RFC REMOTE FUNCTION CALL

    RFC  Remote function Call 远程功能调用, 是SAP系统之间以及非SAP系统之间程序通信的基本接口技术. 例如BAPI , ALE都是基于RFC实现的 SAP系统提供了三种外部 ...

  8. 一个完整的SAP RFC调用接口封装

    因为经常需要访问sap操作数据,就封装了一个类方便调用,运行条件需要安装sap客户端,在sap客户端安装之后会带有一个com接口,本接口就通过这个com访问sap,因为com的后期绑定问题故使用了vb ...

  9. .net 调用SAP RFC的几种方法

    转自:http://www.cherpservice.com/pub/newsdetail.asp?Newsid=3613 第一种方式采用SAP.net Connector: 最新版本是3.,不开源, ...

随机推荐

  1. 性能监控之Spotlight

    有和同事探讨一些技术监控类软件,谈到Spotlight,临时记一下. 下载地址https://pan.baidu.com/s/1HB9xd9LmOR-MOk8FIGBm-A 常规安装模式,下载解压安装 ...

  2. 009:JSON

    一. MySQL JSON类型 1. JSON介绍 什么是 JSON ? JSON 指的是 JavaScript 对象表示法(JavaScript Object Notation) JSON 是轻量级 ...

  3. JS-用法

    JavaScript 用法 HTML 中的脚本必须位于 <script> 与 </script> 标签之间. 脚本可被放置在 HTML 页面的 <body> 和 & ...

  4. 多进程并发简单socket

    server---------------------这种简单实现:坏处客户端启动一个一个进程,进程多了机器要蹦#!/usr/bin/env python # encoding: utf-8  # D ...

  5. Linux的setup命令启动服务名称和功能

    Linux的setup命令启动服务名称和功能 1 anacron 可执行crontab既定时间内没执行的工作.2 atd 单一使用的例行性命令.3 apmd 了解系统电池电量(手提式计算机使用).4 ...

  6. django之设置分页

    分页 Django提供了一些类实现管理数据分页,这些类位于django/core/paginator.py中 Paginator对象 Paginator(列表,int):返回分页对象,参数为列表数据, ...

  7. Dijkstra算法的另一种证明

    按:今天看Tanenbaum的计算机网络时讲到了Dijkstra算法.关于算法的正确性,<算法导论>给出了严格的证明.CLRS的证明基于一个通用的框架,非常清晰.今天只是随意想想是否有其他 ...

  8. scrapy框架的日志等级和请求参数

    一 . Scrapy的日志等级 - 在使用 scrapy crawl xxx 允许程序时,在终端里打印输出的就是scrapy的日志信息 - 日志信息的种类 : ERROR : 错误信息 WARNING ...

  9. leetcode840

    本题不清楚题意,从网上找到了python的解答,记录如下. class Solution: def numMagicSquaresInside(self, grid): ans, lrc = 0, [ ...

  10. e8000051

    Unable to install package (e8000051). Please check used certificate validity and provisioning.. Unab ...