简体   繁体   English

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

[英]getNumRows() returns 0 when running SAP BAPI using JCo SAP

I am writing Java Code to get data from SAP BAPI using Java Connector (JCo) .我正在编写 Java 代码以使用Java Connector (JCo)SAP BAPI获取数据。 This is my first time to make a connection to SAP using JCo.这是我第一次使用 JCo 连接到 SAP。 I was able to get the Tables available in the Data Source and also get one particular Table and Number of Columns using table_name.getNumColumns() which gives me the total count of columns.我能够获得数据源中可用的表格,并且还使用table_name.getNumColumns()获得了一个特定的表格和列数,它为我提供了总列数。 But when I do, table_name.getNumRows() , it says 0 .但是当我这样做时, table_name.getNumRows() ,它说0 Where as in my Data source, there are around 85 Rows .在我的数据源中,大约有85 Rows How can I get the rows from this table?如何从该表中获取行?

The code I have been using:我一直在使用的代码:

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

If you would like to get some data from a SAP BAPI it would help a lot also to call this BAPI.如果您想从 SAP BAPI 获取一些数据,调用此 BAPI 也会有很大帮助。 The data doesn't materialize automatically in the JCo objects out of thin air.数据不会凭空在 JCo 对象中自动实现。
In your code you do not execute any JCoFunction.在您的代码中,您不执行任何 JCoFunction。

Set the mandatory import parameter values for this BAPI (if there are any), execute the BAPI (your JCoFunction object) and then you will get the export data from the SAP system in response which will then also add appropriate rows to the JCoTable object.设置此 BAPI 的强制导入参数值(如果有),执行 BAPI(您的 JCoFunction 对象),然后您将从 SAP 系统获取导出数据作为响应,然后还将适当的行添加到 JCoTable 对象。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM