MIDRANGE dot COM Mailing List Archive



Home » MIDRANGE-L » March 2014

Re: is there a proper method to get next number in sequence?



fixed

Best to use an identity key in the database table defined as the primary
key. The database will not allow two people to get the same key and it is
all managed by the database.


On Thu, Mar 13, 2014 at 7:43 PM, Ken Sims <mdrg8066@xxxxxxxxxxx> wrote:

Hi Joel -

On Thu, 13 Mar 2014 20:47:50 +0000, "Stone, Joel"
<Joel.Stone@xxxxxxxxxx> wrote:

Is it OK to find the next contract # during the contract add? I would
think that this would be risky and it may be better to simply bump the data
area by 1 and then wait and validate it is unique whenever the NEXT user
tries to add a contact.

In situations like this I always store the last number used.

Then in the program I increment the number until I'm able to
successfully add the record, and save that number.

Generally I do a setll first, then if not %equal attempt the write.

Assuming that all programs now use the data data and that the data
area is being held with an EXCLRD lock during this, if the setll is
not %equal, the write should not have a duplicate key failure.

The instances where I do this, there generally aren't gaps in the
numbers, so I do a SETGT/READP to get the highest existing record,
then do the SETLL/WRITE. In this instance I could get a duplicate key
halt on the WRITE because of another job adding a record between my
SETLL and my WRITE. But I still do the SETLL first to minimize
duplicate key halts getting put into the job log. (It reduces the
window from the time between my SETGT and my WRITE to the time between
my SETLL and my WRITE.)

Ken
Opinions expressed are my own and do not necessarily represent the views
of my employer or anyone in their right mind.
--
This is the Midrange Systems Technical Discussion (MIDRANGE-L) mailing list
To post a message email: MIDRANGE-L@xxxxxxxxxxxx
To subscribe, unsubscribe, or change list options,
visit: http://lists.midrange.com/mailman/listinfo/midrange-l
or email: MIDRANGE-L-request@xxxxxxxxxxxx
Before posting, please take a moment to review the archives
at http://archive.midrange.com/midrange-l.







Return to Archive home page | Return to MIDRANGE.COM home page

This mailing list archive is Copyright 1997-2014 by MIDRANGE dot 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 here. If you have questions about this, please contact