Search in sources :

Example 1 with JCoField

use of com.sap.conn.jco.JCoField in project JavaClasses by genexuslabs.

the class EnterpriseConnect method getValue.

/*        ---   Get Return Values  ---           */
public void getValue(String parameterName, GXSimpleCollection[] value) {
    if (value.length != 0) {
        GXSimpleCollection col = value[0];
        col.clear();
        JCoTable tbl = function.getTableParameterList().getTable(parameterName);
        JSONArray jCol = new JSONArray();
        try {
            for (int i = 0; i < tbl.getNumRows(); i++) {
                JSONObject jRow = new JSONObject();
                tbl.setRow(i);
                for (JCoField field : tbl) {
                    if (field.getType() == JCoMetaData.TYPE_INT || (field.getType() == JCoMetaData.TYPE_NUM && field.getDecimals() == 0)) {
                        jRow.put(field.getName(), field.getLong());
                    } else if (field.getType() == JCoMetaData.TYPE_INT2 || field.getType() == JCoMetaData.TYPE_INT1 || field.getType() == JCoMetaData.TYPE_BYTE) {
                        jRow.put(field.getName(), field.getInt());
                    } else if (field.getType() == JCoMetaData.TYPE_NUM || field.getType() == JCoMetaData.TYPE_FLOAT || field.getType() == JCoMetaData.TYPE_BCD) {
                        jRow.put(field.getName(), field.getDouble());
                    } else {
                        jRow.put(field.getName(), field.getString());
                    }
                }
                jCol.put(jRow);
            }
            col.FromJSONObject(jCol);
        } catch (JSONException ex) {
            throw new RuntimeException(ex.toString());
        }
    }
}
Also used : JSONObject(json.org.json.JSONObject) JCoTable(com.sap.conn.jco.JCoTable) GXSimpleCollection(com.genexus.GXSimpleCollection) JSONArray(json.org.json.JSONArray) JSONException(json.org.json.JSONException) JCoField(com.sap.conn.jco.JCoField)

Example 2 with JCoField

use of com.sap.conn.jco.JCoField in project JavaClasses by genexuslabs.

the class EnterpriseConnect method getValue.

public void getValue(String parameterName, IGxJSONAble[] value) {
    try {
        IGxJSONAble struct = value[0];
        JCoStructure jStruct = function.getExportParameterList().getStructure(parameterName);
        JSONObject jRow = new JSONObject();
        for (JCoField field : jStruct) {
            if (field.getType() == JCoMetaData.TYPE_NUM || field.getType() == JCoMetaData.TYPE_FLOAT || field.getType() == JCoMetaData.TYPE_BCD) {
                jRow.put(field.getName(), field.getDouble());
            } else {
                jRow.put(field.getName(), field.getString());
            }
        }
        struct.FromJSONObject(jRow);
    } catch (JSONException ex) {
        throw new RuntimeException(ex.toString());
    }
}
Also used : IGxJSONAble(com.genexus.internet.IGxJSONAble) JSONObject(json.org.json.JSONObject) JCoStructure(com.sap.conn.jco.JCoStructure) JSONException(json.org.json.JSONException) JCoField(com.sap.conn.jco.JCoField)

Aggregations

JCoField (com.sap.conn.jco.JCoField)2 JSONException (json.org.json.JSONException)2 JSONObject (json.org.json.JSONObject)2 GXSimpleCollection (com.genexus.GXSimpleCollection)1 IGxJSONAble (com.genexus.internet.IGxJSONAble)1 JCoStructure (com.sap.conn.jco.JCoStructure)1 JCoTable (com.sap.conn.jco.JCoTable)1 JSONArray (json.org.json.JSONArray)1