REWRITE Statement - Format 1

Read syntax diagramSkip visual syntax diagram
REWRITE Statement - Format 1

>>-REWRITE--record-name-1--+--------------------+--------------->
                           '-FROM--identifier-1-'   

>--+--------------------------------------+--------------------->
   |        (1)                           |   
   '-FORMAT------+----+--+-identifier-2-+-'   
                 '-IS-'  '-literal-1----'     

>--+----------------------------------------+------------------->
   |              (1)                       |   
   '-NULL-KEY-MAP------+----+--identifier-5-'   
                       '-IS-'                   

>--+------------------------------------+----------------------->
   |          (1)                       |   
   '-NULL-MAP------+----+--identifier-6-'   
                   '-IS-'                   

>--+------------------------------------------+----------------->
   '-INVALID--+-----+--imperative-statement-1-'   
              '-KEY-'                             

>--+----------------------------------------------+------------->
   '-NOT INVALID--+-----+--imperative-statement-2-'   
                  '-KEY-'                             

>--+-------------+---------------------------------------------><
   '-END-REWRITE-'   

Notes:
  1. IBM Extension
record-name-1
The name of a record in the File Section, having the same number of character positions as the record being replaced. The name of the record cannot be reference modified.
identifier-1
This is the sending item.
FROM phrase
This phrase has the following effect:
MOVE identifier-1 TO record-name-1.
REWRITE record-name-1.

After successful processing of the REWRITE statement, the current record is no longer available in record-name-1, but is still available in identifier-1. Both record-name-1 and identifier-1 cannot refer to the same storage area.

IBM Extension
FORMAT phrase
This phrase applies when the REWRITE statement is performed against an indexed file for which the ASSIGN specified DATABASE as the file device type. It is optional when processing a file that has one record format.

The value specified in the FORMAT phrase contains the name of the record format to use for this I-O operation. The system uses this to specify or select which record format to operate on.

Identifier-2, if specified, must be an alphanumeric data item of 10 characters or less.

Literal-1, if specified, must be an uppercase character-string of 10 characters or less.

If the FORMAT phrase is not specified, the first format defined is used when accessing indexed files in Random Access Mode.

A value of all blanks is treated as though the FORMAT phrase were not specified. If the value is not valid for the file, a FILE STATUS of 9K is returned and a USE procedure is invoked, if applicable for the file.

NULL-KEY-MAP IS phrase
Refer to the description supplied for this phrase on page NULL-KEY-MAP IS Phrase.
NULL-MAP IS phrase
Refer to the description supplied for this phrase on page NULL-MAP IS Phrase.
End of IBM Extension
INVALID KEY phrase
This phrase is valid in indexed organization files, and relative organization files with random or dynamic access. It is processed when the record specified by the key field in the record area is not found.

When an INVALID KEY condition exists, the updating operation does not take place. The data in record-name is unaffected. This phrase transfers control to the corresponding imperative-statement, as appropriate.

The INVALID KEY phrase must be specified if no applicable EXCEPTION/ERROR procedure is specified for record-name-1.

An INVALID KEY condition exists when:
  • The access mode is sequential, and the value contained in the prime RECORD KEY of the record to be replaced does not equal the value of the prime RECORD KEY data item of the last-retrieved record from the file, or
  • The value contained in the prime RECORD KEY does not equal that of any record in the file.
  • The value of an ALTERNATE RECORD KEY data item for which DUPLICATES is not specified is equal to that of a record already in the file.

The INVALID KEY phrase must be specified for files in which an applicable USE procedure is not specified.

See "Invalid Key Condition" under Common Processing Facilities for more information.

For sequentially accessed indexed files on device type DISK, this phrase is processed when the value contained in the RECORD KEY of the record to be replaced does not equal the RECORD KEY data item of the last retrieved record from the file.

NOT INVALID KEY phrase
This phrase is valid for indexed organization files, and relative organization files with random or dynamic access. After the successful completion of a REWRITE statement with the NOT INVALID KEY phrase, control transfers to the imperative statement associated with the phrase.