2

我有一个名为 ZRFC_BOM_005 的 SAP RFC。执行 RFC 函数后,我尝试从返回的表中获取字段的值,但它只显示字段的名称而没有字段的值。但是,函数“printJCoTable(JCoTable jcoTable)”可以与其他 RFC 一起正常工作。我不知道这里有什么问题。

这是我的代码:

执行 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("%s\t\t", 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("%s\t", fld.getValue()));
        }
        listData.add(list);
        System.out.println();           
    }       
    return listData;
}   

但事实证明只有字段的名称,但没有字段的值。

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

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

那我该如何解决呢?

4

1 回答 1

1

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

我猜你的 DATE_FROM 和 DATE_TO 参数设置错误。要么把java.util.Date对象放在那里,要么如果datetodatefrom必须是字符串,然后选择日期格式yyyyMMddyyyy-MM-dd它们的内容,即今天日期的“20180319”或“2018-03-19”。

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

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

于 2018-03-19T10:02:14.843 回答