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 : Non-persistent procedure example
 

Non-persistent procedure example

Suppose you want to run a non-persistent procedure, AddCustomer.p, with the following definition.

Non-persistent procedure ABL for the OpenAPI

DEFINE INPUT PARAMETER CustName AS CHARACTER.
DEFINE INPUT PARAMETER phone AS CHARACTER.
DEFINE INPUT PARAMETER email AS CHARACTER.
DEFINE OUTPUT PARAMETER CustomerNumber AS INTEGER.
You might write the following client code to run it.

OpenAPI code to run the non-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 nonPersistentProcedure()
  {
    try  // To catch all exceptions
    {
      // Connect to the AppServer
      Connection myConn = new Connection("","","");
      OpenAppObject dynAO = new OpenAppObject(myConn, "asbroker2");

      // Create the parameters
      String CustName = "abc";
      String phone = "999-555-1234";
      String email = "me@foo.com";

      Integer CustomerNumber;

      // Create a place for RETURN-VALUE
      String retVal;

      // Create the ParamArray
      ParamArray parms = new ParamArray(4);

      // Set up input parameters
      parms.addCharacter(0, CustName, ParamArrayMode.INPUT);
      parms.addCharacter(1, phone, ParamArrayMode.INPUT);
      parms.addCharacter(2, email, ParamArrayMode.INPUT);

      // Set up Out parameters - notice the value is null
      parms.addInteger(3, null, ParamArrayMode.OUTPUT);

      // Run the procedure
      dynAO.runProc("AddCustomer.p", parms);

      // Get output parameters - Returned as Object, so must cast
      CustomerNumber = (Integer) parms.getOutputParameter(3);

      // Get RETURN-VALUE - Will return null for AddCustomer() procedure
      retVal = (String)(parms.getProcReturnString());
      dynAO._release();

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