Consultor Eletrônico



Kbase P80479: How to use a Database Sequence?
Autor   Progress Software Corporation - Progress
Acesso   Público
Publicação   6/16/2008
Status: Unverified

GOAL:

How to use a Database Sequence?

GOAL:

How to use the NEXT-VALUE function?

GOAL:

How to use the NEXT-VALUE function?

GOAL:

What is the syntax for to access a 4GL sequence?

FACT(s) (Environment):

All Supported Operating Systems
Progress 8.x
Progress 9.x
OpenEdge 10.x

FIX:

1. The NEXT-VALUE function returns the current INT64 or the current INTEGER value of a sequence defined in the Data Dictionary. It has the following syntax:NEXT-VALUE ( sequence [ , logical-dbname ] )
For example, the following CREATE trigger for the Item table automatically assigns a unique item number using NextItemNum sequence:
TRIGGER PROCEDURE FOR Create OF Item.
ASSIGN Item.ItemNum = NEXT-VALUE(NextItemNum).
2. The CURRENT-VALUE function returns the current INT64 or INTEGER value of a sequence defined in the Data Dictionary. It has the following syntax:
CURRENT-VALUE ( sequence [ , logical-dbname ] )
For example, the following code finds the current value of the NextCustNum sequence and looks up the first order for that Customer:
DEFINE VARIABLE iCurrentCustNum AS INTEGER NO-UNDO.
ASSIGN
iCurrentCustNum = CURRENT-VALUE(NextCustNum).
FIND FIRST Order NO-LOCK WHERE Order.CustNum = iCurrentCustNum NO-ERROR.
3. The logical database name is optionally used when calling the NEXT-VALUE or the CURRENT-VALUE to specify the database that contains the target sequence. This is necessary when two sequences in two connected databases have the same name. For example. The following code references the CURRENT-VALUE of a sequence named mySequence in the first database and the NEXT-VALUE of a sequence named mySequence in the second database
MESSAGE CURRENT-VALUE(mySequence, FirstDatabase)
VIEW-AS ALERT-BOX INFO BUTTONS OK.
MESSAGE NEXT-VALUE(mySequence, SecondDatabase)
VIEW-AS ALERT-BOX INFO BUTTONS OK.