Previous Topic Next topic Print topic


REWRITE

Purpose

Replaces a record in a DIRECT UPDATE, SEQUENTIAL UPDATE, or a KEYED SEQUENTIAL UPDATE file.

Syntax

REWRITE FILE(f)[FROM(v)][KEY(k)];

Parameters

f
A reference to the file containing the record to be replaced.
v
A reference to the variable whose value is to be used to rewrite the specified record.
k
An expression specifying the key to be used to locate the record to be rewritten.

Description

The REWRITE statement replaces a record in an UPDATE file. For SEQUENTIAL UPDATE files, the REWRITE statement specifies that the last record read form the file is to be rewritten. Note that, in this case, a record must be read before it can be rewritten. For DIRECT UPDATE files, and for KEYED SEQUENTIAL UPDATE files associated with indexed (VSAM) files, any record can be rewritten, whether or not it has first been read.

Because the set of file attributes that would be supplied as a result of an implicit file opening caused by a REWRITE statement does not include DIRECT, the FILE specifier must reference a file value whose associated file has been opened with the DIRECT and UPDATE attributes.

The KEY option is required for DIRECT non-indexed files and not allowed for SEQUENTIAL files.

The FROM specifier must contain a variable reference. The storage of that variable is copied as the new record. The FROM specifier must not contain a variable that is an unaligned bit string or a structure that consists entirely of unaligned bit strings or a structure with the UNION attribute.

If the last record read was read by a READ statement with the INTO option, a REWRITE statement without the FROM option has no effect. If the last record read was read by a READ statement with the SET option, a REWRITE without the FROM option causes the data record to be updated with the current contents of the buffer indicated by the pointer variable specified by the SET option of the READ.

The FILE, FROM, and KEY specifiers may be given in any order.

Example

REWRITE FILE(F) FROM(X) KEY(N+1); 
REWRITE FILE(F) FROM(Y(K)) KEY('ABC');

Restrictions

None.

Previous Topic Next topic Print topic