Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
98 views
in Technique[技术] by (71.8m points)

java - 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. 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.

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

System.out.println("RFC_GET_TABLE_ENTRIES");

for (int i = 0; i < 30; i++) {
    codes.setRow(i);
    System.out.println(codes.getString("WA"));
}
question from:https://stackoverflow.com/questions/65870683/how-to-read-a-specific-value-from-a-jcotable-object

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

getString actually accepts indexes as well. If you want to retrieve values according to x and y you can do the following

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.

In other cases, you may want to iterate through each single value in the row with 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
}

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...