【发布时间】:2019-02-15 07:22:34
【问题描述】:
我正在编写 Java 代码以使用 Java 连接器 (JCo) 从 SAP BAPI 获取数据。这是我第一次使用 JCo 连接到 SAP。我能够获得数据源中可用的表,还可以使用 table_name.getNumColumns() 获得一个特定的表和列数,这给了我列的总数。但是当我这样做时,table_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);
}
}
}
【问题讨论】:
-
如果可能,尝试在 SAP 端执行函数以验证返回的行数
-
嘿@DarkKnight 你的意思是使用ABAP执行吗?
-
是的,正是我想说的
-
当然@DarkKnight 我会试试的。感谢您的回复。
-
嗨@DarkKnight,我们已经使用ABAP 实现并且它正在工作。 IDK 为什么它不能在 Java 中工作。 :(