KNOWLEDGE BASE
Log In    |    Knowledge Base    |    4D Home
Tech Tip: Setting the starting sequence number
PRODUCT: 4D | VERSION: 14.x | PLATFORM: Mac & Win
Published On: February 3, 2016

The sequence number is a unique non-repeating number assigned to a field of a record. The number is set by the Autoincrement property and starts at the default of 1. The default can be changed using Set Database Parameter with selector 31. Below is an utilty method that will change the sequence number of the given field.

// Sets starting sequence number of given field.
// Method name: UTIL_SET_SEQ_NUM
//
//  $1  - Pointer to table field (numeric type)
// ($2) - Optional parameter. If specified, set seq no. to given value in paramater
//        else set seq no. to maximum value of all the records of the given field

C_POINTER($fieldPtr;$1;$tblPtr)
C_LONGINT($max;$2)
If (Count parameters>=1)
   $fieldPtr:=$1
   $tblPtr:=Table(Table($fieldPtr))
   ALL RECORDS($tblPtr->)
   If (Count parameters>=2)
      $max:=$2
   Else
      $max:=Max($fieldPtr->)
   End if
   SET DATABASE PARAMETER($tblPtr->;Table sequence number;$max)
End if


Example:

To set [Table_1]ID's sequence number to 1000, do the following:
UTIL_SET_SEQ_NUM (->[Table_1]ID;1000)
$seqNum:=Get database parameter([Table_1];Table sequence number)
Note: If the sequence number is set to 1000, the next new record created will have the sequence number of 1001.