Defining a shared stream
- Last Updated: August 23, 2021
- 2 minute read
- OpenEdge
- Version 12.2
- Documentation
Use the SHARED parameter of the DEFINE STREAM statement to create a shared stream.
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
|
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
|
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 STREAMstatement to define a stream that is available only to the current procedure. - To define a shared stream, you define the stream as
NEW SHAREDin the procedure that creates the stream, and asSHAREDin 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 GLOBALwhen you want that stream to remain available even after the procedure that contains theDEFINE NEW GLOBAL SHARED STREAMstatement ends.
For more information, see the DEFINE
STREAM statement in ABL Reference.