使用jCo(3.x)访问SAP表时无数据

问题描述 投票:0回答:2

这是我的示例代码。在这个例子中只有基本类型,没有结构类型必须设置。但是在输出中没有数据存在于表中。

当我检查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);

}

更新了代码。

java spring-boot sap jco
2个回答
0
投票

多个问题可能导致这种情况

  1. 如果你设置“”或“”到字段。 (当你设置值更好时,如果它们有一些值
  2. 如果它说伙伴不存在,如果你确定它存在,这意味着你的数据没有正确通过。将调试点添加到设置数据的位置,并确保传递正确的名称和正确的值。
  3. 你也不需要添加(索引)你只需要table.appendRow(); //但这不会影响你的情况
  4. 当你setValue确保它的int归档。 (通常不是)在你给出的例子中它的int

例如:

private void configureTableParameters(JCoParameterList tableParameters){
    JCoTable jCoTable=tableParameters.getTable(key);
    jCoTable.appendRow();
    if(value!=null)
    jCoTable.setValue(fieldKey,String.valueOf(value));

}

这只是psuda代码,不起作用


0
投票

首先通过事务代码SE37使用SAP GUI测试ABAP远程功能模块。如果此测试成功并且如果使用相同的参数值从JCo调用您获得不同的结果,那么我建议研究SAP注意206068可能的原因。

还要检查你的方法configureTableParameters。我想,index应该是一个字段索引而不是行数。您的实现将创建太多不必要的行。我假设你想打电话给table.appendRow();而不是table.appendRows(index);。此外,您可能希望使用值"100"填充行中的第一个字段,在这种情况下,您必须传递索引值0而不是1

© www.soinside.com 2019 - 2024. All rights reserved.