/** * 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(); }
/** * This example demonstrates the destination concept introduced with JCO 3. The application does * not deal with single connections anymore. Instead it works with logical destinations like * ABAP_AS and ABAP_MS which separates the application logic from technical configuration. * * @throws com.sap.conn.jco.JCoException */ public static void step1Connect() throws JCoException { JCoDestination destination = JCoDestinationManager.getDestination(ABAP_AS); System.out.println("Attributes:"); System.out.println(destination.getAttributes()); System.out.println(); destination = JCoDestinationManager.getDestination(ABAP_MS); System.out.println("Attributes:"); System.out.println(destination.getAttributes()); System.out.println(); }
/** * This example uses a connection pool. However, the implementation of the application logic is * still the same. Creation of pools and pool management are handled by the JCo runtime. * * @throws com.sap.conn.jco.JCoException */ public static void step2ConnectUsingPool() throws JCoException { JCoDestination destination = JCoDestinationManager.getDestination(ABAP_AS_POOLED); destination.ping(); System.out.println("Attributes:"); System.out.println(destination.getAttributes()); System.out.println(); }