/** * ABAP APIs often uses complex parameters. This example demonstrates how to read the values from * a structure. * * @throws com.sap.conn.jco.JCoException */ public static void step3WorkWithStructure() throws JCoException { JCoDestination destination = JCoDestinationManager.getDestination(ABAP_AS_POOLED); JCoFunction function = destination.getRepository().getFunction("RFC_SYSTEM_INFO"); if (function == null) throw new RuntimeException("RFC_SYSTEM_INFO not found in SAP."); try { function.execute(destination); } catch (AbapException e) { System.out.println(e.toString()); return; } JCoStructure exportStructure = function.getExportParameterList().getStructure("RFCSI_EXPORT"); System.out.println("System info for " + destination.getAttributes().getSystemID() + ":\n"); // The structure contains some fields. The loop just prints out each field with its name. for (int i = 0; i < exportStructure.getMetaData().getFieldCount(); i++) { System.out.println( exportStructure.getMetaData().getName(i) + ":\t" + exportStructure.getString(i)); } System.out.println(); // JCo still supports the JCoFields, but direct access via getXXX is more efficient as field // iterator System.out.println( "The same using field iterator: \nSystem info for " + destination.getAttributes().getSystemID() + ":\n"); for (JCoField field : exportStructure) { System.out.println(field.getName() + ":\t" + field.getString()); } System.out.println(); }
public void run( Class object, Resource resource, IProgressMonitor monitor, Map<String, VCObject> seenObjects, List<Option> options) throws JCoException { beginTransaction(); JCoFunction function = getJCoFunction(getBAPI(), monitor); JCoParameterList ipl = function.getImportParameterList(); String classSpec = object.getName(); String className = VcmlUtils.getClassName(classSpec); int classType = VcmlUtils.getClassType(classSpec); // handleOptions(options, ipl, "???", "???"); ipl.setValue(getCLASSNUM(), className); ipl.setValue(getCLASSTYPE(), classType); JCoStructure classBasicDataNew = ipl.getStructure(getCLASSBASICDATA()); classBasicDataNew.setValue("STATUS", VcmlUtils.createIntFromStatus(object.getStatus())); classBasicDataNew.setValue("CLASSGROUP", nullIfEmpty(object.getGroup())); classBasicDataNew.setValue("VALID_FROM", getToday()); // TODO set VALID_FROM for classes? classBasicDataNew.setValue("VALID_TO", "9999-12-31"); // TODO set VALID_TO for classes? JCoParameterList tpl = function.getTableParameterList(); final JCoTable classDescriptionsNew = tpl.getTable(getCLASSDESCRIPTIONS()); new DescriptionHandler() { @Override public void handleSingleDescription(Language language, String value) { classDescriptionsNew.appendRow(); classDescriptionsNew.setValue("CATCHWORD", value); classDescriptionsNew.setValue("LANGU", VcmlUtils.getLanguageCharacter(language)); classDescriptionsNew.setValue("LANGU_ISO", language.toString()); } }.handleDescription(object.getDescription()); JCoTable classCharacteristicsNew = tpl.getTable(getCLASSCHARACTERISTICS()); List<Characteristic> cstics = object.getCharacteristics(); classCharacteristicsNew.appendRows(cstics.size()); for (Characteristic cstic : cstics) { classCharacteristicsNew.setValue("NAME_CHAR", cstic.getName()); classCharacteristicsNew.nextRow(); } execute(function, monitor, object.getName()); if (processReturnTable(function)) { commit(monitor); } endTransaction(); }
/** * A slightly more complex example than before. Query the companies list returned in a table and * then obtain more details for each company. * * @throws com.sap.conn.jco.JCoException */ public static void step4WorkWithTable() throws JCoException { JCoDestination destination = JCoDestinationManager.getDestination(ABAP_AS_POOLED); JCoFunction function = destination.getRepository().getFunction("BAPI_COMPANYCODE_GETLIST"); if (function == null) throw new RuntimeException("BAPI_COMPANYCODE_GETLIST not found in SAP."); try { function.execute(destination); } catch (AbapException e) { System.out.println(e.toString()); return; } JCoStructure returnStructure = function.getExportParameterList().getStructure("RETURN"); if (!(returnStructure.getString("TYPE").equals("") || returnStructure.getString("TYPE").equals("S"))) { throw new RuntimeException(returnStructure.getString("MESSAGE")); } JCoTable codes = function.getTableParameterList().getTable("COMPANYCODE_LIST"); for (int i = 0; i < codes.getNumRows(); i++) { codes.setRow(i); System.out.println(codes.getString("COMP_CODE") + '\t' + codes.getString("COMP_NAME")); } // move the table cursor to first row codes.firstRow(); for (int i = 0; i < codes.getNumRows(); i++, codes.nextRow()) { function = destination.getRepository().getFunction("BAPI_COMPANYCODE_GETDETAIL"); if (function == null) throw new RuntimeException("BAPI_COMPANYCODE_GETDETAIL not found in SAP."); function.getImportParameterList().setValue("COMPANYCODEID", codes.getString("COMP_CODE")); // We do not need the addresses, so set the corresponding parameter to inactive. // Inactive parameters will be either not generated or at least converted. function.getExportParameterList().setActive("COMPANYCODE_ADDRESS", false); try { function.execute(destination); } catch (AbapException e) { System.out.println(e.toString()); return; } returnStructure = function.getExportParameterList().getStructure("RETURN"); if (!(returnStructure.getString("TYPE").equals("") || returnStructure.getString("TYPE").equals("S") || returnStructure.getString("TYPE").equals("W"))) { throw new RuntimeException(returnStructure.getString("MESSAGE")); } JCoStructure detail = function.getExportParameterList().getStructure("COMPANYCODE_DETAIL"); System.out.println( detail.getString("COMP_CODE") + '\t' + detail.getString("COUNTRY") + '\t' + detail.getString("CITY")); } // for }