createSystemSequenceNumber

createSystemSequenceNumber(name:         String;
                           initialValue: Integer64);

The createSystemSequenceNumber method of the System class creates a system sequence number with the name specified by the value of the name parameter and a current value specified by the initialValue parameter. If a system sequence number with the specified name already exists, the current value is not changed and no error is reported. All access to the system sequence number table is single-threaded and is independent of process transaction state.

If the value of the name parameter is null, it contains embedded null characters, or is longer than 60 characters, a 1454 (The SystemSequenceNumber name is invalid) exception is raised.

If the value of the initialValue parameter is less than zero (0), a 1455 (The SystemSequenceNumber initial value cannot be negative) exception is raised. There is no restriction on the number of system sequence numbers you can create.

Ensure that the initial value passed to the createSystemSequenceNumber method does not cause the getSystemSequenceNumberNext method to return an already used number. If the getSystemSequenceNumberNext method returns zero (0), determine the highest number that has been assigned to an object stored in the database and call the createSystemSequenceNumber method passing that value.

The following method returns the next available customer number, where the customer number is used as a key in an exclusive MemberKeyDictionary collection owned by a Company object.

getNextCustomerNumber(): Integer64;
constants
    SSN_CustomerNumber: String = "MySchema::CustomerNumber";
vars
    nextNumber: Integer64;
    coy: Company;
    cust: Customer;
begin
    nextNumber := system.getSystemSequenceNumberNext(SSN_CustomerNumber);
    if nextNumber = 0 then
       coy := Company.firstInstance();
       if coy <> null then
            cust := coy.allCustomersByNumber.last();
           if cust <> null then
               nextNumber := cust.number
           endif;
       endif;
       system.createSystemSequenceNumber(SSN_CustomerNumber, nextNumber);
       nextNumber := system.getSystemSequenceNumberNext(SSN_CustomerNumber);
    endif;
    return nextNumber;
end;