× 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.



It is an existing file defined with a DDS and not an SQL TABLE.

Let me explain what my question was.

Let us say the lowest sequence in the file for Id ABC is 99998.

Now the first instance of the program, wants to write another record for
Id ABC, so locks this record, and goes on to write a record with seq 99997.

Before the record with 99997 is actually written, another instance of the
program tries to find the lowest sequence for Id ABC. At this point, it is
still 99998, so it goes in LCKW state.

Now the first instance completes the write of 99997 and releases the lock
on 99998.

Wouldn't the second instance get the Seq 99998 record, on which it was
waiting for the lock to be released and try to write 99997 seq#?


Vinay


On Mon, Aug 11, 2014 at 5:43 PM, CRPence <CRPbottle@xxxxxxxxx> wrote:

On 11-Aug-2014 15:58 -0500, Vinay Gavankar wrote:


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).


Although an LF may be used to define the Access Path and UNIQUE, the
data is in the physical. The database can write the sequence for you. Look
into Identity columns. The database file must be an SQL TABLE to use that
feature.

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.

<<SNIP /that/ record etc. I could not comprehend>

TIA for any suggestions.


Assumed the concurrency either does not exist for the initial row for a
particular Id, or any issues with that specific concurrency are already
resolved\dealt-with.

Use the initial row as a means to establish a semaphore for adding any
new row with a newly calculated sequence. Make the writer of each
additional row that has a new sequence number for a particular ID, obtain a
lock on the /initial row/ of that ID [i.e. the row with the ID being
processed and SeqNbr=999999], then while that row lock is still held
determine the lowest existing sequence for that ID, calculate the new
sequence number and set the buffer for the row to be written, then write
that row with the new sequence for that ID, then finally release the lock
on the initial row. Of course, any updater outside of that application['s
algorithm to ensure proper sequencing] could break that process.

--
Regards, Chuck

--
This is the RPG programming on the IBM i (AS/400 and iSeries) (RPG400-L)
mailing list
To post a message email: RPG400-L@xxxxxxxxxxxx
To subscribe, unsubscribe, or change list options,
visit: http://lists.midrange.com/mailman/listinfo/rpg400-l
or email: RPG400-L-request@xxxxxxxxxxxx
Before posting, please take a moment to review the archives
at http://archive.midrange.com/rpg400-l.



As an Amazon Associate we earn from qualifying purchases.

This thread ...

Follow-Ups:
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.