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 接口名称{} * 接口不能拥有构造方法 ...
随机推荐
- PHP学习当中遗漏的知识点
一, 当双引号中包含变量时,变量会与双引号中的内容连接在一起: 当单引号中包含变量时,变量会被当做字符串输出. <?php $love = "I love you!"; $s ...
- 查找素数(0~1000)的算法(Java代码)
1.一般方法,设置标兵,进行查找 class prime{ //检查是否是素数 public void isPrime(){ ; ;i<=;i++){ ; ;j<i;j++){ ){ co ...
- 山东理工大学第七届ACM校赛-飞花的鱼塘 分类: 比赛 2015-06-26 10:30 43人阅读 评论(0) 收藏
飞花的鱼塘 Time Limit: 1000ms Memory limit: 65536K 有疑问?点这里^_^ 题目描述 一日,飞花壕在稷下湖游玩,忽然,飞花巨有了一个养鱼的想法,于是,他大手 ...
- FTP操作类
using System; using System.Collections.Generic; using System.Net; using System.IO; namespace HGFTP { ...
- Java多线程的三种实现方式
java多线程的三种实现方式 一.继承Thread类 二.实现Runnable接口 三.使用ExecutorService, Callable, Future 无论是通过继承Thread类还是实现Ru ...
- Robotium中定位Android客户端疑难元素
对于没有id,没有text,只有一个图标的疑难元素(ImageView),应该如何定位呢?拿人人网个人主页的设置按钮举例: 我最终是通过定位页面上可以定位到的其他元素,然后通过其他元素与疑难元素相对坐 ...
- 短信轰炸PC版
前言 之前用过android版短信轰炸的apk,于是想反编apk查看源码找短信接口,做一个PC版本的,不料反编失败.后不了了之... 昨日逛论坛时无意中看到一个网站有此功能,打开一试究竟,效果可以,于 ...
- [Emacs] 常用快捷键-- 生存指南
Emacs 常用快捷键--生存指南 主要用来记录自己常用到的快捷键,记住这些快捷键可以保证你在Emacs中生存. 有可能不全,但是够用了(简单写文本). 保存和退出 使用 C-x C-s 保存文件. ...
- FlashFXP命令行
flashfxp.exe -upload ftp://user:pass@ip:port -localpath="本地路径" -remotepath="远程FTP上的路 ...
- windows下mysql自动定时备份bat
@echo off : basedataset ip=192.168.12.41set user=rootset password=12456 set databaseName=test set /a ...