Progress
Programming
Handbook


Sharing Streams Among Procedures

In some cases, you might want two or more procedures to share the same input or output streams. The following procedures, p-sstrm.p and p-dispho.p, share the same output stream, phonelist. Notice that phonelist is defined as a shared stream in both procedures:

p-sstrm.p
DEFINE NEW SHARED BUFFER xrep FOR salesrep. 
DEFINE NEW SHARED STREAM phonelist. 
OUTPUT STREAM phonelist TO phonefile. 
PAUSE 2 BEFORE-HIDE. 
FOR EACH xrep: 
  DISPLAY xrep WITH FRAME repname 
    TITLE "Creating report for " 2 COLUMNS CENTERED ROW 10. 
  DISPLAY STREAM phonelist xrep WITH 2 COLUMNS STREAM-IO. 
  RUN p-dispho.p. 
END. 

The p-sstrm.p procedure defines a NEW SHARED STREAM called phonelist. The procedure sends the output from the phonelist stream to a file called phonefile. The procedure also calls the p-dispho.p procedure:

p-dispho.p
DEFINE SHARED BUFFER xrep FOR salesrep. 
DEFINE SHARED STREAM phonelist. 
FOR EACH customer OF xrep BY state: 
  DISPLAY STREAM phonelist cust-num name city state phone 
          WITH NO-LABELS STREAM-IO. 
END. 

The p-dispho.p procedure defines the SHARED STREAM phonelist, and displays the information from that stream on the screen. (It is more efficient to place the FOR EACH and DISPLAY statements in the p-sstrm.p procedure. They are in a separate procedure here to illustrate shared streams.)

NOTE: You cannot define or access shared streams in a persistent procedure. If you do, Progress returns a run-time error when you create the persistent procedure. For more information, see the sections on persistent procedures in Block Properties."

Sharing streams is much like sharing variables:


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