Below are some alternatives for generating unique primary keys values.
For more information read here.
Create a transaction that has the following structure:
Numerator
{
NumeratorCode* - Char(6)
NumeratorLastNumber - Numeric(10)
}
Then, suppose you have defined the following transactions:
Customer
{
CustomerCode* - Numeric(10)
CustomerName - Character(80)
}
Product
{
ProductCode* - Numeric(10)
ProductName - Character(200)
}
After that, create a procedure like this:
Autonumber Procedure
Rule:
Parm(&NumeratorCode, &NumeratorLastNumber);
Source:
For Each Numerator
where NumeratorCode = &NumeratorCode
NumeratorLastNumber += 1
&NumeratorLastNumber = NumeratorLastNumber
when none
new
NumeratorCode = &NumeratorCode
NumeratorLastNumber = 1
&NumeratorLastNumber = 1
endnew
EndFor
Finally, in the Customer transaction rules section, you have to invoke the procedure as follows:
CustomerCode = Autonumber('CUS') on BeforeInsert;
Also, in the Product transaction rules section, you have to invoke the procedure as follows:
ProductCode = Autonumber('PRO') on BeforeInsert;
Get basic samples here.
In two-level transactions, the Serial rule is an option for second level numbering.