连接sap系统需要通过sap javaconnect来连接,对于sapjco.jar系列文件有32位与64位之分【32位用的JAR版本是 2.1.10 (2011-05-10) ,64位用的JAR版本是 2.1.7 (2006-06-12)】。即对jdk有严格要求。现说明客户端32位部署及服务端64位部署两种情况:

一、 我本地是32位,部署本地客户端 sapjco32.zip
a) 将附件相对应位数的librfc32.dll、sapjcorfc.dll、msvcp71.dll、msvcr71.dll四个文件拷贝至system32,其中前两个文件是必须拷贝(后面2个可以不用)。
b) 将相对应位数的sapjco-2.1.7.jar拷贝至对应模块lib下,然后将其部署好。

这里我把它配置到我们的pom.xml里面了,如下:

  1. 首先把相应的JAR文件放在项目的\WEB-INF\lib目录下面。

2.  在pom.xml里面指向该文件。

<dependency>
    <groupId>com.sap</groupId>
    <artifactId>sapjco</artifactId>
    <version>2.1.7</version>
    <scope>system</scope>
    <systemPath>${basedir}/src/main/webapp/WEB-INF/lib/sapjco-2.1.7.jar</systemPath>
</dependency>

二、 服务器是64位 sapjco64.zip
a) 将附件相对应位数的librfc32.dll、sapjcorfc.dll、msvcp71.dll、msvcr71.dll四个文件拷贝至system32及SysWOW64文件夹下
b) 将相对应位数的sapjco-2.1.10.jar拷贝至服务端的lib下,然后将其部署好。同上。

<dependency>
    <groupId>com.sap</groupId>
    <artifactId>sapjco</artifactId>
    <version>2.1.10</version>
    <scope>system</scope>
    <systemPath>${basedir}/src/main/webapp/WEB-INF/lib/sapjco-2.1.10.jar</systemPath>
</dependency>

如何在JAVA里面调用RFC函数,简单的demo如下:[详细的工具类 SapUtil.java]

package org.jeecgframework.core.util;

import com.sap.mw.jco.IFunctionTemplate;
import com.sap.mw.jco.JCO;
import com.sap.mw.jco.JCO.Structure;

public class SapUtil {
    public static double getRate(String rateType, String fromCurrency, String toCurrency, String date) {
    JCO.Client client = null;
    double rate = 0;
    try {
        client = addClientPool();
        JCO.Function func = getFunction(client, "BAPI_EXCHANGERATE_GETDETAIL");
        JCO.ParameterList inputParameterList = func.getImportParameterList();
        inputParameterList.getField("RATE_TYPE").setValue(rateType);
        inputParameterList.getField("FROM_CURR").setValue(fromCurrency);
        inputParameterList.getField("TO_CURRNCY").setValue(toCurrency);
        inputParameterList.getField("DATE").setValue(date);
        client.execute(func);
        JCO.ParameterList outputParameterList = func.getExportParameterList();
        Structure rateStructure = outputParameterList.getStructure("EXCH_RATE");
        rate = rateStructure.getDouble("EXCH_RATE");
        System.out.println(rate);
    } catch (JCO.Exception e) {
        e.printStackTrace();
    } finally {
        if (client != null) {
            JCO.releaseClient(client);
        }
    }
    return rate;
    }

private static JCO.Client addClientPool() {
        String client = "800";
        String user = "crmuser1";
        String password = "CRM1";
        String language = "1";
        String host = "10.10.1.80"; //正式机
        String sysnr = "00";
        JCO.Client sapclient = null;
        try {
            sapclient = JCO.createClient(client, user, password, language, host, sysnr);
            sapclient.connect();
        } catch (JCO.Exception e) {
            throw new RuntimeException("SAP连接错误:" + e.getMessage());
        }
        return sapclient;
    }

private static JCO.Function getFunction(JCO.Client client, String funcName) {
        String repositoryName = "repository";
        JCO.Function func = null;
        try {
            JCO.Repository repository = new JCO.Repository(repositoryName, client);
            IFunctionTemplate ft = repository.getFunctionTemplate(funcName);
            func = ft.getFunction();
        } catch (JCO.Exception e) {
            e.printStackTrace();
        }
        return func;
    }

public static void main(String[] args) {
        getRate("M", "USD", "CNY", "20141001");
        getRate("M", "USD", "CNY", "00000000");
        getRate("M", "EUR", "CNY", null);
        getRate("M", "EUR", "CNY", "20141001");
    }
}

