Sending output to multiple destinations
- Last Updated: March 30, 2020
- 2 minute read
- OpenEdge
- Version 12.2
- Documentation
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. ABL does not restrict you to one output destination per procedure.

In the procedure in the above figure, 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:
- The
SETstatement prompts you for the filename. - The
SEARCHfunction searches for the file, returning the filename if the file is found. - 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
DOblock and retries the block, giving you the opportunity to supply a different filename
- 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
VALUEkeyword with theOUTPUT TOstatement. TheVALUEoption tells the AVM (ABL Virtual Machine) to use the value of the outfile variable rather than the name "outfile" itself. If instead you sayOUTPUT TOoutfile, the AVM 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 the following figure uses the OUTPUT CLOSE statement
to reset the output destination from a file to the terminal.

The procedure in the above figure 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:
- The
OUTPUT TOstatement redirects output so all statements that normally send output to the terminal send output to the cust.dat file. - The
FOR EACH customerandDISPLAYstatements produce a report listing each customer's name, address, city, and state. The procedure sends the report to the cust.dat file. - The
OUTPUT CLOSEstatement resets the output destination for the procedure from the cust.dat file to the terminal. - The last
DISPLAYstatement displays the message "Finished" on the terminal screen.