Field Type Contents cTableName C Upper case table name iNextID I The next key value to use for this tableMy key generation code is similar to this;
* Get the next available PK LPARAMETERS pcTable IF EMPTY(pcTable) * Fail, no table name passed RETURN -1 ENDIF pcTable = UPPER(pcTable) LOCAL lnId, lcAlias, lcOrder lcAlias = ALIAS() IF USED("SysId") SELECT SysId lcOrder = ORDER() ELSE SELECT 0 USE data\SysId lcOrder = "" ENDIF SET ORDER TO TableName SEEK pcTable IF NOT FOUND() INSERT INTO SysId (TableName, NextId) VALUES (pcTable,1) SEEK pcTable ENDIF DO WHILE NOT RLOCK() && Ok, locks only short ENDDO lnId = NextId REPLACE NextId WITH NextId + 1 UNLOCK IF NOT EMPTY( lcOrder ) SET ORDER TO &lcOrder ENDIF IF NOT EMPTY( lcAlias ) SELECT ( lcAlias ) ELSE SELECT 0 ENDIF RETURN lnId