Java 使用rfc调用sap函数

  1. 首先准备 sapjco3.jar sapjco3.dll两个文件
  2. 链接sap 创建 JcoDestination对象
public static JCoDestination getJcoDestination(SapConnInfo sapConnInfo, String destinationName) throws IOException, JCoException {
        Properties properties = new Properties();
        properties.setProperty(DestinationDataProvider.JCO_USER, sapConnInfo.getJcoUser()); // SAP连接名
        properties.setProperty(DestinationDataProvider.JCO_PASSWD, sapConnInfo.getJcoPassword());// 连接密码
        properties.setProperty(DestinationDataProvider.JCO_LANG, sapConnInfo.getJcoLang());// 语言"ZF"
        properties.setProperty(DestinationDataProvider.JCO_CLIENT, sapConnInfo.getJcoClient());// 集团号
        properties.setProperty(DestinationDataProvider.JCO_SYSNR, sapConnInfo.getJcoSysnr());// 系统编号,默认写00 "00"
        properties.setProperty(DestinationDataProvider.JCO_ASHOST, sapConnInfo.getJcoAshost());// SAP服务器地址"10.134.28.98"
//        String name = "ABAP_AS_BOOL";
        String fileName = destinationName;
        File cfg = new File(fileName + ".jcoDestination");
        if (cfg.exists()) {
            cfg.deleteOnExit();
        }else {
            FileOutputStream fos = new FileOutputStream(cfg, false);
            properties.store(fos, "create file");
        }

        return JCoDestinationManager.getDestination(fileName);
    }

3.调用sap 函数

JCoDestination jCoDestination = DbConnection.getJcoDestination(sapConnInfo, destinationName);
//sap 方法返回的table名
String resultTableName = "ZPOGR";
//创建 JCoFunction对象
JCoFunction jCoFunction = jCoDestination.getRepository()
                        .getFunctionTemplate("ZRFC_CTBS_CFA_POGR_01").getFunction();
//配置函数执行参数
JCoParameterList param = jCoFunction.getImportParameterList();
param.setValue("BSI011", dec.getBsi011());
param.setValue("BSI02", dec.getBsi02());
//调用sap 函数
jCoFunction.execute(jCoDestination);
//获取sap 函数返回的JcoTable
JCoTable jCoTable = jCoFunction.getTableParameterList().getTable(resultTableName);
//然后可以遍历JcoTable获取需要的值

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值