首页 > 编程语言 > 详细

SAP Java Connector(JCo)

时间:2014-09-22 15:12:23      阅读:211      评论:0      收藏:0      [点我收藏+]

 JCo是一个高性能的,基于JNI的中间件,它实现了SAP的RFC(Remote Function Call)协议。

      1JCo的安装

      从 http://files.cnblogs.com/byfhd/jco.rar 下载JCo,解压后将librfc32.dll和sapjcorfc.dll拷贝到WINNT"SYSTEM32下,将sapjco.jar加入项目的classpath中。

      2、与SAP的连接

      JCo支持两种连接方式,direct connections和connection pools。

      direct connections:

      import com.sap.mw.jco.*;

      public TutorialConnect1() {
         JCO.Client mConnection;
         try {
            mConnection = JCO.createClient("001", // SAP client
                                                         "",           // userid
                                                         "****",               // password
                                                         null,                 // language
                                                         "",         // server host name
                                                         "00");                // system number          mConnection.connect();                                                                            
         mConnection.disconnect();
         } catch (Exception ex) {
         }
     }

      connection pools:

      static final String POOL_NAME = "Pool";
      public TutorialConnect2() {
         JCO.Client mConnection;
         try {
            JCO.Pool pool = JCO.getClientPoolManager().getPool(POOL_NAME);
            if (pool == null) {
               OrderedProperties properties = OrderedProperties.load("/logon.properties");
               JCO.addClientPool(POOL_NAME,  // pool name
                                                 5,          // maximum number of connections
                                                 logonProperties); // properties
            }
            mConnection = JCO.getClient(POOL_NAME);
         } catch (Exception ex) {
         } finally {                                                                                                                            //返回连接到连接池,否则会导致无可用连接
            JCO.releaseClient(mConnection);
         }
      }

      logon.properties文件的定义:

      jco.client.client=001
      jco.client.user=userid
      jco.client.passwd=****
      jco.client.ashost=hostname
      jco.client.sysnr=00

      3、对SAP进行操作

      SAP中有JCO.Repository对象,包含着SAP的RFM的运行环境元数据。

      JCO.Repository mRepository;
      mRepository = new JCO.Repository("ARAsoft", mConnection); 
      构造器中包含两个参数,第一个是一个任意名称,第二个是连接池或JCO.Client对象。

      IFunctionTemplate对象包含着某个特定的RFM元数据,JCO.Function则代表着一个包含所有参数的RFM。它们之间的关系类似Java中Class和Object的关系。 

      IFunctionTemplate ft = mRepository.getFunctionTemplate("BAPI_SALESORDER_GETLIST");
      //ft为空表示没有在SAP发现对应的RFM
      if (ft == null) return null;
      JCO.Function function = ft.getFunction();

      JCO.ParameterList对象包含做Function的输入、输出和表参数。

      client = JCO.getClient(SID);    //从Pool中取得Client
      JCO.ParameterList input = function.getImportParameterList();
      //设置参数,参数名为第二个参数,参数值为第一个参数,
      input.setValue("0000001200", "CUSTOMER_NUMBER"   );
      input.setValue(      "1000", "SALES_ORGANIZATION");
      client.execute(function);


Download jco: http://files.cnblogs.com/byfhd/jco.rar

SAP Java Connector(JCo)

原文:http://www.cnblogs.com/qiri07/p/3985982.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!