Accessing Files Programmer's Guide (32650-90885)

119
8 Writing to a File
This chapter describes, through program examples, various ways that you can use file
system intrinsics to transfer data from your program to a disk file or a device file. This
chapter is intended to illustrate topics introduced in chapter 7, "Record Selection and Data
Transfer". This chapter is divided into the following topics:
"Sequential Access and Random Access" discusses two common methods of record
selection and data transfer, and uses examples to illustrate the use of the FWRITE and
FWRITEDIR intrinsics.
"Writing to $STDLIST" discusses how your program can use the PRINT and FWRITE
intrinsics to write data from your program to the job/session standard list device,
$STDLIST. An example illustrates the use of the PRINT intrinsic to write a character
string to $STDLIST.
"Writing Messages to the system console" discusses how your program can send
messages from your program to the system console, and request a reply from the
operator. Examples illustrate the use of the PRINTOP and PRINTOPREPLY intrinsics.
"Writing to a Magnetic Tape File" discusses how you can write data to two kinds of
magnetic tape files: unlabeled tape files and labeled tape files. Examples illustrate the
use of the FWRITE intrinsic to write data to both types of tape files.
"Writing a File Label to a Labeled Tape File" provides an example of using the
FWRITELABEL intrinsic to write a user-defined file label to a labeled magnetic tape file.
Sequential Access and Random Access
Two of the most frequently used methods of transferring data to a file from your program
are sequential access and random access.
When you use sequential access to write data to a file, you write data to the record
currently pointed to by the record pointer. You use the FWRITE intrinsic to write data
sequentially to a disk file or device file. When you open a file with any form of write access
(except Append) specified in the
access type option
of HPFOPEN/FOPEN, the file is opened
with the record pointer set to the first record in the file. When you have accomplished the
write operation, the file system automatically sets the record pointer to point to the
beginning of the next record in the file. Both disk files and device files can be accessed with
the FWRITE intrinsic.
When you use random access to write data to a disk file, you write data to any record in the
file by specifying where you want the file system to set the record pointer prior to the write