2

I have a SAP RFC function module named ZRFC_BOM_005. After I execute 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.

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 parameters I put, because I have checked it by another software which is link to SAP.

Is it possible to be a timeout problem? Because when I execute this RFC, it takes about 10 mins to run.

Then how can I solve this?

This is my code:

  • to 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);
    
  • printJCoTable function 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;
      }   
    
Sandra Rossi
  • 11,934
  • 5
  • 22
  • 48
LittleY
  • 17
  • 4
  • How many rows does the JCoTable "T_BOMITEM" have after execution? What is returned from jcoTable.getNumRows()? – Trixx Mar 02 '18 at 05:03
  • 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 Mar 05 '18 at 11:41
  • 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 Mar 05 '18 at 13:17
  • @Trixx 1.there are 226 columns(Field count) in the JCoTable "T_BOMITEM" 2.jcoTable.getNumRows() is 0 – LittleY Mar 19 '18 at 04:11
  • @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 Mar 19 '18 at 04:17
  • @Lothar My question is i always got 0 rows returned from jco, but when i go into SAP, i can find those data – LittleY Mar 19 '18 at 04:18

1 Answers1

1

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.

Trixx
  • 1,796
  • 1
  • 15
  • 18
  • After I tried another RFC, I also has this table empty problem - jcoTable.getNumRows() returns 0. And I'm sure it's not because of date format. The params are only string numbers. Also, I can't access your SAP note 206068 link, and I couldn't find what's the key information after I googled it... Do you have other reference? – LittleY Mar 20 '18 at 13:34
  • If you can't access the SAP note, from where did you get the SAP JCo SDK? If you downloaded JCo legally then you should be able to read SAP notes, too. And as said: Try to execute your RFM with SE37 in the ABAP backend, and if provides the correct results then check the differences of the provided IMPORT parameter values with using the ABAP debugger. – Trixx Mar 20 '18 at 15:12