Hi Tommy
Generally such a design involves a table with multiple records, allowing you to generate unique keys for different purposes.
It would be called like this
lnSaleNo = GetNextNumber("SALES")
Then you'd need an RLOCK(). I would not use flock unless absolutely needed. If you had multiple unique keys being generated you would create a logjam locking the whole table.
I made some changes below as well.
>Hi Gang!
>
>We used to have a record in a table for EACH lane of a drug store (each register, that is). Each record had a field to track the sales number for THAT register (lane). So, you could have multiple duplicate sales numbers in the drug store over a period of time.
>
>They didn't like that ( I didn't either ), so I was tasked to code up a solution so there would be UNIQUE sales numbers at that location (store). The registerrs would no longer look at the previous table, but would call a function to get a UNIQUE sales number for the store at THAT MOMENT in time. Here is what I came up with, ...
>
>SET REPROCESS TO AUTO is globally set at the beginning of the program.....
>
>
>FUNCTION GetNextSaleNumber
>LOCAL lnNextSaleNumber
>
>IF NOT USED('sales_no')
> USE IN 0 sales_no
>ENDIF
>*Lock the sales_no record to allow no one else to modifiy the last_sale value while I am updating it....
>IF RLOCK('sales_no')
> IF sales_no.last_sale = 999999
> REPLACE sales_no.last_sale WITH 1 IN sales_no
> ELSE
> REPLACE sales_no.last_sale WITH sales_no.last_sale + 1 IN sales_no
> ENDIF
> lnNextSaleNumber = sales_no.last_sale
>ELSE
> lnNextSaleNumber = -1
>ENDIF
>UNLOCK RECORD recno() IN sales_no
>RETURN lnNextSaleNumber
>
>
>Sales_no is a simple table with ONE record and ONE field in it. ( sales_no.last_sale ).
>
>And you would call it this way.... lnSaleNo = GetNextSaleNumber()
>
>Does this look ok? Should I do some error trapping in case something goes wroing ( a pc locks up during the function and LOCKS the sales_no table ) ??
>
>What else would you do?
>
>Thanks!