In addition to the return codes in the I/O Command Return Codes Table, the system variable *DBMS_RECORD_LOCKED can be used to distinguish between an I/O error status of record locked and other I/O errors.
The following example shows how the IO_ERROR parameter passes control to the label TST when an error occurs and the GOTO NXT by-passes the if condition when the command was successful.
UPDATE FIELDS(#ORDERQTY) IN_FILE(ORDLINE)
WITH_KEY(#ORDER #LINE) IO_ERROR(TST)
TST IF COND('*DBMS_RECORD_LOCKED *EQ Y')
MESSAGE MSGTXT('Order line record locked')
........ ..Required action
ABORT MSGTXT('Fatal I/O error on ORDERLINE file')
NXT ....... ..Next action
Comments / Warnings
If using this method on files which were compiled prior to Release 7.0, the I/O module must be recompiled first.
As the IO_ERROR parameter passes control to the label nominated, the condition should always have an ELSE command with an appropriate action to handle a non-record locked I/O error as in the example:
DBMS_RECORD_LOCKED only checks the status of the file, which is the subject of the command. If in the example batch control logic is used and the batch control record was locked *DBMS_RECORD_LOCKED would return a value of 'N'. The same applies to any files used by triggers. If the record locked status is to be checked for a file used by a trigger the above logic should be inserted into the trigger function.
IBM i: Automaticaly unlocks a file after a certain period of time.
Non-IBM i: This feature is emulated and disabled by default. For further details, refer to Lock Timeout.