Java_SAP RFC

Java 和 SAP 数据交互

RFC 模式

  1. 引入相关 sapjco3.jarsapjco.dll

说明 : 相关 JDK , 开发工具 IntelliJ IDEAEclipse TomcataWeb 容器版本必须一致,目前是64位。编码格式设置一致为 UTF-8

  1. 配置相关的 SAP 信息
Properties connectProperties = new Properties();
//IP 地址
connectProperties.setProperty(DestinationDataProvider.JCO_ASHOST, "xxx.xxx.xxx.xxx");
//系统编号
connectProperties.setProperty(DestinationDataProvider.JCO_SYSNR, "xx");
//集团编号
connectProperties.setProperty(DestinationDataProvider.JCO_CLIENT, "xxx");
//用户名
connectProperties.setProperty(DestinationDataProvider.JCO_USER, "xxx");
//密码
connectProperties.setProperty(DestinationDataProvider.JCO_PASSWD, "xxxx");
//语言
connectProperties.setProperty(DestinationDataProvider.JCO_LANG, "ZH");
//最大连接数
connectProperties.setProperty(DestinationDataProvider.JCO_POOL_CAPACITY, "10");
//最大连接线程
connectProperties.setProperty(DestinationDataProvider.JCO_PEAK_LIMIT, "10");
//超时时间
connectProperties.setProperty(DestinationDataProvider.JCO_MAX_GET_TIME, "1000");
  1. 根据配置文件生成相关信息
private static void createDataFile(String name, String suffix, Properties properties){
File cfg = new File(name+"."+suffix);
if(cfg.exists()){
cfg.deleteOnExit();
}
try{
FileOutputStream fos = new FileOutputStream(cfg, false);
properties.store(fos, "for tests only !");
fos.close();
}catch (Exception e){
// log.error("Create Data file fault, error msg: " + e.toString());
throw new RuntimeException("Unable to create the destination file " + cfg.getName(), e);
}
}
  1. 创建连接
public static JCoDestination connect(){
JCoDestination destination =null;
try {
destination = JCoDestinationManager.getDestination(ABAP_AS_POOLED);
} catch (JCoException e) {
// log.error("Connect SAP fault, error msg: " + e.toString());
}
return destination;
}
  1. 方法调用
JCoFunction function = null;
//获取连接
JCoDestination destination = Test.connect();
try {
//获取远程 function 进行后续数据交互
function = destination.getRepository().getFunction("Z_RFC_TEST1");
//导出参数
JCoParameterList imParaList = function.getImportParameterList();
//导入参数
JCoParameterList exportParam = function.getExportParameterList();
//设置传递值
//  exportParam.setValue("xxx", "xxx");
//执行调用
function.execute(destination);
//查询表
JCoTable tb = function.getTableParameterList().getTable("IT");
//循环输出查询到的表数据
for (int i = 0; i < tb.getNumRows(); i++) {
tb.setRow(i);
System.out.print("名字 :" + tb.getString("NAME"));
System.out.print(" | ");
System.out.print("年龄 :" + tb.getInt("AGE"));
System.out.print(" | ");
System.out.println("地址 :"+tb.getString("ADDRESS"));
System.out.println("------------------------------------");
}
} catch (JCoException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • Spring Boot 参考指南 介绍 转载自:https://www.gitbook.com/book/qbgb...
    毛宇鹏阅读 46,951评论 6 342
  • Spring Cloud为开发人员提供了快速构建分布式系统中一些常见模式的工具(例如配置管理,服务发现,断路器,智...
    卡卡罗2017阅读 134,923评论 18 139
  • 天气微凉时 飞来雨燕 雨水短暂来过 仿佛秋风的轻叹 光从指尖流过 温热而细腻 如此宁静的日子 伴随着好天气
    隽永之歌阅读 290评论 0 0
  • 央措和乐胥见讨不到好处便气鼓鼓的离开了。 “娘亲.....”阿离像是做错事情一般,拽着衣角跪在地下不肯起来。 “阿...
    夏汐baby阅读 12,798评论 15 39
  • 古语云:兵马未动,粮草先行 正所谓,鹏程万里必先丰满羽翼,搏击蓝海定当万事俱备 石行长讲话高瞻远瞩、意味深长,我们...
    李凯_5ce4阅读 182评论 0 0