baxbear
baxbear

Reputation: 890

How to evaluate a JCoStructure?

I have the following structure:

|----------|----------|----|---|
| STRUCTURE 'NameOfStructur'   |
|----------|----------|----|---|
|Num       |A         |B   |C  |
|----------|----------|----|---|
|0123456789|0123456789|0123|456|
|----------|----------|----|---|
|          |          |    |   |
|----------|----------|----|---|

which I print with:

JCoStructure struct = exportParameters.getStructure(paramName);
System.out.println(struct.toString());

and with:

JCoStructure struct = exportParameters.getStructure(paramName);

JCoFieldIterator fieldIt = struct.getFieldIterator();

while (fieldIt.hasNextField()) {
    JCoField field = fieldIt.nextField();
    System.out.println(field.getName());
}

I receive the attribute names (Num, A, B, C) but I am still not able to get the values from this struct. field.getValue() just returns null and field.toString() delivers an object reference value.

Does anybody know how to receive this values?

Upvotes: 1

Views: 1028

Answers (2)

baxbear
baxbear

Reputation: 890

Answer is simple,

|0123456789|0123456789|0123|456|

is just like a parting line on every "empty" and non empty table/structure when printing it with "toString()". Thought this are entries on our test-sap-system. So it is completly correct, that I will receive for every entry a "null" because these datastructures are empty yet.

So basically @Trixx is completly right about how to retrieve values from JCoStructures/JCoFields but my problem wasn't that I was not able to retrieve the correct methods from the documentation but that it wasn't documented that the line that was printed out was a separation line and not as I thought a tuple of example data.

Upvotes: -1

Trixx
Trixx

Reputation: 1885

JCoField.getName() gets the field's name and for the field's value use an appropriate getter-method, e.g. JCoField.getString() should always work. If feasible, other getter-methods will do a type conversion on-the-fly, e.g. JCoField.getInt() will work and return a primitive int 623521, if the field contains the string "623521" as a value.

In your example, all the fields in the structure are currently empty, so JCoField.getString() will return "".

By the way, you do not need to use the field iterator. You can also directly access the field values from the JCoStructure by using the field's name or its index, e.g. use JCoStructure.getString("Num") or JCoStructure.getString(0).

Upvotes: 4

Related Questions