Java 使用JCo SAP运行SAP BAPI时,getNumRows()返回0

Java 使用JCo SAP运行SAP BAPI时,getNumRows()返回0,java,sap,jco,bapi,Java,Sap,Jco,Bapi,我正在编写Java代码,以便使用Java连接器(JCo)从SAP BAPI获取数据。这是我第一次使用JCo连接到SAP。我可以使用Table\u name.getNumColumns()获取数据源中可用的表,还可以获取一个特定的表和列数,该表给出了列的总数。但当我这样做时,table\u name.getNumRows(),它会显示0。在我的数据源中,大约有85行。我如何从这个表中获取行 我一直在使用的代码: public class SapConnection { public

我正在编写Java代码,以便使用Java连接器(JCo)从SAP BAPI获取数据。这是我第一次使用JCo连接到SAP。我可以使用Table\u name.getNumColumns()获取数据源中可用的表,还可以获取一个特定的表和列数,该表给出了列的总数。但当我这样做时,table\u name.getNumRows(),它会显示0。在我的数据源中,大约有85行。我如何从这个表中获取行

我一直在使用的代码:

public class SapConnection {

      public static void gettingTableData(JCoFunction function) {

          JCoParameterList table_list = function.getTableParameterList();
          JCoTable my_table = function.getTableParameterList().getTable("SOME_TABLE");

          System.out.println("Field Count: "+my_table.getFieldCount());

          // This is not working as Number of Rows is 0.
          for(int i = 0; i<my_table.getNumRows(); i++, my_table.nextRow()) {
              // get those rows and do something ..
          }

          System.out.println("Is Empty: "+my_table.isEmpty()); // returns True
          System.out.println("Is First Row: "+my_table.isFirstRow()); // returns false
          System.out.println("Next Row: "+my_table.nextRow()); // returns false
          System.out.println("Num Rows: "+my_table.getNumRows()); // returning 0

        }

      public static void loadDataSourceAndGetData(JCoDestination dest) throws JCoException {

       JCoRepository sapRepository = dest.getRepository();
       JCoFunctionTemplate template = 
           sapRepository.getFunctionTemplate("DATA_SOURCE_NAME");
       JCoFunction my_function = template.getFunction();

       gettingTableData(my_function);

  }

     public static void main(String[] args) throws JCoException {
         // get the Properties created for connection.
         Properties pp = getJcoProperties();
         PropertiesDestinationDataProvider pddp = new PropertiesDestinationDataProvider(pp);
         Environment.registerDestinationDataProvider(pddp);

         JCoDestination dest = getDestination();

         try {
             // Using JCo Context for stateful function calls to Start() and End()
             JCoContext.begin(dest);
             loadDataSourceAndGetData(dest);
             JCoRepository sapRepository = dest.getRepository();
             System.out.println(sapRepository.getMonitor().getLastAccessTimestamp());
         } finally {
             // end the connection.
             JCoContext.end(dest);
         }
    }
}
公共类SapConnection{
公共静态void gettingTableData(JCoFunction函数){
JCoParameterList table_list=函数.getTableParameterList();
JCoTable my_table=function.getTableParameterList().getTable(“一些表”);
System.out.println(“字段计数:+my_table.getFieldCount());
//这不起作用,因为行数为0。

对于(int i=0;i如果您想从SAP BAPI获取一些数据,那么调用此BAPI也会有很大帮助。数据不会凭空在JCo对象中自动具体化。
在代码中,您不执行任何JCoFunction


设置此BAPI的强制导入参数值(如果有),执行BAPI(您的JCoFunction对象)然后,您将从SAP系统获得导出数据作为响应,该系统还将向JCoTable对象添加适当的行。

如果可能,请尝试在SAP端执行函数以验证返回的行数Hey@DarkKnight您是指使用ABAP执行吗?是的,正是我想说的确保@DarkKnight我会尝试。谢谢关于回复。Hi@DarkKnight我们已经使用ABAP实现了,它正在工作。IDK为什么它在Java中不工作:(