use of com.sap.conn.jco.JCoTable in project Clownfish by rawdog71.
the class SAPUtility method getSapExport.
/*
getSapExport
Übergibt die POST Parameter und ruft SAP RFC auf
Setzt die Ergebnisse in eine Hashmap zur Ausgabe in Freemarker
*/
public static HashMap<String, HashMap> getSapExport(List<CfSitesaprfc> sitesaprfclist, HashMap<String, List> saprfcfunctionparamMap, List<JsonFormParameter> postmap, RPY_TABLE_READ rpytableread) {
JCoTable functions_table = null;
HashMap<String, HashMap> sapexport = new HashMap<>();
for (CfSitesaprfc cfsitesaprfc : sitesaprfclist) {
try {
HashMap<String, Object> sapvalues = new HashMap<>();
List<RfcFunctionParam> paramlist = saprfcfunctionparamMap.get(cfsitesaprfc.getCfSitesaprfcPK().getRfcfunction());
// Setze die Import Parameter des SAP RFC mit den Werten aus den POST Parametern
JCoFunction function = sapc.getDestination().getRepository().getFunction(cfsitesaprfc.getCfSitesaprfcPK().getRfcfunction());
for (RfcFunctionParam rfcfunctionparam : paramlist) {
if (rfcfunctionparam.getParamclass().compareToIgnoreCase("I") == 0) {
if (null != postmap) {
for (JsonFormParameter jfp : postmap) {
if (jfp.getName().compareToIgnoreCase(rfcfunctionparam.getParameter()) == 0) {
function.getImportParameterList().setValue(rfcfunctionparam.getParameter(), jfp.getValue());
}
}
}
}
}
// SAP RFC ausführen
function.execute(sapc.getDestination());
HashMap<String, ArrayList> saptables = new HashMap<>();
for (RfcFunctionParam rfcfunctionparam : paramlist) {
String tablename = rfcfunctionparam.getTabname();
String paramname = rfcfunctionparam.getParameter();
if (rfcfunctionparam.getParamclass().compareToIgnoreCase("E") == 0) {
sapvalues.put(rfcfunctionparam.getParameter(), function.getExportParameterList().getString(rfcfunctionparam.getParameter()));
}
if (rfcfunctionparam.getParamclass().compareToIgnoreCase("T") == 0) {
ArrayList<HashMap> tablevalues = new ArrayList<>();
functions_table = function.getTableParameterList().getTable(paramname);
List<RpyTableRead> rpytablereadlist = rpytableread.getRpyTableReadList(tablename);
for (int i = 0; i < functions_table.getNumRows(); i++) {
HashMap<String, String> sapexportvalues = new HashMap<>();
functions_table.setRow(i);
for (RpyTableRead rpytablereadentry : rpytablereadlist) {
if ((rpytablereadentry.getDatatype().compareToIgnoreCase(SAPDATATYPE.CHAR) == 0) || (rpytablereadentry.getDatatype().compareToIgnoreCase(SAPDATATYPE.NUMC) == 0) || (rpytablereadentry.getDatatype().compareToIgnoreCase(SAPDATATYPE.UNIT) == 0)) {
String value = functions_table.getString(rpytablereadentry.getFieldname());
sapexportvalues.put(rpytablereadentry.getFieldname(), value);
continue;
}
if ((rpytablereadentry.getDatatype().compareToIgnoreCase(SAPDATATYPE.DATS) == 0) || (rpytablereadentry.getDatatype().compareToIgnoreCase(SAPDATATYPE.TIMS) == 0)) {
Date value = functions_table.getDate(rpytablereadentry.getFieldname());
String datum = "";
if (null != value) {
if (rpytablereadentry.getDatatype().compareToIgnoreCase(SAPDATATYPE.DATS) == 0) {
SimpleDateFormat sdf = new SimpleDateFormat("dd.MM.yyyy");
datum = sdf.format(value);
} else {
SimpleDateFormat sdf = new SimpleDateFormat("HH:mm:ss");
datum = sdf.format(value);
}
}
sapexportvalues.put(rpytablereadentry.getFieldname(), datum);
continue;
}
if (rpytablereadentry.getDatatype().compareToIgnoreCase(SAPDATATYPE.QUAN) == 0) {
double value = functions_table.getDouble(rpytablereadentry.getFieldname());
sapexportvalues.put(rpytablereadentry.getFieldname(), String.valueOf(value));
continue;
}
if ((rpytablereadentry.getDatatype().compareToIgnoreCase(SAPDATATYPE.INT1) == 0) || (rpytablereadentry.getDatatype().compareToIgnoreCase(SAPDATATYPE.INT2) == 0) || (rpytablereadentry.getDatatype().compareToIgnoreCase(SAPDATATYPE.INT4) == 0) || (rpytablereadentry.getDatatype().compareToIgnoreCase(SAPDATATYPE.INT8) == 0)) {
int value = functions_table.getInt(rpytablereadentry.getFieldname());
sapexportvalues.put(rpytablereadentry.getFieldname(), String.valueOf(value));
}
}
tablevalues.add(sapexportvalues);
}
saptables.put(paramname, tablevalues);
}
}
sapvalues.put("table", saptables);
sapexport.put(cfsitesaprfc.getCfSitesaprfcPK().getRfcfunction(), sapvalues);
} catch (JCoException ex) {
LOGGER.error(ex.getMessage());
}
}
return sapexport;
}
use of com.sap.conn.jco.JCoTable in project bonita-connector-sap by bonitasoft.
the class SAPCallFunction method fillJCOTableParameterList.
@SuppressWarnings("unchecked")
private JCoParameterList fillJCOTableParameterList() throws ConnectorException {
final JCoParameterList tableParameterList = function.getTableParameterList();
final List<List<Object>> inputParameters = (List<List<Object>>) getInputParameter(INPUT_PARAMETERS);
if (inputParameters != null) {
final JCoParameterList inputParameterList = function.getImportParameterList();
for (List<Object> column : inputParameters) {
final String parameterType = (String) column.get(0);
final String tableName = (String) column.get(1);
final String parameterName = (String) column.get(2);
final Object parameterValue = column.get(3);
if (INPUT_STRUCTURE.equals(parameterType)) {
if (inputParameterList == null) {
throw new ConnectorException("input_structure is not a supported input type for parameter '" + parameterName + "' of table '" + tableName + "'");
}
final JCoStructure structure = inputParameterList.getStructure(tableName);
if (structure == null) {
throw new ConnectorException("input_structure is not a supported input type for parameter '" + parameterName + "' of table '" + tableName + "'");
}
structure.setValue(parameterName, parameterValue);
} else if (INPUT_SINGLE.equals(parameterType)) {
if (inputParameterList == null) {
throw new ConnectorException("input_single is not a supported input type for parameter '" + parameterName + "' of table '" + tableName + "'");
}
inputParameterList.setValue(parameterName, parameterValue);
} else {
// INPUT_TABLE or TABLE_INPUT
List<Object> list = new ArrayList<>();
if (parameterValue instanceof List<?>) {
list.addAll((List<Object>) parameterValue);
} else {
list.add(parameterValue);
}
int rowSize = list.size();
JCoTable table = null;
if (INPUT_TABLE.equals(parameterType)) {
if (inputParameterList == null) {
throw new ConnectorException("input_table is not a supported input type for parameter '" + parameterName + "' of table '" + tableName + "'");
}
table = inputParameterList.getTable(tableName);
} else if (TABLE_INPUT.equals(parameterType)) {
if (tableParameterList == null) {
throw new ConnectorException("table_input is not a supported input type for parameter '" + parameterName + "' of table '" + tableName + "'");
}
table = tableParameterList.getTable(tableName);
}
if (table != null) {
table.firstRow();
for (int rowNb = 0; rowNb < rowSize; rowNb++) {
if (table.getNumRows() < (rowNb + 1)) {
table.appendRow();
}
table.setValue(parameterName, list.get(rowNb));
table.nextRow();
}
}
}
}
}
return tableParameterList;
}
use of com.sap.conn.jco.JCoTable 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());
}
}
}
use of com.sap.conn.jco.JCoTable in project bonita-connector-sap by bonitasoft.
the class SAPCallFunction method retrieveTableVariableValue.
private Serializable retrieveTableVariableValue(final JCoParameterList tableParameterList, final JCoParameterList outputParameterList, final String parameterType, final String tableName, final String xpath) {
Serializable variableValue;
JCoTable table = null;
if (OUTPUT_TABLE.equals(parameterType)) {
table = outputParameterList.getTable(tableName);
} else if (TABLE_OUTPUT.equals(parameterType)) {
table = tableParameterList.getTable(tableName);
}
ArrayList<String> list = new ArrayList<>();
if (table != null) {
boolean hasMoreElements = !table.isEmpty();
while (hasMoreElements) {
list.add(table.getString(xpath));
if (table.isLastRow()) {
hasMoreElements = false;
} else {
table.nextRow();
}
}
}
if (list.isEmpty()) {
variableValue = null;
} else if (list.size() == 1) {
variableValue = list.get(0);
} else {
variableValue = list;
}
return variableValue;
}
use of com.sap.conn.jco.JCoTable in project JavaClasses by genexuslabs.
the class EnterpriseConnect method setValue.
public void setValue(String parameterName, GXSimpleCollection value, Boolean inOut) {
JCoTable jTable = function.getTableParameterList().getTable(parameterName);
Boolean setValues = false;
try {
for (int i = 1; i <= value.getItemCount(); i++) {
IGxJSONAble item = (IGxJSONAble) value.item(i);
if (item != null) {
setValues = true;
JSONObject jObj = (JSONObject) item.GetJSONObject();
jTable.appendRow();
jTable.lastRow();
Iterator<?> keys = jObj.keys();
while (keys.hasNext()) {
String key = (String) keys.next();
int jcoType = jTable.getRecordMetaData().getType(key);
if (jObj.get(key) instanceof String) {
jTable.setValue(key, jObj.getString(key));
} else if (jcoType == JCoMetaData.TYPE_NUM || jcoType == JCoMetaData.TYPE_INT) {
jTable.setValue(key, jObj.getLong(key));
} else if (jcoType == JCoMetaData.TYPE_FLOAT || jcoType == JCoMetaData.TYPE_BCD) {
jTable.setValue(key, jObj.getDouble(key));
} else if (jcoType == JCoMetaData.TYPE_DATE) {
jTable.setValue(key, jObj.getString(key));
} else if (jcoType == JCoMetaData.TYPE_INT2 || jcoType == JCoMetaData.TYPE_INT1 || jcoType == JCoMetaData.TYPE_BYTE) {
jTable.setValue(key, jObj.getInt(key));
} else {
System.out.println(key + " Invalid Type " + Integer.toString(jcoType));
}
}
}
}
} catch (JSONException ex) {
throw new RuntimeException(ex.toString());
}
if (setValues) {
function.getTableParameterList().setActive(parameterName, true);
} else {
function.getTableParameterList().setActive(parameterName, inOut);
}
}
Aggregations