Use sys(2015) instead.
From help: "SYS(3) may return a non-unique name when issued successionally on a fast computer. Use SUBSTR(SYS(2015), 3, 10) to create unique, legal eight character file name."
If you don't need a valid 8-character filename, it is better to use the entire 10 bytes.
Better yet, use GUIDs (16-bytes).
If all users are connected all the time, it is much simpler to create an auto-incremented value, with a table holding the next value to be used.
HTH, Hilmar.
>I am trying to generate and capture a unique id using the sys3 command. Once a id is created it checks a table that holds all the previous id's that were generated, if the id is found in the table already, then continue with process until it comes across one that doesnt match and then write to the table. Is this code accomplishing this? I am finding duplicate records in my Keytable.dbf.
>
>PARAMETERS mOdeType, pk_find
>
>*LOCAL m.pk_find
>
>m.pk_find = .F.
>
>IF !USED('KEYTABLE')
> USE (oVar.SysPath) + 'KEYTABLE.dbf' IN 0 SHARED
>ENDIF
>
>SELE KEYTABLE
>GO TOP
>
>*!* SET MULTILOCKS ON
>=CURSORSETPROP("BUFFERING",5)
>
>
>DO WHILE m.pk_find = .F.
> oVar.KeyId = SYS(3)
>
> SELE KEY_ID FROM KEYTABLE ;
> WHERE ALLT(KEYTABLE.KEY_ID) == ALLT(oVar.KeyId) ;
> INTO CURSOR PkIdFound
>
> SELE PkIdFound
> IF RECCOUNT() > 0 && PK ID FOR THIS PARTICULAR TABLE EXIST....LOOP
> m.pk_find = .F.
> LOOP
> ELSE
> m.pk_find = .T.
> DO CASE
> CASE ALLT(UPPER(mOdeType)) == 'UPDATE VTRANS'
> INSERT INTO KEYTABLE (KEY_ID, HTC_PROC) VALUE (oVar.KeyId, 'VTRANS UPDATE')
>
> CASE ALLT(UPPER(mOdeType)) == 'PRINT REPORTS'
> INSERT INTO KEYTABLE (KEY_ID, HTC_PROC) VALUE (oVar.KeyId, 'PRINT REPORTS')
>
> ENDCASE
>
> SELE KEYTABLE
> =TABLEUPDATE(.T.)
> ENDIF
>ENDDO
>
>RETURN
Difference in opinions hath cost many millions of lives: for instance, whether flesh be bread, or bread be flesh; whether whistling be a vice or a virtue; whether it be better to kiss a post, or throw it into the fire... (from Gulliver's Travels)