mig28mx
3rd June 2008, 18:46
Hello all,
I need to implement an automatic sequence when a record is inserted into a table.
Seq Record
10 1
20 2
It is like the venerable program gwbasic when auto line was selected.
Any ideas?
thank you in advance.
mark_h
3rd June 2008, 20:27
I do not do anything fancy - I just look for the max for the key. In the below example it returns 1 for a new key or it returns max+1 for existing key. Nothing hard and there might be a better answer, but this is how we have done it.
function long get.next.tpppc291.sern(domain tppdm.cprj someprj)
{
long max.sern
select max(tpppc291_1.sern):max.sern
from tpppc291 tpppc291_1
where tpppc291_1._index1 = {:someprj, :tpppc291.cico}
selectdo
max.sern = max.sern + 1
selectempty
max.sern = 1
endselect
return(max.sern)
}
mig28mx
4th June 2008, 01:30
Hello Mark,
Thanks for your help.ยด
Sorry to ask, but how can I add you code to my existing table?
Perhaps use add.set option?
Regards
mark_h
4th June 2008, 02:36
Here is an example - Item is the main findex field on the table. The second field is build quantity.
field.tiudi017.bqty:
before.input:
if update.status = add.set then
read.serial.number()
search.last.used.seqn.on.screen()
tiudi017.etry = serial.number + 1
display("tiudi017.etry")
refresh()
update.occ()
endif
| Get max from table
function read.serial.number()
{
serial.number = 0
select max(a.etry):serial.number
from tiudi017 a
where a._index1 = {:tiudi017.mitm }
as set with 1 rows
selectdo
endselect
}
| Check highest used on the screen.
function search.last.used.seqn.on.screen()
{
long occ.no
for occ.no = 1 to (filled.occ - 1)
do.occ(occ.no,check.last.used.sern)
endfor
}
function check.last.used.sern()
{
if tiudi017.etry > serial.number then
serial.number = tiudi017.etry
endif
}
At least this seems to work.
mig28mx
4th June 2008, 18:20
Hello Mark,
Thank you for your help!
Regards.