Let's talk about how you use Lock, and how it works. When you lock something, the system adds the argument of Lock to the Lock Table. If another process tries to lock the same record, that process will wait until the first process releases the lock. The second process may select a different record for editing, and Lock that record; the system will add that record to the Lock Table also. Use the Management Portal; click System Operation > Locks > View Locks to look at the Lock Table.
The regular form of Lock also clears any entries in the Lock Table for your process prior to adding the new entry. To add an entry to the Lock Table without clearing any other locks, use Lock +. To remove the entry, use Lock -. You can use one Terminal session to lock a record, and then start another session and try to lock the same record, or a different record, and see the results in the Lock Table.
USER>lock ^x(1) ; clear all locks for this process, and add ^x(1) USER>lock ; clear all locks for this process USER>lock +^x(1) ; add ^x(1) without clearing anything USER>lock -^x(1) ; just clear ^x(1) USER>
In the next exercise, you will write some code that allows the user to edit a person. Your code will update the ^PersonD and ^PersonI globals. In this case, once the user selects a record for editing, with a specific ID, you will use this code: lock +^PersonD(id). After the new data is stored, you will unlock the record using: lock -^PersonD(id).