这是我的示例代码。在这个例子中只有基本类型,没有结构类型必须设置。但是在输出中没有数据存在于表中。
当我检查SAP中的记录时,它包含此特定id的多个记录。有人可以向我解释这个吗?
public void invokeRFC(JCoDestination destination) {
JCoFunction function=null;
try
{
JCoFunctionTemplate functionTemplate = destination.getRepository().getFunctionTemplate("RFC_METHOD");
if (functionTemplate != null) {
function = functionTemplate.getFunction();
}
if (function == null)
throw new RuntimeException("Not found in SAP.");
//to fill elementary types and structures
configureImportParameters(function,"xxx", "abc");
//to fill table type parameters
configureTableParameters(function, "tblName",1,"100");
function.execute(destination);
} catch (JCoException e)
{
e.printStackTrace();
}
}
public void configureTableParameters(JCoFunction function, String table_name, int index, String id) {
JCoTable table = function.getTableParameterList().getTable("table_name");
table.appendRow();
table.setRow(index);
table.setValue("Partner", "100");
}
private void exportTable(JCoFunction jCoFunction, String tblName) {
JCoTable resultTable = jCoFunction.getTableParameterList().getTable(tblName);
int value = resultTable.getNumRows();
System.out.println(value);
}
private void configureImportParameters(JCoFunction function, String param1, String param2) {
JCoParameterList parameterList =
function.getImportParameterList();
parameterList.setValue("field1", param1);
parameterList.setValue("field2", param2);
}
更新了代码。
多个问题可能导致这种情况
例如:
private void configureTableParameters(JCoParameterList tableParameters){
JCoTable jCoTable=tableParameters.getTable(key);
jCoTable.appendRow();
if(value!=null)
jCoTable.setValue(fieldKey,String.valueOf(value));
}
这只是psuda代码,不起作用
首先通过事务代码SE37使用SAP GUI测试ABAP远程功能模块。如果此测试成功并且如果使用相同的参数值从JCo调用您获得不同的结果,那么我建议研究SAP注意206068可能的原因。
还要检查你的方法configureTableParameters
。我想,index
应该是一个字段索引而不是行数。您的实现将创建太多不必要的行。我假设你想打电话给table.appendRow();
而不是table.appendRows(index);
。此外,您可能希望使用值"100"
填充行中的第一个字段,在这种情况下,您必须传递索引值0
而不是1
。