Release 10.1A: OpenEdge Development:
Progress 4GL Reference

> ## DEFINE STREAM statement

> Use the DEFINE STREAM statement when you want to use streams other than the two unnamed streams supplied by Progress. Using other streams let you, in a single procedure, get input from more than one source simultaneously or send output to more than one destination simultaneously.

> #### Syntax

>     DEFINE [ [ NEW [ GLOBAL ] ] SHARED ] [ PRIVATE ] STREAM stream

> `NEW SHARED STREAM `stream``

> Defines and identifies a stream that can be shared by other procedures. When the procedure using the DEFINE NEW SHARED STREAM statement ends, the stream is no longer available to any procedure. The value you use for the `stream` option must be a constant.

> `NEW GLOBAL SHARED STREAM `stream``

> Defines and identifies a stream that can be shared by other procedures and that will remain available even after the procedure that contains the DEFINE NEW GLOBAL SHARED STREAM statement ends. The value you use for the `stream` option must be a constant.

> `SHARED STREAM `stream``

> Defines and identifies a stream that was created by another procedure using the DEFINE NEW SHARED STREAM statement or the DEFINE NEW GLOBAL SHARED STREAM statement. The value you use for the `stream` option must be a constant.

> `[ PRIVATE ] STREAM `stream``

> Defines and identifies a stream as a data member for a class, and optionally specifies an access mode for that data member. Do not specify the access mode when defining a stream for a method within a class.

> PRIVATE data members can be accessed only by the defining class. The default access mode is PRIVATE.

> Note: This option is applicable only when defining a data member for a class in a class definition (`.cls`) file.

> `STREAM `stream``

> Defines and identifies a stream that can be used only by the procedure, or method within a class, containing the DEFINE STREAM statement. The value you use for the `stream` option must be a constant.

> Examples

> This procedure, in a single pass through the item table, uses the rpt stream to create a report and the exceptions stream to create a list of exceptions:

> r-dfstr.p
>     DEFINE NEW SHARED STREAM rpt.
>     DEFINE STREAM exceptions.
>     DEFINE VARIABLE fnr AS CHARACTER FORMAT "x(12)".
>     DEFINE VARIABLE fne AS CHARACTER FORMAT "x(12)".
>     DEFINE VARIABLE excount AS INTEGER LABEL "Total Number of exceptions".
>     DEFINE NEW SHARED BUFFER xitem FOR item.

>     SET fnr LABEL "Enter filename for report output" SKIP(1)
>         fne LABEL "Enter filename for exception output"
>         WITH SIDE-LABELS FRAME fnames.

>     OUTPUT STREAM rpt TO VALUE(fnr) PAGED.
>     OUTPUT STREAM exceptions TO VALUE(fne) PAGED.

>     FOR EACH xitem:
>         IF on-hand < alloc THEN DO:
>           DISPLAY STREAM exceptions item-num item-name on-hand alloc
>              WITH FRAME exitem DOWN.
>           excount = excount + 1.
>         END.
>         RUN r-dfstr2.p.
>     END.

>     DISPLAY STREAM exceptions SKIP(1) excount WITH FRAME exc SIDE-LABELS.
>     DISPLAY STREAM rpt WITH FRAME exc.

>     OUTPUT STREAM rpt CLOSE.
>     OUTPUT STREAM exceptions CLOSE.

> Include the DISPLAY statement in the `r-dfstr2.p` procedure in the `r-dfstr.p` procedure for efficiency. (It is in a separate procedure here to illustrate shared streams.)

> r-dfstr2.p
>     DEFINE SHARED STREAM rpt.
>     DEFINE SHARED BUFFER xitem FOR item.

>     DISPLAY STREAM rpt item-num item-name WITH NO-LABELS NO-BOX.

> #### Notes

> - You cannot define a SHARED or NEW SHARED stream in a user-defined function, an internal procedure, or a persistent procedure. If you do, Progress raises an ERROR on the RUN statement that creates the procedure.

> - You cannot define a SHARED or NEW SHARED stream in a class definition (`.cls`) file. If you do, Progress generates a compilation error.

> - Progress automatically provides two unnamed streams to each procedure: the input stream and the output stream. These streams give the procedure a way to communicate with an input source and an output destination. For example, the following statement tells Progress to use the unnamed input stream to get input from the file named `testfile`.

>     INPUT FROM testfile.

> - Using the DEFINE STREAM statement creates a stream, but it does not actually open that stream. To open a stream, you must use the STREAM option with the INPUT FROM, INPUT THROUGH, OUTPUT TO, OUTPUT THROUGH, or INPUT-OUTPUT THROUGH statements. You must also use the STREAM option with any data handling statements that move data to and from the stream.

> - After you open the stream, you can use the SEEK function to return the offset value of the file pointer, or you can use the SEEK statement to position the file pointer to any location in the file.

> - For more information on using streams, see the section on alternate I/O sources in OpenEdge Development: Programming Interfaces .

> #### See also

> DISPLAY statement, INPUT CLOSE statement, INPUT FROM statement, INPUT THROUGH statement, INPUT-OUTPUT THROUGH statement, OUTPUT CLOSE statement, OUTPUT THROUGH statement, OUTPUT TO statement, PROMPT-FOR statement, RUN statement, SEEK function, SEEK statement, SET statement

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