Start of Content Area

Procedure documentation Executing Functions  Locate the document in its SAP Library structure

In the following example a function is executed by calling a function module and a structure is accessed.

 

Example

Example:

You want to call functions STFC_CONNECTIONand RFC_SYSTEM_INFO.

...

       1.      You call a destination and the corresponding function.

       2.      All function parameters can be called using the methods getImportParameterList(), getExportParameterList(), and getTableParameterList().

       3.      The method getStructure() facilitates access to any structure parameter in an import or export parameter list.

       4.       

 Syntax Executing Simple Functions

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("BAPI_COMPANYCODE_GETLIST 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 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();
    }
 
Syntax Accessing a Structure

 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();

    }

More Information

      Starting SAP GUI

 

End of Content Area