RFC_READ_TABLE 的一般用途
我从未使用过 JCo,但据我所知,它的接口与 .Net 连接器 NCo 非常相似。这基本上是 NCo 代码,添加了一些猜测,但它应该可以工作。
// get the table parameter FIELDS that should be in the parameter list
// the parameter table has several fields, only the field FIELDNAME has to be set before calling the function module
JCOTable inputTableParam = function.getTableParameterList().getTable("FIELDS");
// add a row to the FIELDS table parameter
inputTableParam.appendRow();
// set values for the new row
inputTableParam.setValue("FIELDNAME", "EMPLOYEE");
// just for fun, add another field to retrieve
inputTableParam.appendRow();
inputTableParam.setValue("FIELDNAME", "SURNAME");
// now we have to set the non-table parameters
JCoParameterList inputParamList = function.getImportParameterList();
// parameter QUERY_TABLE, defines which table to query
inputParamList.setValue("QUERY_TABLE", "ZEMPLOYEES");
// parameter DELIMITER - we get a single string as the return value, the field values within that string are delimited by this character
inputParamList.setValue("DELIMITER", ";");
// execute the function
function.execute(destination);
// the parameter table DATA contains the rows
JCoTable table = function.getTableParameterList().getTable("DATA");
最后,你的变量table
将保存一个表对象,该对象具有一个名为WA
。该字段包含您在输入参数表中选择的字段的内容FIELDS
。你可以迭代一遍table
并逐行获取值。
使用 RFC_READ_TABLE 进行查询
RFC_READ_TABLE
并不真正允许查询,它只允许您定义WHERE
条款。这TABLE
范围OPTIONS
有一个字段TEXT
,72个字符宽,只能取ABAP
合规的WHERE
条款。
为了扩展上面的示例,我们将添加一个 where 子句以仅从表中选择条目ZEMPLOYEES
with SURNAME
=“史密斯”和FORNAME
=“约翰”。
JCOTable optionsTableParam = function.getTableParameterList().getTable("OPTIONS");
// add a row to the FIELDS table parameter
optionsTableParam.appendRow();
optionsTableParam.setValue("TEXT", "SURNAME EQ 'SMITH' AND FORNAME EQ 'JOHN');
场TEXT
仅 72 个字符长,因此如果您想添加更长的子句,则必须手动将条件分成几行。RFC_READ_TABLE
有点粗糙和有限。
表之间的复杂连接可以通过在 SAP 系统中创建视图来实现(事务SE11
),然后使用 RFC_READ_TABLE 查询该视图。
如果您想从JCo调用功能模块,那么熟悉基本的功能模块属性将会非常有帮助。可以查看transaction中的一个功能模块定义SE37
。在那里你可以看到IMPORT
, EXPORT
, CHANGING
and TABLE
参数。您必须填写的参数以及包含结果的参数取决于您调用的功能模块 -RFC_READ_TABLE
有不同的,比如说,BAPI_DELIVERY_GETLIST
.
这是 JCoFunction 的文档以及 JCo 和 NCo 之间的区别之一,JCo 有单独的函数来获取和设置不同的参数类型:https://help.hana.ondemand.com/javadoc/com/sap/conn/jco/JCoFunction.html https://help.hana.ondemand.com/javadoc/com/sap/conn/jco/JCoFunction.html