• JAVA实现SAP接口


    JAVA实现SAP接口

    环境spring-boot+maven

    1.maven依赖
            <dependency>
                <groupId>com.github.virtualcry</groupId>
                <artifactId>sapjco-spring-boot-starter</artifactId>
                <version>3.1.4</version>
            </dependency>
    
    • 1
    • 2
    • 3
    • 4
    • 5
    2.配置文件 application.yml
    jco:
      clients:
        main-client:
          # 服务端地址
          ashost: 127.0.0.1
          # 系统编号
          sysnr: 00
          # 系统环境
          client: 800
          # 用户名
          user: userName
          # 密码
          password: userPwd
          # 最大连接数
          pool-capacity: 20
          # 最大连接线程数
          peak-limit: 50
          # 语言
          language: ZH
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19

    3.在项目resources目录下创建lib文件夹并放置如下文件
    sap文件
    4.测试方法(以下代码放main方法里执行一样)

    
        @Test
        public void testSap(){
        	//获取连接工厂
            JCoConnectionFactory connectionFactory = JCoConnectionFactoryProvider.getSingleton().getIfAvailable();
            //获取连接client (main-client(同名yml配置文件中配置名))
            JCoClient client = connectionFactory.getClient("main-client");
            try {
                // 1.获取调用 RFC 函数对象(FUNCTION_NAME:方法名)
                JCoFunction func = client.getFunction("FUNCTION_NAME");
    
                // 2.1 配置传入普通参数
                JCoParameterList importParameterList = func.getImportParameterList();
                importParameterList.setValue("NAME", "XIAOMING");
                importParameterList.setValue("AGE", "18");
                // 2.2 设置传入内表参数(IN_MATNR:内表名称)
                JCoTable inTable = func.getTableParameterList().getTable("IN_MATNR");
                inTable.appendRow();
                inTable.setValue("USERNO","001");
                inTable.setValue("USERNAME","张三");
                inTable.setValue("USERAGE",18);
                inTable.appendRow();
                inTable.setValue("USERNO","002");
                inTable.setValue("USERNAME","李四");
                inTable.setValue("USERAGE",20);
    
                // 3.调用并获取返回值
                func.execute(client.getDestination());
                
                // 4.1 获取普通参数
                JCoParameterList exportParameterList = func.getExportParameterList();
                //返回代码、返回消息
                String returncode = exportParameterList.getString("RETURNCODE");
                String returnms = exportParameterList.getString("RETURNMS");
    
                System.out.println("获取返回普通参数:");
                System.out.println(returncode);
                System.out.println(returnms);
    
                // 4.2获取 返回内表 (OUTDATA:返回表名称)
                JCoTable maraTable = func.getTableParameterList().getTable("OUTDATA");
    
                // 循环输出 Table 数据
                for (int i = 0; i < maraTable.getNumRows(); i++) {
                    System.out.println("获取返回内表数据:");
                    maraTable.setRow(i);
    
                    String code = maraTable.getString("CODE");
                    String msg = maraTable.getString("MSG");
                    System.out.println("获取内表code:"+code);
                    System.out.println("获取内表msg:"+msg);
                }
    
            } catch (Exception e) {
                e.printStackTrace();
            }
    
        }
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35
    • 36
    • 37
    • 38
    • 39
    • 40
    • 41
    • 42
    • 43
    • 44
    • 45
    • 46
    • 47
    • 48
    • 49
    • 50
    • 51
    • 52
    • 53
    • 54
    • 55
    • 56
    • 57
    • 58

    以上方法名、参数、内表参数、返回参数、返回内表参数 皆为甲方文档中定义,我们只需要传值和取值即可

    5.正式环境运行时需要再jdk中放置以下文件
    在这里插入图片描述

  • 相关阅读:
    就近值 reduce用法 时间戳与时间点对比循环查找
    苹果悄悄推出了一个改变一切的新银行杀手储蓄账户
    类和对象10:对象访问方法
    『无为则无心』Python面向对象 — 59、魔法方法
    【吴恩达机器学习笔记】九、机器学习系统的设计
    【软考设计师】【计算机系统】E02 原、反、补、移码
    【计网】(三)超网、路由、NAT协议
    tcpdump抓包实现过程
    JUC——Chapter01——Java Multi-Threading Skills 多线程应用技能 —— 读《Java多线程编程技术核心技术》笔记
    嵌入式考试重点
  • 原文地址:https://blog.csdn.net/ywh22122/article/details/132634830