Release 10.1A: OpenEdge Development:
Programming Interfaces

> ## Sending output to multiple destinations

> At some points in a procedure, you might want to send output to the terminal, but at other points you might want to send output to a file. Progress does not restrict you to one output destination per procedure.

> Figure 5–4: Multiple output destinations

> In the procedure in Figure 5–4, you supply the name of the file where you want to send a customer report and then, if that file does not already exist, send the report to that file.

> | To send output to a file:

> 1. The `SET` statement prompts you for the filename.

> 2. The `SEARCH` function searches for the file, returning the filename if the file is found.

> 3. If the file is found, the procedure:

> - Displays a message telling you the file already exists and to use another filename.
> - Rings the terminal bell.
> - Undoes the work done in the `DO` block and retries the block, giving you the opportunity to supply a different filename.
> 4. If the file is not found, the procedure uses this statement:

>     OUTPUT TO VALUE(outfile).

> This statement redirects the output to the file you specified. You must use the `VALUE` keyword with the `OUTPUT` `TO` statement. The `VALUE` option tells Progress to use the value of the outfile variable rather than the name “outfile” itself. If instead you say `OUTPUT` `TO` outfile, Progress assumes that outfile is the name of the text file to which you want to send output.

> You use the `OUTPUT` `CLOSE` statement to stop sending output to a destination. Output sent after the `OUTPUT` `CLOSE` statement goes to the destination used prior to the `OUTPUT` `TO` statement.

> For example, the procedure in Figure 5–5 uses the `OUTPUT` `CLOSE` statement to reset the output destination from a file to the terminal.

> Figure 5–5: The OUTPUT CLOSE statement

> This procedure sends customer information to a file called `cust.dat`. Then the procedure displays the word “Finished” on your terminal screen. The procedure executes as follows:

> 1. The `OUTPUT` `TO` statement redirects output so all statements that normally send output to the terminal send output to the `cust.dat` file.

> 2. The `FOR` `EACH customer` and `DISPLAY` statements produce a report listing each customer’s name, address, city, and state. The procedure sends the report to the `cust.dat` file.

> 3. The `OUTPUT` `CLOSE` statement resets the output destination for the procedure from the `cust.dat` file to the terminal.

> 4. The last `DISPLAY` statement displays the message “Finished” on the terminal screen.

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