Use the SHARED parameter of the DEFINE STREAM statement to create a shared stream.
Note: You cannot define or access shared streams in a persistent procedure or in a class file. You can access streams defined in persistent procedures or class files by using stream object handles. See Usingstream object handles for more information.
For example, the procedures i-sstrm.p and i-dispho.p share the same output stream, phonelist. Notice that phonelist is defined as a shared stream in both procedures.
i-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 i-dispho.p.
END.
The i-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 i-dispho.p procedure.
i-dispho.p
DEFINE SHARED BUFFER xrep FOR salesrep.
DEFINE SHARED STREAM phonelist.
FOR EACH Customer OF xrep NO-LOCK BY Customer.State:
DISPLAY STREAM phonelist Customer.CustNum Customer.Name Customer.City
Customer.State Customer.Phone
WITH NO-LABELS STREAM-IO.
END.
The i-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 i-sstrm.p procedure. They are in a separate procedure here to illustrate shared streams.)
Sharing streams is much like sharing variables because:
You use a regular DEFINE STREAM statement to define a stream that is available only to the current procedure.
To define a shared stream, you define the stream as NEW SHARED in the procedure that creates the stream, and as SHARED in all other procedures that use that stream. If you do not explicitly close the stream, ABL closes it automatically at the end of the procedure in which you defined it.
You define the stream as NEW GLOBAL when you want that stream to remain available even after the procedure that contains the DEFINE NEW GLOBAL SHARED STREAM statement ends.
For more information, see the DEFINE STREAM statement in OpenEdge Development: ABL Reference.