Progress
Programming
Handbook
Defining Additional Input/Output Streams
When you start a procedure, Progress 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. Figure 7–7 illustrates this scenario.
Figure 7–7: 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.
The procedure
p-dfstr.p
uses the two report scenarios shown in Figure 7–7.
The numbers to the left of the procedure correspond to the following step-by-step descriptions:
- 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.
- 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.
- 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.”
- 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.”
- The FOR EACH block reads a single item record on each iteration of the block.
- If the allocated amount of an item is larger than the on-hand amount of that item:
- 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.
- 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.
- 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.
- 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.
- 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.
- The OUTPUT STREAM CLOSE statements close the rpt and exception streams, redirecting all further output to the default output destination.
Copyright © 2004 Progress Software Corporation www.progress.com Voice: (781) 280-4000 Fax: (781) 280-4095 |