简体   繁体   English

如何从 JCoTable object 中读取特定值

[英]How to read a specific value from a JCoTable object

I successfully got the Table entries from a SAP system via RFC_GET_TABLE_ENTRIES .我通过RFC_GET_TABLE_ENTRIES从 SAP 系统成功获取了表条目。 It works all fine and lists me all the rows of the table.它工作得很好,并列出了表格的所有行。

My problem right now is that I have no idea how to get a single value out.我现在的问题是我不知道如何得到一个值。 Usually I would go like codes [x][y] but that doesn't work because it is not a normal two-dimensional-array table but a JCOtable and I have no idea how that works.通常我会 go 之类的代码[x][y]但这不起作用,因为它不是普通的二维数组表而是JCOtable ,我不知道它是如何工作的。

The code is a little longer but this is the call itself.代码有点长,但这是调用本身。

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

and this is the console output这是控制台 output

System.out.println("RFC_GET_TABLE_ENTRIES");

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

getString actually accepts indexes as well. getString实际上也接受索引。 If you want to retrieve values according to x and y you can do the following如果要根据 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

It works similarly to codes[x][y] as if it's an array, but this is not commonly used.它的工作方式类似于codes[x][y] ,就好像它是一个数组一样,但这并不常用。

In other cases, you may want to iterate through each single value in the row with JCoRecordFieldIterator .在其他情况下,您可能希望使用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
}

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

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