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 2: Remote persistent procedure example
 
Example 2: Remote persistent procedure example
The following code example shows how to instantiate a remote persistent procedure, order.p, on PAS for OpenEdge instance:
DEFINE VARIABLE hAppSrv   AS HANDLE NO-UNDO.
DEFINE VARIABLE hOrder    AS HANDLE NO-UNDO.
DEFINE VARIABLE iOrderNum AS 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.

CREATE SERVER hAppSrv.
lReturn = hAppSrv:CONNECT("-URL http://slater:OuterLimits64@zeus:8810/inventory/apsv",
                          "SMITH", "StarShip90").

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.

RUN GetExistingOrder IN hOrder
  (iOrderNum, OUTPUT TABLE ttOrder, OUTPUT TABLE ttOrderLine) NO-ERROR.
IF ERROR-STATUS:ERROR THEN DO:
  lReturn = hAppSrv:DISCONNECT().
  DELETE OBJECT hAppSrv NO-ERROR.
  RETURN ERROR RETURN-VALUE.
END.
. . .
lReturn = hAppSrv:DISCONNECT().
DELETE OBJECT hAppSrv NO-ERROR.
When the RUN statement for order.p completes, a reference to the persistent procedure context is saved in handle hOrder. The SERVER attribute for hOrder contains a reference to the server handle hAppSrv. When the internal procedure GetExistingOrder is run for persistent procedure hOrder, ABL uses the value of hAppSrv to determine the PAS for OpenEdge instance and session where the persistent procedure is located.