× The internal search function is temporarily non-functional. The current search engine is no longer viable and we are researching alternatives.
As a stop gap measure, we are using Google's custom search engine service.
If you know of an easy to use, open source, search engine ... please contact support@midrange.com.



Two ways I would handle it in order of preference:
1. Use a SQL - AS IDENTITY column and let the system handle it.
2. Use a data area for the next number, locking it when retrieving the next number guarantees you won't get duplicates.

Scott

-----Original Message-----
From: RPG400-L [mailto:rpg400-l-bounces@xxxxxxxxxxxx] On Behalf Of Vinay Gavankar
Sent: Monday, August 11, 2014 2:58 PM
To: RPG programming on the IBM i (AS/400 and iSeries)
Subject: Question on File locking

Hi,

I have a logical file with an Id and Sequence number as a Unique key. The first record for an Id is written with Seq No. as 99999 and subsequent records are to be written with (current lowest sequence - 1).

There is only one program that is writing to this file, but is running concurrently.

What would be a fool-proof way of writing to the file without having to trap for error on write and looping.

For example, when getting the lowest sequence, I can keep that record locked, and then write a record with a lower sequence and then unlock the file.

But if another instance of the program hits the same Id at the same time when the record is locked, it will wait for those microseconds for the lock to be released, but once the lock is released, wouldn't it get that record, instead of the the one that was written with a lower sequence number? In which case, it would end up with duplicate sequence number when it tries to write a record.

Is my understanding of what would happen wrong?

Would it make any difference if I were to use Setll & read instead of a Chain to get to the lowest sequence number?

TIA for any suggestions.

Vinay

As an Amazon Associate we earn from qualifying purchases.

This thread ...

Replies:

Follow On AppleNews
Return to Archive home page | Return to MIDRANGE.COM home page

This mailing list archive is Copyright 1997-2024 by midrange.com and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available on our policy page. If you have questions about this, please contact [javascript protected email address].

Operating expenses for this site are earned using the Amazon Associate program and Google Adsense.