REWRITE
The REWRITE statement rewrites the current record to the specified file.
••••• REWRITE ••• ••••••••••••••••••••••
FAIL •
(1)
(2) (3) (4)
(2) Application ID |
(3) File name or field name |
(4) Fail action (0=nothing, 1=warning, 2=error, 3=cancel) |
If the record is rewritten successfully, the next level of the true/false status indicator is set to T. The status indicator is set to F if the rewrite fails (for example, a unique alternate key is already on file). If the record is not rewritten successfully, the FAIL parameter determines what additional action to take. In addition, on a false condition, the predefined field STATUS CODE returns a token indicating the reason for an I/O command failure. This token can be used as a key to read the system message file to obtain a descriptive I/O error message (see STATUS CODE for details).
When using this statement in conjunction with an RDBMS table, you can specify a field name instead of a file name to limit the volume of data being passed between APPX and the RDBMS. See the Partial-Record I/O section in Chapter 4-3: Specifying Statements for more information.
Once a record is rewritten, the hold on that record is released. If another rewrite (or a delete) is to be attempted, the record must be read again with HOLD? equal to 1 or 2.
The record must have been previously read with the HOLD? specification set to 1 or 2, or the rewrite must be done on the record currently being held by the process control file.
Because of the nature of various file systems, only one record may be held for update at a time. If a designer does not take this into consideration, the hold on a record may be lost without notice because of multiple reads with hold. If the record is read with HOLD? equal to 1, and the hold on the record is subsequently lost, the rewrite will fail. If the record is read with HOLD? equal to 2 (hold for recovery), and the hold is subsequently lost, APPX attempts to reread the record and hold it for update. If the record that is reread is changed in any way from the original record read, the rewrite will fail.
Note also that a designer should not rewrite a record held by the process control file in an input process. APPX assumes that the process control file record is still held when it needs to rewrite or delete the record. If you need to modify the process control file record in an input process, you can do so in the Pre-PCF Update event point for that process. If the record must be rewritten before the Pre-PCF Update event point, you must reread it with hold or a non-recoverable file processing error will occur.
A non-recoverable file processing error occurs if a rewrite of a record is attempted without having read the record with hold.
BEG READ, DELETE, END READ, READ, READNEXT, WRITE
In this example, a record is read and updated.
READ TAR
ADJUST1 HOLD
1 FT 0 BY ADJUST1 KEY
F ERROR Unexpected
Error READ TAR ADJUST1
T SET TAR
ADJUST1 JOURNAL OK = 0
T REWRITE TAR
ADJUST1 FAIL
0
TF ERROR Unexpected
Error REWRITE TAR ADJUST1