Try OpenEdge Now
skip to main content
Application Migration and Development Guide
Application Development with PAS for OpenEdge : Programming ABL Client Applications : Running and managing remote procedures : Remote procedure code examples : Example 3: Remote persistent procedure example using the FUNCTION statement
 
Example 3: Remote persistent procedure example using the FUNCTION statement
This example shows how a client application invokes a user-defined function, GetExistingOrder, that is implemented remotely on a PAS for OpenEdge instance. It is presented as an alternative way to Example 2. The FUNCTION GetFirstOrder statement in the following example replaces the internal procedure GetExistingOrder referenced in Example 2:
DEFINE VARIABLE hAppSrv  AS HANDLE  NO-UNDO.
DEFINE VARIABLE hOrder   AS HANDLE  NO-UNDO.
DEFINE VARIABLE iCustNum LIKE Order.Order-Num NO-UNDO.
DEFINE VARIABLE lReturn  AS LOGICAL NO-UNDO.

DEFINE TEMP-TABLE ttOrder     LIKE Order.
DEFINE TEMP-TABLE ttOrderLine LIKE Order-Line.

FUNCTION GetFirstOrder RETURNS LOGICAL
  (INPUT piCustNum AS INTEGER,
   OUTPUT TABLE ttOrder,
   OUTPUT TABLE ttOrderLine) IN hOrder.

CREATE SERVER hAppSrv.
lReturn = hAppSrv:CONNECT("-URL http://slater:OuterLimits64@zeus:8810/inventory/apsv",
                          "SMITH", "StartShip90").
IF NOT lReturn THEN DO:
  DELETE OBJECT hAppSrv NO-ERROR.
  RETURN ERROR "Failed to connect to server".
END.
IF ERROR-STATUS:ERROR THEN DO:
  DELETE OBJECT hAppSrv NO-ERROR.
  RETURN ERROR RETURN-VALUE.
END.
. . .
RUN order.p ON hAppSrv TRANSACTION DISTINCT PERSISTENT SET hOrder.
IF NOT GetFirstOrder (INPUT iCustNum, OUTPUT TABLE ttOrder,
                      OUTPUT TABLE ttOrderLine) THEN DO:
  lReturn = hAppSrv:DISCONNECT().
  DELETE OBJECT hAppSrv NO-ERROR.
  RETURN ERROR.
END.
. . .
lReturn = hAppSrv:DISCONNECT().
DELETE OBJECT hAppSrv NO-ERROR.
Like Example 2, when the RUN statement for order.p completes, a reference to the persistent procedure context is saved in handle hOrder, and the SERVER attribute for hOrder contains a reference to the server handle hAppSrv. However, instead of running an internal procedure, it runs the user-defined function, GetFirstOrder.
For more information about creating user-defined functions, see the FUNCTION Statement section in OpenEdge Development: ABL Reference.
Note: If a client application exits without executing the DISCONNECT( ) method on the appropriate handles, OpenEdge automatically disconnects the client from the server. This automatic disconnection can also occur if the server machine looses network connectivity with the client application. This can happen, for example, if there is a network failure.