Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How can I prevent Duplicate Bill No in my app. ?

Status
Not open for further replies.

rskomal

Programmer
Feb 2, 2003
13
IN
I use the following to obtain last bill no from a dbf


sele Bill_book
set order to 1 // index on str(bill_no,7) to bill_1

set filt to bill_no = mbill_no
go bott
store bill_no + 1 to mbill_no
set filt to


Now when I call the save routine, I check for duplicate bill_no :-

Do Case
Case choice = "S"

sele bill_book
seek str(mbill_no,7)

if Found()
Alert("Sorry Can't Save, Duplicate !!!")
.....
Else
Save_Data()
.....
endif

EndCase
....
....

But sometime ( I don't know how ) program assigns duplicate bill_no and overwrite previous (same) bill No.
When our a/c deptt. reports two bills having same bill no it looks...

Is there any other reason for this?

Please help and suggest the best way to assign unique no.

Thanks.

 
R u woking in a network environment?

Will more than one user try to save data at a time?

Durai.
 
Rskomal,
A couple of things:
What is the origional mbill_no that you set to filter to? Since you do not know what the last record is how do you get this value? I would expect not to set a filter as it can really slow things down and all that you want is the highest existing bill number so it's not needed.

When you get the last bill number, add 1 and store it to mbill_no what do you do next? If you are in a multiuser system then somebody else could have grabbed that number and used it.

What you need to do is create the bill_book record, enter the new number in the bill_no field and do a dbcommit() so that others will then see that record and add the correct next number.

Try to forget about selecting areas and use an alias, it makes things so much more readable. It might take a bit more typing but in 6 months time when things are not as fresh in you mind it really helps.
A solution might look something like this:

bill_book->(dbsetorder(1)) // index on str(bill_no,7) to bill_1
bill_book->(dbgobottom())
mbill_no := bill_book->bill_no

//Add the record here
bill_book->(addrec(5)) //from Locks5 Clipper net prog
bill_book->bill_no := mbill_no
bill_book->(dbcommit()) // so others can see on network

Do Case
Case choice = "S"
if bill_book->(dbseek(str(mbill_no,7))) // it's mine
//Alert("Sorry Can't Save, Duplicate !!!")
//Add your data here
save_data()
.....
Else
// why no record?
.....
endif
EndCase

Hope this helps, good luck

Ian Boys
DTE Systems Ltd
 
Dear Ian Boys

This app. is not multiuser so there is no other user who can save in the mean time. Secondly I know filter is quite slow but the problem is that my database contain bill nos for Sale, Purchase, Mtrl. Issue, Mtrl. Recd... so I have to use filter command. If any other alternate please do suggest.(but this app contain only Sales bill )

Your code looks a bit more sophisticated I think they will work. Thanks.

This application is running succesfully since last 3 months but 3/4 days ago it generated two bills having same bill no thats why I was asking for that ...




 
What is the mbill_no used in the origional filter? I can't work out quite how that works. How do Sale, Purchase, Mtrl. Issue, Mtrl. Recd... bill_numbers differ?

How about using a memory variable saved to disk. You can then use several different files for other types of bills.

if file('bill_no.mem')
restore from bill_no additive
mbill_no++
save all like mbill_no to bill_no.mem
else
mbill_no := 10000 // a start number
save all like mbill_no to bill_no.mem
endif

The other option is to do a soft seek on a ceiling number, for example if all of a certain type of bill are <100000, do a dbseek(99999,.T.) and then dbskip(-1) and add 1 to that bill_no





Ian Boys
DTE Systems Ltd
 
rskomal,

To store bill no. in .memDBF file is the best way as said by Ian Boys.

Durai.

 

possible explainations on HOW your problem happened...

* your index file may be corrupted and therefor doesn't 'see' other records. Try rebuilding the index file



 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top