KNOWLEDGE BASE
Log In    |    Knowledge Base    |    4D Home
Tech Tip: Utility to check if sequential is the same as max value of a field
PRODUCT: 4D | VERSION: 12.4 | PLATFORM: Mac & Win
Published On: October 13, 2012

This utility is designed to be used as a startup method that utilizes Set Database Parameter. The startup determines the maximum value of the fields then retrieves the sequence number to compare. If it is less than max value, then sequence number is out of sync. The utility will execute the Set Database Parameter to repair the sequence.

Call Example:SetSequenceNumber(->[Table]SeqField)

Here is the utility to execute the method:

// Method: SetSequenceNumber
C_POINTER($1;$table_p) // field pointer
C_LONGINT($nextSeq_l;$maxValue_l;$tableNum_l;$fieldNum_l)
C_TEXT($unused_t)

RESOLVE POINTER($1;$unused_t;$tableNum_l;$fieldNum_l)
$table_p:=Table($tableNum_l)

$nextSeq_l:=Get database parameter($table_p->;Table Sequence Number)
ALL RECORDS($table_p->)
$maxValue_l:=Max($1->)

If ($nextSeq_l<$maxValue_l)
    SET DATABASE PARAMETER($table_p->;Table Sequence Number;$maxValue_l+1)
End if