PS:可能遇到的问题(都是32位和64位所用文件不一致问题)

    1. java.lang.ExceptionInInitializerError:
      JCO.classInitialize(): Could not load middleware layer
      'com.sap.mw.jco.rfc.MiddlewareRFC'JCO.nativeInit():
      Could not
      initialize dynamic link library sapjcorfc
      [C:\Windows\System32\sapjcorfc.dll: Can't load AMD 64-bit .dll on a IA
      32-bit platform].

    2. java.lang.ExceptionInInitializerError:
      JCO.classInitialize(): Could not load middleware layer
      'com.sap.mw.jco.rfc.MiddlewareRFC'JCO.nativeInit():
      Could not
      initialize dynamic link library sapjcorfc. Found version "2.1.7
      (2006-06-12)" but required version "2.1.10 (2011-05-10)".

如何实现SAP的RFC函数调用(原创)的更多相关文章

  1. 访问SAP的RFC

    .NET 环境Xp(sp3) vs2010, win2003 EN 32bit(sp2)winform,webform 引用sapnco.dll,sapnco_utils.dll(自动引用)配置文件需 ...

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

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

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

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

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

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

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

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

  6. C#通过RFC调用SAP

    using System;using System.Collections.Generic;using SAP.Middleware.Connector;using System.Data;using ...

  7. .NET连接SAP系统专题:.NET调用RFC几种方式(一)

    本来今天是要写一篇关于NCO3.0的东西,就是关乎.NET调用SAP的RFC的,支持VS2010和.NET 4.0等.现在网上到处都是充斥着NCO1.X和NCO2.0,需要用VS2003来使用,都是一 ...

  8. 还在写SQL做SAP二开?通过RFC调用NetWeaver,让HANA数据库操作更可靠

    相比于从零开始构建全套信息化系统,基于成熟的ERP等行业软件做二次开发是更多中大型企业应对个性化软件需求的首选方案.如何在二开模块中,可靠地对成品软件的数据库进行读写操作,以满足单据自动创建.元数据自 ...

  9. Java(JCo3)与SAP系统相互调用

    声明:原创作品,转载时请注明文章来自SAP师太技术博客( 博/客/园www.cnblogs.com):www.cnblogs.com/jiangzhengjun,并以超链接形式标明文章原始出处,否则将 ...

随机推荐

  1. JavaScript高级 面向对象的程序设计 (二)《JavaScript高级程序设计(第三版)》

    二.继承 OO是面向对象语言最为有魅力的概念.一般的OO语言都实现了两种继承,接口继承和实现继承.接口继承只继承方法签名,而实际继承继承了实际的方法. 而在JS中,函数没有签名,所以无法实现接口继承. ...

  2. 《Google 代码风格指南》

    <Google 代码风格指南> https://github.com/google/styleguide

  3. CentOS下安装LNMP(LINUX+NGINX+MYSQL+PHP)环境

    一.安装Nginx最新版 首先查看是否有安装源包 yum list nginx  (或yum info nginx) 如果没有则 vi /etc/yum.repos.d/nginx.repo #添加如 ...

  4. 用开源中国(oschina)Git管理代码(整合IntelliJ 13.1.5)

    简介 开源中国提供了Git服务(地址:http://git.oschina.net/),在速度上比国外的github要快很多.使用了一段时间,感觉很不错.oschina git提供了演示平台,可以运行 ...

  5. List GetEnumerator

    static void Main() { List<int> list = new List<int>(); list.Add(); list.Add(); list.Add( ...

  6. a 标签 跳转4种类型

    <a href=''  target=''>中的target有4种参数: '_self'   ,  '_parent'   ,  '_top'    和  '_blank' 在没有使用框架 ...

  7. Mysql 简单问题汇总(持续更新)

    主从架构相关问题 问题现象:从机连接主机时报错 [ERROR] Slave I/O: error connecting to master 'repl@192.168.0.50:3306' - ret ...

  8. 线程操作API

    线程操作API 1.currentThread 2.getId() .getName().getPriority().getStart.isAlive().isDaemon().isInterrupt ...

  9. C/C++ 关于大小端模式

    大端模式:  数据的高字节存在低地址  数据的低字节存在高地址 小端模式:  数据的高字节存在高地址  数据的低字节存在低地址 如图,i为int类型占4个字节,但只有1个字节的值为1,另外3个字节值为 ...

  10. HDU1006

    Problem Description The three hands of the clock are rotating every second and meeting each other ma ...