Try OpenEdge Now
skip to main content
Developing AppServer Applications
Programming ABL Client Applications : Managing asynchronous requests : Examples : A complete asynchronous request example
 
A complete asynchronous request example
In the following example, the ABL client procedure, client.p, calls server.p (following) asynchronously on an AppServer. The server.p procedure returns the customer number corresponding to a customer name provided by client.p.
The client.p procedure blocks and waits for the PROCEDURE-COMPLETE event that triggers execution of the GetCustNum event procedure. The GetCustNum procedure displays the result and deletes the corresponding asynchronous request handle (referenced by the SELF system handle).
In a more typical example, additional event handlers (triggers) would be active for user-interface events, allowing the user of client.p to perform other tasks with the procedure while completion of the request is pending. In this case, the client application blocks immediately after submitting the request to wait for the result and terminate on the PROCEDURE-COMPLETE event.

client.p

DEFINE VARIABLE cCustomer AS CHARACTER NO-UNDO INITIAL "WILNER".
DEFINE VARIABLE hRequest  AS HANDLE    NO-UNDO.
DEFINE VARIABLE hServer   AS HANDLE    NO-UNDO.
DEFINE VARIABLE lReturn   AS LOGICAL   NO-UNDO.

CREATE SERVER hServer.
lReturn = hServer:CONNECT("-S 5162 -H zeus -AppService Inventory").

RUN server.p ON hServer ASYNCHRONOUS SET hRequest
  EVENT-PROCEDURE "GetCustNum"
  (INPUT cCustomer, OUTPUT iCustomer AS INTEGER).

WAIT-FOR PROCEDURE-COMPLETE OF hRequest.

DELETE OBJECT hRequest NO-ERROR.
hServer:DISCONNECT().
DELETE OBJECT hServer NO-ERROR.

PROCEDURE GetCustNum:
  DEFINE INPUT PARAMETER piCustomer AS INTEGER NO-UNDO.

  DISPLAY piCustomer.
END.

server.p

DEFINE INPUT  PARAMETER pcCustomer AS CHARACTER NO-UNDO.
DEFINE OUTPUT PARAMETER piCustomer AS INTEGER   NO-UNDO.

FOR FIRST customer WHERE customer.name = pcCustomer NO-LOCK:
  piCustomer = customer.cust-num.
END.