美文网首页
Java_SAP RFC

Java_SAP RFC

作者: hijll | 来源:发表于2018-03-06 15:47 被阅读0次

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();
}

相关文章

  • Java_SAP RFC

    Java 和 SAP 数据交互 RFC 模式 引入相关 sapjco3.jar 和 sapjco.dll 。 说明...

  • RFC5661

    RFC文档 RFC3530: NFS 4 RFC5661: NFS 4.1 RFC4506: XDR RFC553...

  • DNS威胁

    https://www.rfc-editor.org/rfc/rfc3833.html

  • RFC文档目录

    阅读原版RFC RFC Editor RFC Editor Search RFC 文档的形成 在1992年成立的 ...

  • Mojo::Message::Request

    简介 Mojo :: Message :: Request是基于RFC 7230,RFC 7231,RFC 723...

  • 创建 GUID/UUID

    根据 RFC 4122[https://www.ietf.org/rfc/rfc4122.txt],UUID(通用...

  • BFD RFC 阅读 简记

    参考: https://www.rfc-editor.org/rfc/rfc5880[https://www.rf...

  • Mojo::Message

    简介 Mojo :: Message是基于RFC 7230,RFC 7231和RFC 2388的 HTTP消息容器...

  • HTTP2 协议初识

    RFC:https://tools.ietf.org/html/rfc7540 RFC 中英文对照:https:...

  • Syslog协议-RFC5424 + RFC3164

    RFC5424协议手册地址:https://tools.ietf.org/html/rfc5424RFC3164协...

网友评论

      本文标题:Java_SAP RFC

      本文链接:https://www.haomeiwen.com/subject/cnqrfftx.html