6.3.2 Writing Records to a Terminal-Format File
The following example receives information from a termi-
nal, then writes the information to a terminal-format file as
a report:
EXAMPLE: Click to display example.
Output
EXAMPLE: Click to display example.
This program first prints a header explaining its purpose,
then opens a terminal-format file on channel 4. After this file
is opened, the two PRINT # statements place an explanatory
header followed by a blank line into the file.
The program then prompts you for the number of salesper-
sons for which data is to be entered. The FOR...NEXT loop
prompts for the name, sales area, and items sold for each
salesperson. Note that the FOR...NEXT loop executes only
as many times as there are salespersons. See Chapter 10 for
more information about FOR...NEXT loops.
After the data has been entered for each salesperson, the
program writes this information to the terminal-format
file. Because the response to the first question was 3, the
FOR...NEXT loop executes three times.
After the last item has been printed to the file, the program
closes the file and ends. When you display the file with the
DCL command TYPE, you see that the information is printed
under the proper headers. You can also print the file on a
line printer. Note that the PRINT # statement formats the
output in print zones as the PRINT statement does.
$ TYPE SALES.DAT
Salesperson Sales Area Items Sold
JONES NJ 5
SMITH NH 6
BAINES VT 8