Java SAP JCo3 无法从返回的表中查找数据



我有一个名为ZRFC_BOM_005的SAP RFC功能模块。执行 RFC 函数后,我尝试从返回的表中获取字段的值,但它只显示字段的名称,而不显示字段的值。但是,该函数printJCoTable(JCoTable jcoTable)与其他 RFC 配合使用。我不知道这里有什么问题。

但结果只显示字段的名称,而没有字段的值。

PS:我确定返回字段的值与我输入的参数相同,因为我已通过链接到SAP的另一个软件对其进行了检查。

是否有可能出现超时问题?因为当我执行这个 RFC 时,运行大约需要 10 分钟。

那我该如何解决这个问题呢?

这是我的代码:

  • 要执行 SAP RFC,请执行以下操作:

    JCoFunction function = destination.getRepository().getFunction("ZRFC_BOM_005");             
    JCoParameterList input = function.getImportParameterList();     
    input.setValue("DATE_FROM", datefrom);
    input.setValue("DATE_TO", dateto);                      
    input.setValue("I_CAPID", i_capid);
    input.setValue("I_MEHRS", i_mehrs);
    input.setValue("I_MTNRV", i_mtnrv);
    input.setValue("I_STLAN", i_stlan);
    input.setValue("I_WERKS", i_werks);         
    if (function == null)
    throw new RuntimeException("ZRFC_BOM_005 not found in SAP.");
    try {           
    function.execute(destination);          
    } catch (AbapException e) {
    System.out.println(e.toString());           
    }
    JCoTable table = function.getTableParameterList().getTable("T_BOMITEM");
    printJCoTable(table);
    
  • printJCoTable打印表的字段和表的值的函数:

    public static List<List<String>> printJCoTable(JCoTable jcoTable) {
    List<List<String>> listData = new ArrayList<List<String>>();        
    // 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("%stt", 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
    List list = new ArrayList<>();
    for (JCoField fld : jcoTable) {             
    list.add(fld.getValue());               
    System.out.print(String.format("%st", fld.getValue()));
    }
    listData.add(list);
    System.out.println();           
    }       
    return listData;
    }   
    

正如您评论的那样,jcoTable.getNumRows()返回 0:这意味着
该表为空,如果您尝试访问此表的任何内容字段,则 JCo 异常错误消息是正确的。 因此,您的 RFC 调用返回此空表,这意味着您的输入参数值似乎不包含您期望的数据。再次检查它们。

我想您的DATE_FROM和DATE_TO参数设置错误。要么把java.util.Date对象放进去,要么如果datetodatefrom必须是字符串,那么选择日期格式yyyyMMddyyyy-MM-dd其内容,即"20180319"或"2018-03-19"作为今天的日期。

如果不是那么容易,它也可能是事务 SE37 自动调用和使用外部到内部表示转换退出例程的东西,但如果直接从外部调用启用 RFC 的功能模块,则不会。有关此领域此问题和其他问题的更多详细信息,我建议研究SAP注释206068。

您可以使用 ABAP 调试器工具检查这两种情况,以查看通过 SE37 调用函数模块与通过 JCo 程序调用时真正传递了哪些输入参数值。

最新更新