Try OpenEdge Now
skip to main content
Programming Interfaces
Input/Output Processes : Alternate I/O Sources : Changing the output destination : Sending output to multiple destinations
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. ABL does not restrict you to one output destination per procedure.
Figure 25. Multiple output destinations
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:
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:
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 the AVM (ABL Virtual Machine) to use the value of the outfile variable rather than the name "outfile" itself. If instead you say OUTPUT TO outfile, 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.
Figure 26. The OUTPUT CLOSE statement
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:
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.