Updating database records
The update operation allows you to change an existing database record in a logical or physical file.
The UPDAT statement in the RPG language and the REWRITE statement in the COBOL language are examples of this operation. Before you update a database record, first read and lock the record. You lock the record by specifying the update option on any of the read operations listed under Reading database records using an arrival sequence access path or Reading database records using a keyed sequence access path. If you issue several read operations with the update option specified, each read operation releases the lock on the previous record before attempting to locate and lock the new record. When you do the update operation, the system assumes that you are updating the currently locked record. Therefore, you do not have to identify the record to be updated on the update operation. After the update operation is done, the system releases the lock.
The rules for locking are different if your job is running under commitment control.
If the update operation changes a key field in an access path for which immediate maintenance is specified, the access path is updated if the high-level language allows it. (Some high-level languages do not allow changes to the key field in an update operation.)
If you request a read operation on a record that is already locked for update and if your job is running under a commitment control level of *ALL or *CS (cursor stability), then wait until the record is released or the time specified by the WAITRCD parameter on the create file or override commands has been exceeded. If the WAITRCD time is exceeded without the lock being released, an exception is returned to your program and a message is sent to your job stating the file, member, relative record number, and the job which has the lock. If the job that is reading records is not running under a commitment control level of *ALL or *CS, the job is able to read a record that is locked for update.
If the file you are updating has an update trigger associated with it, the trigger program is called before or after updating the record.
If the files being updated are associated with referential constraints, the update operation can be affected.
Parent topic:
Basic database file operations in programs
Related concepts
Commitment control
Triggering automatic events in your database
Ensuring data integrity with referential constraints