Example 1: Remote non-persistent procedure example
This example shows how to run a remote, non-persistent procedure, checkstk.p, on an AppServer identified as hAppSrv. The TRANSACTION DISTINCT option is used on the RUN statement to specify that the client application's transaction is not propagated to hAppSrv. The two temp-table parameters that are defined, ttOrderLine and ttItem, are passed as INPUT and OUTPUT parameters, respectively, to the checkstk.p procedure, as shown:
DEFINE VARIABLE hAppSrv AS HANDLE NO-UNDO.
DEFINE VARIABLE lReturn AS LOGICAL NO-UNDO.
DEFINE TEMP-TABLE ttOrderLine LIKE Order-Line.
DEFINE TEMP-TABLE ttItem LIKE Item.
CREATE SERVER hAppSrv.
lReturn = hAppSrv:CONNECT("-AppService inventory -S 5162 -H zeus",
"SMITH", "STARSHIP").
IF NOT lReturn THEN DO:
DELETE OBJECT hAppSrv NO-ERROR.
RETURN ERROR "Failed to connect to AppServer".
END.
IF ERROR-STATUS:ERROR THEN DO:
DELETE OBJECT hAppSrv NO-ERROR.
RETURN ERROR RETURN-VALUE.
END.
. . .
RUN checkstk.p ON hAppSrv TRANSACTION DISTINCT (Customer.Cust-Num, TABLE ttOrderLine,OUTPUT TABLE ttItem) 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 is executed, a remote procedure request to run checkstk.p is sent to the AppServer instance that is connected via the hAppSrv server handle. Once the RUN statement is completed, this code checks to see if checkstk.p completed with an ERROR condition as would occur by executing the RETURN ERROR statement. If checkstk.p did execute the RETURN ERROR statement, then this code also returns with an ERROR condition. By using the RETURN-VALUE function, the code also returns the value returned by checkstk.p.