2
votes

I have a SAP RFC named ZRFC_BOM_005. After I exec the RFC function, I try to get field's value from the returned table, but it only shows field's name but no field's value. However, the function "printJCoTable(JCoTable jcoTable)" works fine with other RFC. I don't know what's wrong with it here.

This is my code:

Execute 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);

Use printJCoTable to print table's field and table's value:

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;
}   

But it turns out only field's name but no field's value.

PS:I'm sure that there are returned field's value exist with the same params i put, because i have checked it by another software which is link to SAP.

is it possible to be Timeout problem ? because when I exec this RFC, it takes about 10 mins to run.

Then how can I solve this?

1
How many rows does the JCoTable "T_BOMITEM" have after execution? What is returned from jcoTable.getNumRows()? - Trixx
The inner for-loop seems to have two end-}... Does this even compile? In any case: if you run your example with JCo trace activated (level 6 or 7 should be enough), you should see in the trace, whether the R/3 returns any data for that table. And no: timeout can NOT be a problem here. You would get an exception (SYSTEM_FAILURE), if the ABAP side would abort with a timeout. - Lanzelot
Instead of calling the SAP system, you can set some rows yourself and call your print-method. If no values show up, either, you can rule out the SAP side and concentrate on the implementation of the print-method. - Lothar
@Trixx 1.there are 226 columns(Field count) in the JCoTable "T_BOMITEM" 2.jcoTable.getNumRows() is 0 - LittleY
@Lanzelot Yes, it is after compile. It was my copy-past mistake, i'd already edited it. I got this exception:Exception in thread "main" java.lang.IllegalStateException: Trying to access row values in a table which does not have any rows yet. But my question is when i go into SAP system, i can found those data - LittleY

1 Answers

1
votes

As you commented that jcoTable.getNumRows() returns 0:
That means that the table is empty and the JCo exception error message is correct if you are trying access any content fields of this table. So your RFC call returns this empty table which means that your input parameter values do not seem to contain the data which you are expecting. Check them once again.

I guess your DATE_FROM and DATE_TO parameters are set wrongly. Either put java.util.Date objects in there, or if dateto and datefrom have to be strings, then choose the date format yyyyMMdd or yyyy-MM-dd for their content, i.e. "20180319" or "2018-03-19" for today's date.

If it is not that easy, it also could be something with the EXTERNAL to INTERNAL representation conversion exit routines which are called and used by transaction SE37 automatically, but not if the RFC-enabled function module is called directly from external side. For more details on this and other issues in this area I recommend to study SAP note 206068.

You may check both scenarios with the ABAP debugger tool in order to see which input parameter values are really passed when your function module is called via SE37 compared to being called via your JCo program.