有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

java在使用jCo(3.x))访问SAP表时未获取数据

这是我的示例代码。在本例中,只有基本类型,不必设置结构类型。但在输出中,表中不存在任何数据

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

}

更新了代码


共 (2) 个答案

  1. # 1 楼答案

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

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

  2. # 2 楼答案

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

    1. 如果将“”或“”设置为字段。(设置值时,如果这些值有一些值,则最好设置这些值

    2. 如果它说合作伙伴不存在,如果你确定它存在,这意味着你的数据没有正确传递。在设置数据的位置添加调试点,并确保传递正确的名称和值

    3. 此外,您不需要添加(索引),只需添加表即可。appendRow();//但这不会影响你的案子

    4. 此外,当您设置值时,请确保其int字段。(通常不是)在给定的示例中,它的int

    例如:

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

    这只是psuda代码,不起作用