简体   繁体   中英

How to fix 'JCO_ERROR_CONVERSION: Cannot convert a value from type java.lang.String to STRUCTURE'

One of the functions we implemented in SAP is not working correctly. In SAP 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 for the Input Parameter "I_REZEPT" like int8 & 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 looks like this

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

expected was something like this

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

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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