首页 > 解决方案 > 如何从 JCoTable 对象中读取特定值

问题描述

我通过RFC_GET_TABLE_ENTRIES. 它工作得很好,并列出了表格的所有行。

我现在的问题是我不知道如何得到一个值。通常我会喜欢代码[x][y],但这不起作用,因为它不是一个普通的二维数组表,而是一个JCOtable,我不知道它是如何工作的。

代码有点长,但这是调用本身。

JCoDestination destination = JCoDestinationManager.getDestination("mySAPSystem");
JCoFunction function = destination.getRepository().getFunction("RFC_GET_TABLE_ENTRIES");



if (function==null)
    throw new RuntimeException("Function not found in SAP.");

function.getImportParameterList().setValue( "MAX_ENTRIES", 30);
function.getImportParameterList().setValue( "TABLE_NAME", "ZTEST_TABLE ");
JCoTable codes = function.getTableParameterList().getTable("ENTRIES");
codes.appendRow();

这是控制台输出

System.out.println("RFC_GET_TABLE_ENTRIES");

for (int i = 0; i < 30; i++) {
    codes.setRow(i);
    System.out.println(codes.getString("WA"));
}

标签: javajco

解决方案


getString实际上也接受索引。如果要根据 x 和 y 检索值,可以执行以下操作

codes.setRow(y);
String value = codes.getString(x); // It can also be getFloat, getInt, etc. depending on the data type,
                                   // or getValue, which gives you an Object

它的工作方式与数组类似codes[x][y],但这并不常用。

在其他情况下,您可能希望使用 遍历行中的每个单个值JCoRecordFieldIterator

JCoRecordFieldIterator itr = codes. getRecordFieldIterator();
while(itr.hasNextField()){
    JCoRecordField field = itr.nextRecordField();
    String value = field.getValue(); // Or getString, getFloat, etc.
    // Whatever you want to do with the value
}

推荐阅读