Im folgenden Beispiel wird eine Funktion durch Aufruf eines Funktionsbausteins ausgeführt und auf eine Struktur zugegriffen.
Beispiel:
Sie wollen die Funktionen STFC_CONNECTION und RFC_SYSTEM_INFO aufrufen.
...
1. Rufen Sie eine Destination und die entprechende Funktion auf.
2. Alle Parameter einer Funktion können durch die Methoden getImportParameterList(), getExportParameterList() und getTableParameterList() aufgerufen werden.
3. Die Methode getStructure() ermöglicht den Zugriff auf einen beliebigen Strukturparameter in einer Import- oder Exportparameterliste.
Einfache Funktion ausführen
public static void step3SimpleCall() throws JCoException{JCoDestination destination = JCoDestinationManager.getDestination(DESTINATION_NAME2);JCoFunction function = destination.getRepository().getFunction("STFC_CONNECTION");if(function == null)throw new RuntimeException("STFC_CONNECTION not found in SAP.");function.getImportParameterList().setValue("REQUTEXT", "Hello SAP");try{function.execute(destination);}catch(AbapException e){System.out.println(e.toString());return;}System.out.println("STFC_CONNECTION finished:");System.out.println(" Echo: " + function.getExportParameterList().getString("ECHOTEXT"));System.out.println(" Response: " + function.getExportParameterList().getString("RESPTEXT"));System.out.println();} |
public static void step3WorkWithStructure() throws JCoException { JCoDestination destination = JCoDestinationManager.getDestination(DESTINATION_NAME2); 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"); 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 getXX 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(); } |