Progress
Programming
Handbook


Creating Persistent Procedures

To make an external procedure persistent, execute it using the PERSISTENT option of the RUN statement. This is an instantiating RUN statement, because it both executes the external procedure and creates a persistent instance of its context:

SYNTAX
RUN filename PERSISTENT [ SET handle ] [ run-options ] 

The filename and run-options are the same as for any external procedure (see the "External Procedures" section).

The handle is a field or variable defined with the HANDLE data type. The RUN statement sets handle to a procedure handle value that identifies the current context of the persistent procedure. You can use this procedure handle to invoke procedure triggers or internal procedures defined in the persistent procedure context. For information on procedure handles, see the "External Procedures" section.

For example, this code fragment creates two persistent procedures from db-tools.p and dde-tools.p, and assigns the procedure handles to hdbtools and hddetools, respectively:

DEFINE VARIABLE hdb-tools AS HANDLE. 
DEFINE VARIABLE hdde-tools AS HANDLE. 
DEFINE VARIABLE ldone AS LOGICAL INITIAL FALSE. 
DEFINE BUFFER cust-buf FOR customer. 
RUN db-tools.p PERSISTENT SET hdb-tools. 
RUN dde-tools.p PERSISTENT SET hdde-tools (INPUT "Customer Activity"). 
RUN get-first-customer IN hdb-tools (BUFFER cust-buf). 
DO WHILE NOT ldone: 
    RUN add-to-spread-sheet IN hdde-tools (BUFFER cust-buf). 
    RUN get-next-customer IN hdb-tools (BUFFER cust-buf, OUTPUT ldone). 
END. 

Assume that these two procedures interact with the sports database (db-tools.p) and a spreadsheet application using Windows Dynamic Data Exchange (DDE) (dde-tools.p). The fragment then runs the internal procedures within these persistent procedures to add customer information to a spreadsheet named Customer Activity. (For more information on using DDE, see the Progress External Program Interfaces manual.)

This application fragment shows how you can use persistent procedures to set up modular environments that encapsulate processing details from the rest of an application.


Copyright © 2004 Progress Software Corporation
www.progress.com
Voice: (781) 280-4000
Fax: (781) 280-4095