# 10.7 REWRITE Statement

The REWRITE statement is a data transfer output statement that rewrites the current record.

A REWRITE statement can be formatted or unformatted, and takes one of the following forms:

  Formatted:
  REWRITE (eunit, format [, iostat] [, err]) [io-list]
  Unformatted:
  REWRITE (eunit [, iostat] [, err]) [io-list]
  eunit
  Is an external unit specifier ([UNIT=]io-unit).
  format
  Is a format specifier ([FMT=]format).
  iostat
  Is a status specifier (IOSTAT=i-var).
  err
  Is a branch specifier (ERR=label) if an error condition occurs.
  io-list
  Is an I/O list.

In the REWRITE statement, data (translated if formatted; untranslated if unformatted) is written to the current (existing) record in one of the following types of external files:

- On OpenVMS systems: In all types of files. In sequential files, the current record and new record must be the same length.
- On Tru64 UNIX, Linux, and Windows systems: In a file with direct access.

The current record is the last record accessed by a preceding, successful sequential, indexed (VMS only), or direct-access READ statement.

Between a READ and REWRITE statement, you should not specify any other I/O statement (except INQUIRE) on that logical unit. Execution of any other I/O statement on the logical unit destroys the current-record context and causes the current record to become undefined.

Only one record can be rewritten in a single REWRITE statement operation.

The output list (and format specification, if any) must not specify more characters for a record than the record size. (Record size is specified by RECL in an OPEN statement.)

If the number of characters specified by the I/O list (and format, if any) do not fill a record, blank characters are added to fill the record.

If the primary key (VMS only) value is changed in a keyed-access file, an error occurs.

Examples

In the following example, the current record (contained in the relative organization file connected to logical unit 3) is updated with the values represented by NAME, AGE, and BIRTH:

          REWRITE (3, 10, ERR=99) NAME, AGE, BIRTH
    10    FORMAT (A16, I2, A8)

For More Information:

- On formatted data and data transfers, see your user manual or programmer's guide.
- On I/O control-list specifiers, see Section 10.2.1.
- On I/O lists, see Section 10.2.2.
- On the RECL specifier in OPEN statements, see Section 12.6.25 for details on OpenVMS systems; see Section 13.6.23 for details on Tru64 UNIX, Linux, and Windows systems.

Previous Page Next Page Table of Contents