| **Navigation:**  [[introduction.htm|Language Reference]] > 13 - Built-in Functions >====== WATCH (automatic concurrency check) ====== | [[val return ascii value .htm|{{btn_prev_n.gif|Previous page}}]][[introduction.htm|{{btn_home_n.gif|Return to chapter overview}}]][[what return field from group .htm|{{btn_next_n.gif|Next page}}]] | | || **WATCH(**// entity //**)** {{blk2blue.jpg|blk2blue.jpg}} | **WATCH** | Arms automatic optimistic concurrency checking. | | //entity// | The label of a FILE or VIEW declaration. | The **WATCH** statement arms automatic optimistic concurrency checking by the file driver for a following GET, REGET, NEXT, or PREVIOUS statement in a multi-user environment. The WATCH terminates when the WATCHed record is PUT back to the //entity//, or another GET, NEXT, PREVIOUS, or REGET statement executes on the same //entity// without first executing another WATCH statement. Generally, the file driver retains a copy of the retrieved record on the GET, NEXT, PREVIOUS, or REGET when it successfully gets the record. When the retrieved record is PUT to the //file//, the record on disk is compared to the original record retrieved. Error 89 (Record Changed By Another Station) is posted by the PUT statement if the record has been changed by another user. You can now specify which fields are to be used to WATCH if a record has changed. By default //all// fields are used. However, if you have a specific field (or set of fields) that are always changed when a record is changed (e.g., a record last changed a timestamp field), then you can set the **external name** of the field to: **<;F****//ieldName//****> | WATCH** and then //only// fields with the WATCH switch in them will be used to check if a record has changed. **Example:** **SET(Itm:InvoiceKey)                     !Start at beginning of Items file** **LOOP                                    !Process all records** ** ****WATCH****(Items)                           !Arm concurrency check** ** NEXT(Items)                            !Get a record** ** IF ERRORCODE() THEN BREAK.** ** DO ItemProcess                         !process the item** ** PUT(Items)                             !and put it back** ** IF ERRORCODE() = RecordChangedErr      !If changed by another station** **  PREVIOUS(Items)                       !Setup to re-process the changed record** ** ELSE** **  STOP(ERROR())                         !Stop on any other error** ** END** **END** **See Also:** [[next read next record in sequence .htm|NEXT]] [[previous read previous view record in sequence .htm|PREVIOUS]] [[get read a record or entry .htm|GET]] [[reget re get record .htm|REGET]] [[hold exclusive record access .htm|HOLD]]