14.6.5 Writing Records
For a file opened with ACCESS WRITE or ACCESS
MODIFY, the PUT statement moves data from the record
buffer to a file using the I/O buffer. PUT statements are
valid on RMS sequential, relative, and indexed files. You can-
not use PUT statements on terminal-format files or virtual
array files.
Sequential access is valid on RMS sequential, relative, and
indexed files. For sequential, variable, and stream files, a se-
quential PUT operation adds a record at the end of the file.
For sequential fixed and relative files, PUT writes records
sequentially or randomly depending on the presence of a
RECORD clause. For indexed files, RMS stores records in
order of the primary key's collating sequence. Therefore,
you do not need to specify a random or sequential PUT.
Table 14-3 shows the record context after both random and
sequential PUT operations.
After a PUT operation, the current record pointer has no
value. However, the value of the next record pointer changes
depending on the file type and the record access mode used
with the PUT operation. In a sequential, stream, or variable
file, records can only be added at the end of the file; therefore,
the next record after PUT is the end of the file. In a relative,
sequential, or fixed file, the next record after a PUT operation
is the next logical record.
The following example opens a sequential file with ACCESS
APPEND specified. For sequential files, this is almost iden-
tical to ACCESS WRITE. The only difference is that, with
ACCESS APPEND, BASIC positions the file pointer after the
last record in the file when it opens the file for processing. All
subsequent PUT operations append the new record to the end
of the existing file.
EXAMPLE: Click to display EXAMPLE.
If the current record pointer is not at the end of the file when
you attempt a sequential PUT operation to a sequential file,
BASIC signals ``Not at end of file'' (ERR=149).
In the following example, the PUT statement writes records
to an indexed file. In this case, the error message ``Duplicate
key detected'' (ERR=134) indicates that a record with a
matching key field already exists, and you did not allow
duplicates on that key.
EXAMPLE: Click to display EXAMPLE.
EXAMPLE: Click to display EXAMPLE.