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 11.x and later:
NEXT-VALUE ( sequence [ , logical-dbname ] [, tenant-id] )
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).
For 11.x and later with Multi-tenancy:
NEXT-VALUE(sequenceA,sportsmt,2)
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 11.x and later:
CURRENT-VALUE ( sequence [ , logical-dbname ] [ , tenant-id ] )
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.
4. In a multi-tenant database a sequence can handle different values for each Tenant. NEXT-VALUE function will get the next value and there are 2 more parameters that indicate the database and the tenant ID that needs to match with the current user. NEXT-VALUE ( sequence [ , logical-dbname ] [, tenant-id] )
If there was a table customer and a multi-tenant sequence name SeqA with a starting value of 1, running NEXT-VALUE(seqA,<dbname>,<tenantID>) the values for other tenants won't be incremented. For example:
NEXT-VALUE(seqA,testdb,GET-EFFECTIVE-TENANT-ID ("testdb"))
In this case for users running this function linked to a tenant the next value will be 2, but will keep for other tenants the value 1. So, if user 1 (tenant = 1) and user 3 (tenant 2) run some transactions:
User 1 –> next value = 2.
User 1 –> next value = 3.
User 1 –> next value = 4.
Now, user 2 runs some transactions and since user 2 is linked to another tenant, the result would be:
User 2 -> next value = 2.