Try OpenEdge Now
skip to main content
Java Open Clients
Using the Open Client Java OpenAPI to Directly Access the AppServer : Sample Java OpenAPI code : Persistent procedure example
 

Persistent procedure example

Suppose you want to run a persistent procedure, CustomerOrder.p, with the following definition, containing a user-defined function.

Persistent procedure ABL for the OpenAPI

DEFINE INPUT PARAMETER custNum AS INTEGER NO-UNDO.
...

FUNCTION GetTotalOrdersByNumber RETURNS INTEGER (threshold AS DECIMAL):
...
END.
...
You might write the following client code to run it.

OpenAPI code to run the persistent procedure

import com.progress.open4gl.javaproxy.*;
import com.progress.open4gl.Parameter;

public class sampleClient
{  private static final java.lang.String tName = new String( "KM_client" );
  public static void persistentProcedure()
  {
    try  // To catch all exceptions
    {
      // Connect to the AppServer
      Connection myConn = new Connection("","","");
      OpenAppObject dynAO = new OpenAppObject(myConn, "asbroker2");

      // Run the persistent Procedure
      // First set up parameters
      ParamArray parms = new ParamArray(1);
      int custNum = 3;

      // Set up input parameters
      parms.addInteger(0, custNum, ParamArrayMode.INPUT);

      // Run procedure
      OpenProcObject dynPO = dynAO.createPO("OrderInfo/CustomerOrder.p",
                                            parms);
      // Call UDF
      // First set up parameters
      Integer retVal;
      java.math.BigDecimal threshold = new java.math.BigDecimal(1000);
      parms.clear(); // Clear for reuse

      // Set up input parameters
      parms.addDecimal(0, threshold, ParamArrayMode.INPUT);

      // Set up return type
      parms.setReturnType(Parameter.PRO_INTEGER);

      // Run procedure
      dynPO.runProc("GetTotalOrdersByNumber", parms);

      // Get return value
      retVal = (Integer)(parms.getReturnValue());

      dynPO._release();
      dynAO._release();
    } // try to catch all unexpected exceptions
    catch ( Exception e )
    {
        System.out.println("Exception in sample2()");
        System.out.println("Exception Message: " + e.getMessage());
        e.printStackTrace();
    }
  }
} // class