record locking in As/400

1,150 pts.
Tags:
AS/400 DB2
HI can anybody tell me about how to handle the Record locking situation when more than one user tries to access the same record in a physical file....?
ASKED: December 24, 2008  4:02 PM
UPDATED: October 6, 2011  7:14 AM

Answer Wiki

Thanks. We'll let you know when a new response is added.

Option 1 – inform the second user that the record is locked.

For native RPGLE (non-SQL) for files opened for Update.
the READ, READE or CHAIN needs (E)

Read(E) Myfile
if %ERROR
do error thing — display message record is locked
else
if not %EOF(Myfile) or if %found(Myfile) for chains

I’m sure that you can find code to actually show who is locking the record if you like.
———————————————–
Option2: For high volumn usage you can display screens without locking the records
add (N) to the read/reade/chain (No lock will not allow update)

on return after display if update is needed
get the record again but without the (N) and then update it.
————————–
Option2b: solution Option2 will write over changes made between inital acquisition and
final update.

For highest volumn usage you can display screens without locking the records
add (N) to the read/reade/chain (No lock will not allow update)
save a copy of the record by moving it to a datastructure – different prefix same file structure

on return after display if update is needed
get the record again but without the (N)
If newly acquired record is equal to the saved copy update it.
else unlock it display the new record with a message that it was updated by someone else and proceed.

Discuss This Question: 1  Reply

 
There was an error processing your information. Please try again later.
Thanks. We'll let you know when a new response is added.
Send me notifications when members answer or reply to this question.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy
  • Yorkshireman
    Don't lock the record. Don't ever write anything that locks a record - ever. Except just before you update it. read and display read and display decide an update is needed read the record for update (lock) check it hasn't changed since you displayed it ( tell the user if so) updtae it release the lock read and display read and display bl hblah
    5,520 pointsBadges:
    report

Forgot Password

No problem! Submit your e-mail address below. We'll send you an e-mail containing your password.

Your password has been sent to:

To follow this tag...

There was an error processing your information. Please try again later.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy

Thanks! We'll email you when relevant content is added and updated.

Following