Kbase P102781: How to avoid a sequence to rollover ?
Autor |
  Progress Software Corporation - Progress |
Acesso |
  Público |
Publicação |
  04/04/2005 |
|
Status: Unverified
GOAL:
How to avoid a sequence to rollover ?
GOAL:
How to extend a sequence maximum value ?
GOAL:
How to obtain a unique sequential large value ?
FIX:
Sometimes the maximum value of a sequence 2,147,483,647 is not enough to guarantee uniqueness during a long period of time. In this case it is possible to use two or more sequences to get longer and unique values.
Here is an example of a program that includes a function that uses two sequences to create a longer value. Sequence1 and Sequence2 are defined in the DB and start from 0 up to 2,147,483,647.
/* bisequence.p */
/* Defines and double resolution sequence function */
FUNCTION bisequence RETURNS Character ().
DEF VAR ns1 AS INTEGER.
DEF VAR ns2 AS INTEGER.
ns1 = NEXT-VALUE(sequence1).
/* Define a maximum value with a 100 number margin in case other
processes get sequences while doing this IF */
IF ns1 < 2147483647 - 100 THEN
ns2 = Current-VALUE(sequence2).
ELSE DO:
CURRENT-VALUE(sequence1) = 0.
ns2 = NEXT-VALUE(sequence2).
END.
RETURN ( string(ns2,"9999999999") + string(ns1,"9999999999") ).
END FUNCTION.
/* Start Program */
DEF VAR biseq AS CHARACTER format "x(30)".
biseq = bisequence().
DISPLAY biseq.