Accessing Files Programmer's Guide (32650-90885)

137
10 Updating a File
You can use the FUPDATE intrinsic to update a logical record of a disk file. FUPDATE affects
the last logical record (or block for NOBUF files) accessed by any intrinsic call for the file
named, and writes information from a buffer in the stack into this record. Following the
update operation, the record pointer is set to indicate the next record position. The record
number need not be supplied in the FUPDATE intrinsic call; FUPDATE automatically updates
the last record referenced in any intrinsic call. Note that the file system assumes that the
record to be updated has just been accessed in some way.
The disk file containing the record to be updated must have been opened with the
access
type option
parameter of HPFOPEN/FOPEN set to update access. In addition, the file must
not contain a variable-length record format. Example 10-1 is an HP Pascal/iX code
segment that illustrates how to use the FUPDATE intrinsic to update records in a disk file
being shared by multiple concurrent accessors. The program segment also uses file system
locking intrinsics (FLOCK and FUNLOCK) to guarantee exclusive access to the file while the
update occurs.
The pertinent code from Example 10-1 is shown below:
.
.
.
read_length := FREAD (disk_file_num, inbuf, 128);
.
.
.
FUPDATE (disk_file_num, inbuf, 128);
.
.
.
The statements above are in a loop that follows this algorithm:
1. Read the record from the file identified by disk_file_num using the FREAD intrinsic.
2. Write the record to STDLIST to be reviewed by user.
3. Read new data input to STDIN by user and modify record in program.
4. Using FUPDATE intrinsic, write the updated record to the location in disk_file_num
indicated by last intrinsic call (in this case, the FREAD call shown above).
Example 10-1. Updating a Disk File
procedure update_disk_file;
{**************************************************************}