Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
FLOCK and Unique Sales Numbers
Message
From
24/06/2014 10:24:16
 
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Environment versions
Visual FoxPro:
VFP 9 SP1
OS:
Windows XP SP3
Network:
Windows 2003 Server
Database:
Visual FoxPro
Application:
Desktop
Miscellaneous
Thread ID:
01602280
Message ID:
01602293
Views:
44
>>>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 table to allow no one else to modifiy the last_sale value while I am updating it....
>>>IF FLOCK('sales_no')
>>>	SELECT sales_no
>>>	IF sales_no.last_sale = 999999
>>>		REPLACE sales_no.last_sale WITH 1
>>>	ELSE 
>>>		REPLACE sales_no.last_sale WITH sales_no.last_sale + 1
>>>	ENDIF 
>>>	lnNextSaleNumber = sales_no.last_sale
>>>ELSE
>>>	lnNextSaleNumber = -1	 
>>>ENDIF
>>>SELECT sales_no
>>>UNLOCK    
>>>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!
>>
>>One thing that doesn't look ok, is when you fail to lock the table, you return -1
>>
>>You should at least do a number of attemps to lock the table, imo
>
>I thought that was the purpose of the SET REPROCESS TO AUTOMATIC.
>
>The FLOCK would continue to try and LOCK the record infinitum until the cows come home... or until the record is UNLOCKED by the other register that has it LOCKED.


OK
Gregory
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform