When you start a procedure, the AVM automatically provides that procedure with input and output streams. As described in the previous sections, the default source for the input stream is the terminal and the default destination for the output stream is also the terminal. You saw how to use the INPUT FROM and OUTPUT TO statements to redirect these input and output streams.
You might find that having just one input stream and one output stream is not enough for particular procedures. That is, you might want to get input from more than one source at the same time or send output to more than one destination at the same time.
Suppose you want to produce a report of the items you have in inventory and you want to send the report to a file. You already know how to use the OUTPUT TO statement to redirect the output stream to a file. Suppose that you also want to produce an "exceptions" report at the same time. Any item where the allocated amount is greater than the on-hand amount is an exception. The following figure illustrates this scenario.
Figure 29. Multiple output streams scenario
For items that are exceptions, the procedure needs to send output to a second location. That means you need two different output streams.
You use the DEFINE STREAM statement to define additional streams for a procedure to get input from more than one source simultaneously and send output to more than one destination simultaneously. Streams you name can be operating system files, printers, the terminal, or other non-terminal devices.
For information regarding the maximum number of streams allowed in OpenEdge applications, see the Input/Output Limits table in OpenEdge Deployment: Managing ABL Applications.
For information about the size limit of operating system files, see the input/output limits section of OpenEdge Deployment: Managing ABL Applications.
The procedure i-dfstr.p uses the two report scenarios shown in the above figure.
i-dfstr.p
DEFINE VARIABLE exception AS LOGICAL NO-UNDO.
DEFINE VARIABLE excount AS INTEGER NO-UNDO
LABEL "Total Number of exceptions".
DEFINE VARIABLE fne AS CHARACTER NO-UNDO FORMAT "x(12)".
DEFINE VARIABLE fnr AS CHARACTER NO-UNDO FORMAT "x(12)".
DEFINE STREAM exceptions.
DEFINE STREAM rpt.
/*1*/ SET fnr LABEL "Enter filename for report output" SKIP(1)
fne LABEL "Enter filename for exception output"
WITH SIDE-LABELS FRAME fnames.
/*2*/ OUTPUT STREAM rpt TO VALUE(fnr) PAGED.
OUTPUT STREAM exceptions TO VALUE(fne) PAGED.
The numbers on the left of the procedure correspond to the following step-by-step descriptions:
1. The SET statement prompts you for the filenames you want to use for the Item Inventory Report and for the Item Exception Report. It stores your answers in the fnr and fne variables, respectively.
2. The OUTPUT STREAM statements open two output streams, named rpt and exceptions. These streams were defined at the start of the procedure with the DEFINE STREAM statement.
The rpt and exceptions streams are directed to the files whose names you supplied: VALUE(fnr) and VALUE(fne). This means that output can now be sent to either or both of those files.
3. The DISPLAY statement displays the text Item Inventory Report. But instead of displaying that text on the terminal, it displays it to the rpt stream. The file you named for the Item Inventory Report contains the text Item Inventory Report.
4. This DISPLAY statement also displays text but it uses the exceptions stream. The file you named for the Item Exception Report contains the text Item Exception Report.
5. The FOR EACH block reads a single item record on each iteration of the block.
6. If the allocated amount of an item is larger than the on-hand amount of that item then:
The DISPLAY statement displays item data to the exceptions stream. After this DISPLAY statement finishes, the file you named for the Item Exception Report contains item data for a single item.
The excount counter variable, defined at the start of the procedure, is incremented by 1. The value of this variable is displayed at the end of the procedure so that you know the total number of exception items in inventory.
The exception logical variable, defined at the start of the procedure, is set to TRUE.
7. The DISPLAY statement displays some item data to the rpt stream. After this statement finishes, the file you named for the Item Inventory Report contains item data for a single item.
8. If the item is an exception, determined by the value in the exception logical variable, the DISPLAY statement displays the string "See Exception Report" to the rpt stream. That way you know, when looking at the Item Inventory Report, which items are exceptions.
9. The DISPLAY statement displays the value of the excount variable to the exceptions stream. The value of this variable is the total number of exception items.
10. This DISPLAY statement displays the value of the excount variable to the rpt stream. Although the DISPLAY statement does not explicitly say what is being displayed, it does name the same frame, exc, as is used to display excount in the previous DISPLAY statement. That means that the exc frame already contains the excount value. Thus, all this second DISPLAY statement has to do is name the same frame.
11. The OUTPUT STREAM CLOSE statements close the rpt and exception streams, redirecting all further output to the default output destination.