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.
SAMPLES>lock ^x(1) ; clear all locks for this process, and add ^x(1) SAMPLES>lock ; clear all locks for this process SAMPLES>lock +^x(1) ; add ^x(1) without clearing anything SAMPLES>lock -^x(1) ; just clear ^x(1) SAMPLES>
In the next version of your lookup routine, you will write some code that allows the user to edit a person. This means you will be updating the ^PersonD and ^PersonI globals. In this case, once the user selects a record for editing, with a specific ID, you will add this to your routine: lock +^PersonD(id). After the new data is stored, you will unlock the record using lock -^PersonD(id).