Try OpenEdge Now
skip to main content
Programming Interfaces
Data Management : Database Access : Sequences : Accessing and incrementing sequences : Using the NEXT-VALUE function
 
Using the NEXT-VALUE function
Use the NEXT–VALUE function to increment a sequence by its defined positive or negative increment value. If the sequence cycles and NEXT–VALUE increments it beyond its Upper or Lower limit, the function sets and returns the defined Initial value for the sequence. If the sequence terminates and NEXT–VALUE tries to increment it beyond its Upper or Lower limit, the function returns the Unknown value (?) and leaves the sequence value unchanged.
The following example creates a new Customer record with the next available Customer number generated by the NextCustNum sequence:
DEFINE VARIABLE input-custnum AS INTEGER NO-UNDO.

input-custnum = NEXT-VALUE(NextCustNum, sports2000).
FIND sports2000.Customer NO-LOCK
  WHERE Customer.CustNum = input-custnum NO-ERROR.

DO WHILE (AVAILABLE Customer):
  input-custnum = NEXT-VALUE(NextCustNum, sports2000).
  FIND sports2000.Customer NO-LOCK
    WHERE Customer.CustNum = input-custnum NO-ERROR.
END.

CREATE sports2000.Customer.
Customer.CustNum = input-custnum.
UPDATE sports2000.Customer.
. . .
Because this example does not check the NextCustNum sequence for termination, it implies that NextCustNum is a cycling sequence. Because it does check for and ignore existing records containing the generated CustNum value, the example can reuse previously deleted (or otherwise skipped) Customer numbers after the sequence cycles.