SAP接口编程 之 JCo3.0系列(03) : Table参数
Table参数作为export parameter
BAPI_COMPANYCODE_GETDETAIL
是一个适合演示的函数,没有import paramter参数,调用后COMPANYCODE_GETDETAIL
表参数返回SAP系统中所有公司代码的清单。只包括公司代码ID和公司代码名称两个字段。
JCo中,与表参数相关的两个接口是JCoTable
和JCoRecordMetaDta
, JCoTable
就是RFM中tabl参数,而JCoRecordMetaDta
是JCoTable
或JCoStructure
的元数据。
在.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 items
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();
}
}
}
要点说明:
对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
* 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;
}
@Test
public void printCompanies() throws JCoException
{
JCoTable companies = this.getCocdList();
JCoUtils.printJCoTable(companies);
}
}
Table参数作为import parameter
table作为输入参数,主要解决填充table的问题,基本模式如下:
someTable.appendRow();
someTable.setValue("FLDNAME", 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)
*/
JCoDestination dest = JCoDestinationManager.getDestination("ECC");
JCoFunction fm = dest.getRepository().getFunction("RFC_READ_TABLE");
// table we want to query is USR04
// which is user authorization table in SAP
fm.getImportParameterList().setValue("QUERY_TABLE", "USR04");
// output data will be delimited by comma
fm.getImportParameterList().setValue("DELIMITER", ",");
// processing table parameters
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' ");
// 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;
}
@Test
public 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重要方法总结

原文链接:http://www.jianshu.com/p/a088510cf965
著作权归作者所有,转载请联系作者获得授权,并标注“简书作者”。
SAP接口编程 之 JCo3.0系列(03) : Table参数的更多相关文章
- SAP接口编程 之 JCo3.0系列(01):JCoDestination
SAP接口编程 之 JCo3.0系列(01):JCoDestination 字数2101 阅读103 评论0 喜欢0 JCo3.0是Java语言与ABAP语言双向通讯的中间件.与之前1.0/2.0相比 ...
- SAP接口编程 之 JCo3.0系列(02) : JCo Client Programming
SAP接口编程 之 JCo3.0系列(02) : JCo Client Programming 字数545 阅读52 评论0 喜欢1 JCo3.0调用SAP函数的过程 大致可以总结为以下步骤: 连接至 ...
- SAP接口编程 之 JCo3.0系列(04) : 会话管理
在SAP接口编程之 NCo3.0系列(06) : 会话管理 这篇文章中,对会话管理的相关知识点已经说得很详细了,请参考.现在用JCo3.0来实现. 1. JCoContext 如果SAP中多个函数需要 ...
- SAP接口编程 之 JCo3.0系列(05) : Exception Handling
JCO3.0的Exception,常用的Exception如下: JCoException 继承自java.lang.Exception,是JCo3中Exception的基类. JCoRuntimeE ...
- 2690036 - SAP HANA 2.0 SPS 03 Database Revision 034
Symptom This is the SAP Release Note for SAP HANA 2.0 Database Revision 034 (2.00.034.00) of the SAP ...
- LXD 2.0 系列(四):资源控制
LXD 提供了各种资源限制.其中一些与容器本身相关,如内存配额.CPU 限制和 I/O 优先级.而另外一些则与特定设备相关,如 I/O 带宽或磁盘用量限制.-- Stéphane Graber 本文导 ...
- Java 集合系列 03 ArrayList详细介绍(源码解析)和使用示例
java 集合系列目录: Java 集合系列 01 总体框架 Java 集合系列 02 Collection架构 Java 集合系列 03 ArrayList详细介绍(源码解析)和使用示例 Java ...
- Spring Boot 2.0系列文章(七):SpringApplication 深入探索
关注我 转载请务必注明原创地址为:http://www.54tianzhisheng.cn/2018/04/30/springboot_SpringApplication/ 前言 在 Spring B ...
- java接口,接口的特性,接口实现多态,面向接口编程
package cn.zy.cellphone; /**接口是一种引用数据类型.使用interface声明接口,形式 * 形式:public interface 接口名称{} * 接口不能拥有构造方法 ...
随机推荐
- 实现Ecshop商品跳到淘宝、京东等的购买链接
今天简单的实现了一下ecshop商品导出到第三方的购买链接功能.大致思路是给商品添加一个buy_link的text字段,存为json结构,然后通过json解析输出到商品购买页面 1.添加字段 增加购买 ...
- Greenplum迁移到配置不同的GP系统
要使用gp_restore或gpdbrestore并行恢复操作,恢复的系统必须与备份的系统具有相同的配置(相同数量的Instance).如果想要恢复数据库对象和数据到配置不同的系统(比如系统扩展了更多 ...
- 原来样式改变不了(input type="file")
label { background-color: #979fa8; color: #fff; display: inline-block; padding: .8rem 4rem; cursor: ...
- LeetCode----67. Add Binary(java)
package addBinary67;/* Given two binary strings, return their sum (also a binary string).For example ...
- [算法][C]计算向量的角度
C 语言里 double atan2(double y,double x) 返回的是原点至点(x,y)的方位角,即与 x 轴的夹角.也可以理解为复数 x+yi 的辐角.返回值的单位为弧度,取值范围为 ...
- Cocos2dx-lua开发之c++绑定到lua
一. 简单介绍 文章介绍是在实际的游戏开发项目中,将自定义的C++类绑定到lua中,能够让lua调用c++类.会创建一个python脚本,执行python脚本会让自动将我们的c++类绑定到lua.生成 ...
- 关于基于webrtc的android-apk 和 webrtc-brows
这一段时间我在做一些关于基于webrtc应用的一些研究,做个一个android的demo,详情如下: 手机客户端: 基于webrtc的 android apk (webrtc 代码版本 R67 ...
- Android Webview实现文件下载功能
在做美图欣赏Android应用的时候,其中有涉及到Android应用下载的功能,这个应用本身其实也比较简单,就是通过WebView控制调用相应的WEB页面进行展示.刚开始以为和普通的文件下载实 ...
- 20160113006 asp.net实现ftp上传代码(解决大文件上传问题)
using System;using System.Configuration;using System.Data;using System.Linq;using System.Web;using S ...
- Financial Management 分类: POJ 2015-06-11 10:51 12人阅读 评论(0) 收藏
Financial Management Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 164431 Accepted: ...