Accessing Files Programmer's Guide (32650-90885)

122 Chapter8
Writing to a File
Writing to $STDLIST
end; {end procedure }
The operation is performed in a loop. Before each write operation, record_num is
decremented. The loop ends when the FREAD intrinsic encounters an EOF in
old_disk_file (indicating the end of the file). For more information about FWRITEDIR
intrinsic parameters, refer to the MPE/iX Intrinsics Reference Manual. For more
information about the FREAD intrinsic, refer to chapter 9, "Reading from a File". In
appendix A, "HP Pascal/iX Program Examples", example A-3 uses a similar routine to copy
records using the random access method of data transfer to write date from one file to
another.
Writing to $STDLIST
You can write data from your program to your program's standard list device $STDLIST
using two intrinsics:
PRINT
FWRITE
Normally, $STDLIST for jobs is a line printer and for sessions a terminal. You can write a
string of ASCII characters from an array in your program to $STDLIST with the PRINT
intrinsic. You do not need to use HPFOPEN/FOPEN to open the standard list device in order
to use PRINT.
NOTE
The PRINT intrinsic is limited in its usefulness in that FILE commands are
not allowed. In addition, you cannot use the FCHECK intrinsic to determine
error conditions encountered by PRINT. You may find it more convenient (and
a better programming practice) to use the HPFOPEN/FOPEN intrinsic to open
the file $STDLIST, then write to this file using FWRITE.
You can also use the FWRITE intrinsic to write data from your program to the standard list
device $STDLIST, if you opened $STDLIST with HPFOPEN/FOPEN. In this case, the
HPFOPEN/FOPEN call returns a file number that identifies $STDLIST. You would then write
to $STDLIST sequentially using FWRITE. For more information about opening $STDLIST,
refer to chapter 5, "Opening a File".
Example 8-3 is an HP Pascal/iX code segment that contains a PRINT intrinsic call that
transmits a message to $STDLIST.
Example 8-3. Writing to $STDLIST Using PRINT
.
.
.
var
message : packed array [1..72] of char; {declare PRINT parm}
message_length : shortint; {declare PRINT parm}
controlcode : 0..65535; {declare PRINT parm}
.