1

One of the functions we implemented in SAP system is not working correctly. In SAP system all functions are working correctly and return the right values, however, when called in Java JCo the Client wants a structure rather than a String or int.

When extracting the structure from the Parameter it gives a Structure that has two unnamed columns each with no lengths of Bytes to be filled in.

Metadata:
{[],[]}
0,0

We tried different datatypes in SAP system for the Input Parameter "I_REZEPT" like int8 and char12

private String sollwerte(JSONObject jsonin) throws JSONException, JCoException {
String id = String.valueOf(jsonin.getInt("rezeptid"));
JCoStructure in = input.getStructure("I_REZEPT");
System.out.println("Fieldcount:"+in.getFieldCount());
input.setValue("I_REZEPT", id);
e.printStackTrace();
function.execute(destination);
...

Stacktrace:

com.sap.conn.jco.ConversionException: (122) JCO_ERROR_CONVERSION: Cannot convert a value of '1' from type java.lang.String to STRUCTURE at field I_REZEPT
  at com.sap.conn.jco.rt.AbstractRecord.createConversionException(AbstractRecord.java:436)
  at com.sap.conn.jco.rt.AbstractRecord.createConversionException(AbstractRecord.java:430)
  at com.sap.conn.jco.rt.AbstractRecord.setValue(AbstractRecord.java:2824)
  at com.sap.conn.jco.rt.AbstractRecord.setValue(AbstractRecord.java:3933)
  at edu.hsalbsig.intellifarm.connector.sap.IntellifarmSapFunction.sollwerte(IntellifarmSapFunction.java:226)
  at edu.hsalbsig.intellifarm.connector.sap.IntellifarmSapFunction.execute(IntellifarmSapFunction.java:61)
  at edu.hsalbsig.intellifarm.connector.mqtt.IntellifarmMqttClient.messageArrived(IntellifarmMqttClient.java:98)
  at org.eclipse.paho.client.mqttv3.internal.CommsCallback.deliverMessage(CommsCallback.java:513)
  at org.eclipse.paho.client.mqttv3.internal.CommsCallback.handleMessage(CommsCallback.java:416)
  at org.eclipse.paho.client.mqttv3.internal.CommsCallback.run(CommsCallback.java:213)
  at java.base/java.lang.Thread.run(Thread.java:834)

While debugging the function from SAP system, it looks like this

Input:
|--------|
| PARAMETERS 'INPUT'
|--------|
|I_REZEPT|
|--------|
|        |
|--------|
|I_REZEPT|
|--------|

expected was something like this

Input:
|------------------|
| PARAMETERS 'INPUT'
|------------------|
|I_REZEPT          |
|------------------|
|012345678901234567|
|------------------|
|                  |
|------------------|
Sandra Rossi
  • 11,934
  • 5
  • 22
  • 48
Kanvas
  • 31
  • 4
  • Hi! Welcome to Stack Overflow! Have you taken the [tour](https://stackoverflow.com/tour) yet? Also, please make sure you read [How to create a Minimal, Complete, and Verifiable example](https://stackoverflow.com/help/mcve) and [How do I ask a good question?](https://stackoverflow.com/help/how-to-ask), so you can improve your question. Right now, it is not very clear as to what you are trying to achieve and what your question is. – Soutzikevich Jun 05 '19 at 22:09

1 Answers1

0

Without knowing your function interface definition from ABAP side it is difficult to help here. But if input.getStructure("I_REZEPT"); works this import parameter I_REZEPT seems to be structure. Therefore you cannot call input.setValue("I_REZEPT", (String)id); with trying to set a string for it and this is what the exception is showing. I_REZEPT is an IMPORT parameter and is of type STRUCTURE, it is not a STRING or a CHAR type parameter. It contains various other fields - at least one.

Instead of this, I guess you may call in.setValue(0, id); for setting the first field of this structure or in.setValue("FIELDNAME", id); with using the correct field name within the structure.

Trixx
  • 1,796
  • 1
  • 15
  • 18
  • Thanks for the fast reply. I forgot to mention, that I already tried to extract the structure. The result was a structure with 2 not fillable columns with no names. Filling the structure proved to me to be futile. From what I see in the SAP Dashboard is the type of the Import Variable was declared as CHAR12. – Kanvas Jun 06 '19 at 21:23
  • A structure contains 1 or more fields where each field can also be another (nested) structure again or even a table. You can see and browse the structure with transaction SE37 and double-clicking on the elements in the SAP GUI. Please also note the differences between `input` and `in` in my previous reply. – Trixx Jun 06 '19 at 21:40
  • And if you want to play around with the structures and meta data in Java also have a look at methods `toXML()`, `getListMetaData()` and `getRecordMetaData()`. – Trixx Jun 06 '19 at 21:46