SAP接口编程之 JCo3.0 系列(03) : 表参数
表参数 (table parameter) 作为 export parameter
BAPI_COMPANYCODE_GETDETAIL
是一个适合演示的函数,没有 importing paramter
参数,调用后 COMPANYCODE_GETDETAIL
表参数 返回 SAP 系统中所有公司代码的清单。只有公司代码ID和公司代码名称两个字段。
JCo 中,与表参数相关的两个接口( interface ) 类型是 JCoTable
和JCoRecordMetaDta
, JCoTable
就是 Remote Function Module (RFM) 的表参数,而JCoRecordMetaDta
是 JCoTable
或 JCoStructure
的元数据 (meta-data)。
在 .net 环境中,我喜欢将 IRfcTable
转换成 DataTable
,但 Java 没有类似的数据结构,所以决定直接在方法中传递 JCoTable
算了。但为了方便输出,可以考虑使用一段通用代码:
package jco3.utils;import com.sap.conn.jco.JCoField;
import com.sap.conn.jco.JCoRecordMetaData;
import com.sap.conn.jco.JCoTable;public class JCoUtils
{public static void printJCoTable(JCoTable jcoTable){// header// JCoRecordMeataData is the meta data of either a structure or a table.// Each element describes a field of the structure or table. JCoRecordMetaData tableMeta = jcoTable.getRecordMetaData(); for(int i = 0; i < tableMeta.getFieldCount(); i++){System.out.print(String.format("%s\t", tableMeta.getName(i))); }System.out.println(); // new line// line itemsfor(int i = 0; i < jcoTable.getNumRows(); i++){// Sets the row pointer to the specified position(beginning from zero)jcoTable.setRow(i);// Each line is of type JCoStructurefor(JCoField fld : jcoTable){System.out.print(String.format("%s\t", fld.getValue()));}System.out.println();}}
}
要点说明:
对于 JCoTable
,输出表头和行项目。表头通过获取 JCoTable
的 meta-data,然后使用 meta-data 的 getName()
方法。
JCoRecordMetaData tableMeta = jcoTable.getRecordMetaData();
for(int i = 0; i < tableMeta.getFieldCount(); i++){System.out.print(String.format("%s\t", tableMeta.getName(i)));
}
JCoTable
每一行都是一个 JCoStructure
,可以通过 setRow()
设置指针的位置,然后再遍历各个 field:
//行数据
for(int i = 0; i < jcoTable.getNumRows(); i++){// Sets the row pointer to the specified position(beginning from zero)jcoTable.setRow(i);// Each line is of type JCoStructure// 列字段for(JCoField fld : jcoTable){System.out.print(String.format("%s\t", fld.getValue()));}System.out.println();
}
完成输出之后,接下来就是 RFM 调用:
package jco3.demo5;import org.junit.Test;
import com.sap.conn.jco.*;
import jco3.utils.JCoUtils;public class JCoTableDemo
{public JCoTable getCocdList() throws JCoException{/*** Get company code list in SAP system using BAPI BAPI_COMPANYCODE_GETLIST. * Since JCoTable is rather flexible, we simply use this interface as return value*/JCoDestination dest = JCoDestinationManager.getDestination("ECC");JCoFunction fm = dest.getRepository().getFunction("BAPI_COMPANYCODE_GETLIST"); fm.execute(dest);JCoTable companies = fm.getTableParameterList().getTable("COMPANYCODE_LIST");return companies; }@Testpublic void printCompanies() throws JCoException{JCoTable companies = this.getCocdList();JCoUtils.printJCoTable(companies);}
}
表参数作为 import parameter
table 作为输入参数,主要解决 table 数据填充问题,基本模式如下:
someTable.appendRow();
someTable.setValue("FIELD_NAME", someValue);
以 RFC_READ_TABLE
函数为例,读取 SAP 标准表 USR04
数据。
package jco3.demo5;import org.junit.Test;
import com.sap.conn.jco.*;
import jco3.utils.JCoUtils;public class JCoTableAsImport
{ public JCoTable readTable() throws JCoException{/*** Shows how to process JCoTable as importing parameter*/JCoDestination dest = JCoDestinationManager.getDestination("ECC");JCoFunction fm = dest.getRepository().getFunction("RFC_READ_TABLE");// table we want to query is USR04// which is the user authorization table in SAP systemfm.getImportParameterList().setValue("QUERY_TABLE", "USR04");// output data will be delimited by commafm.getImportParameterList().setValue("DELIMITER", ",");// processing table parametersJCoTable options = fm.getTableParameterList().getTable("OPTIONS");// modification date >= 2012.01.01 and <= 2015.12.31options.appendRow();options.setValue("TEXT", "MODDA GE '20120101' ");options.appendRow();options.setValue("TEXT", "AND MODDA LE '20151231' ");// We only care about fields of [user id] and [modification date] String[] outputFields = new String[] {"BNAME", "MODDA"};JCoTable fields = fm.getTableParameterList().getTable("FIELDS");int count = outputFields.length;fields.appendRows(count);for (int i = 0; i < count; i++){fields.setRow(i);fields.setValue("FIELDNAME", outputFields[i]); }fm.execute(dest);JCoTable data = fm.getTableParameterList().getTable("DATA");return data;}@Testpublic void printUsers() throws JCoException{JCoTable users = this.readTable();JCoUtils.printJCoTable(users);}
}
在代码中我们使用了两种方法来插入 table 的行项目.
第一种方法:
JCoTable options = fm.getTableParameterList().getTable("OPTIONS");
// modification date >= 2012.01.01 and <= 2015.12.31
options.appendRow();
options.setValue("TEXT", "MODDA GE '20120101' ");
options.appendRow();
options.setValue("TEXT", "AND MODDA LE '20151231' ");
第二种方法:
String[] outputFields = new String[] {"BNAME", "MODDA"};
JCoTable fields = fm.getTableParameterList().getTable("FIELDS");
int count = outputFields.length;
fields.appendRows(count);
for (int i = 0; i < count; i++){fields.setRow(i);fields.setValue("FIELDNAME", outputFields[i]);
}
JCoTable
重要方法总结
作者:https://www.jianshu.com/u/fd37d4449963
SAP接口编程之 JCo3.0 系列(03) : 表参数相关推荐
- SAP接口编程 之 JCo3.0系列:Table参数
Table参数作为export parameter BAPI_COMPANYCODE_GETDETAIL是一个适合演示的函数,没有import paramter参数,调用后COMPANYCODE_GE ...
- php调用sap端rfc接口,SAP 接口编程之 RFC 系列(15) : 调用自定义函数
从外部环境调用自定义函数 (FM, Function Module)与调用 SAP 内置的函数并没有不同,需要注意的是在 SAP 系统自定义 FM 的要点: 1)FM 必须是 Remote-enabl ...
- 大白话,讲编程之《ES6系列连载》汇总,再也不用翻历史消息了
想翻看以前的ES6系列章节,老是要查看公众号的历史消息,特别是在地铁里没wifi的时候,每次页面切换都要load很久,相当麻烦. 别怕,最懂你们的前端君又来了,来一篇完美的汇总,你要的ES6,都在这里 ...
- SpringBoot2.0系列(03)---SpringBoot之使用freemark视图模板
前言 freemarker介绍: FreeMarker是一款模板引擎: 即一种基于模板和要改变的数据, 并用来生成输出文本(HTML网页.电子邮件.配置文件.源代码等)的通用工具. 它不是面向最终用户 ...
- python画鱼教程_Python Flask高级编程之从0到1开发《鱼书》精品项目 学习 教程??
一 .安装环境 我们使用 flask web框架,并用 sqlalchemy来做数据库映射,并使用 migrate做数据迁移. $ pip install flask $ pip install SQ ...
- C语言编程之求0—7能组成的奇数个数
问题描述:使用C语言编程实现求0-7所能组成的奇数个数. 程序源码: #include<stdio.h> void main() { long sum=4,s=4; int j; for( ...
- 如何使用JCO3.0同时访问多个SAP系统
代码实现如下,从上到下依次调用,直到被获取连接为止. JCOProvider类似注册中心,注册连接信息. 如有问题请参考: 如何使用JCO3.0同时访问多个SAP系统 SAP接口编程 之 JCo3.0 ...
- SAP系统和微信集成的系列教程之十:如何在SAP C4C系统里直接回复消息给微信用户
本系列的英文版Jerry写作于2017年,这个教程总共包含十篇文章,发表在SAP社区上. 系列目录 (1) 微信开发环境的搭建 (2) 如何通过微信公众号消费API (3) 微信用户关注公众号之后,自 ...
- zbb20180929 thread java并发编程之Condition
java并发编程之Condition 引言 在java中,对于任意一个java对象,它都拥有一组定义在java.lang.Object上监视器方法,包括wait(),wait(long timeout ...
- Linux内存管理:ARM64体系结构与编程之cache(3):cache一致性协议(MESI、MOESI)、cache伪共享
目录 为什么系统软件人员要深入了解cache? cache一致性协议 神马是MESI协议? MESI的操作 MESI状态图 演示:初始化状态为I的cache line 当本地CPU的缓存行状态为I时, ...
最新文章
- PL/SQL中查询Oracle大数(17位以上)时显示科学计数法的解决方法
- ACCESS的Ole对象读取
- Number of Components
- P7099-[yLOI2020]灼【数学期望,结论】
- HDU 4027 Can you answer these queries?(线段树/区间不等更新)
- PHP地图规划骑行路径,骑行路线规划-路线规划-开发指南-iOS 导航SDK | 高德地图API...
- eclipse 打包 apk 文件
- FAST_ICA MTALAB工具包下载/ICA分析/独立成分分析MATLAB安装包/ICA toolbox
- 小爱同学app安卓版_小爱同学app下载_小爱同学官网版手机客户端下载 安卓版 V2.8.60 - 罐头安卓网...
- 李宏毅2022机器学习HW4解析
- 产品包装设计在品牌和营销中的重要性
- 【网络通信】【电信运营商实战工程师】思科设备篇-网络工程师必备基础知识
- 关于ImportError: DLL load failed: 找不到指定的模块
- 使用navicat新建sqlite数据库
- ibox (bootstrap)
- 在当当和亚马逊中搜书并输出最低价格
- Python财务分析-Pandas复制Google Trends
- c语言 用计数控制的循环实现正数累加求和,C语言循环结构程序设计实验五
- c语言中生日蛋糕图片大全,关于生日蛋糕图片大全
- springboot整合pdf.js实现在线预览pdf文件
热门文章
- 2020年电工(技师)找答案及电工(技师)考试申请表
- Java CXF框架(案例加解析)(快速入门)模拟服务端和客户端(客户端远程调用服务端功能)
- AMADA阿玛达触摸屏维修折弯机主机维修
- 什么是准静态平坦瑞利衰落信道?
- 《高等代数学》(姚慕生),习题1.2:三阶行列式
- 华为海思芯片自立自强!
- 华为海思和MTK 智能手机
- 华为面试题:一头牛重 800 公斤,一座桥承重 700 公斤,请问牛怎么过桥?
- 高频电子线路张肃文第五版详解_高频电子线路第五版张肃文主编学习课件(上).ppt...
- 【U+】友加畅捷U+通用财务清理操作员密码