ltannous
27th February 2004, 21:24
I have created a table similar to tdpur041 (purchase order lines)
I have an index on orer number and postion number.
I want to update my table with information from the purchase order lines.
When I execute the session, it only writes the last postion number, another error is that there has to be data in the record in order for me to update it.
Any suggestions:

form.all:
init.form:
get.screen.defaults()

zoom.from.all:
on.entry:
import("wtpur041.orno", hold.orno)
wtpur041.orno = hold.orno

choice.cont.process:
on.choice:
read.main.table()

functions:

function read.main.table()
{
long count
db.retry.point()

select tdpur041.*
from tdpur041
where tdpur041.orno = :hold.orno
selectdo

select wtpur041.*
from wtpur041 for update
where wtpur041.orno = :tdpur041.orno
order by wtpur041.orno
selectdo

|update set
display("wtpur041.orno")
refresh()

wtpur041.pono = tdpur041.pono
wtpur041.item = tdpur041.item
wtpur041.dim4 = tdpur041.dim4
db.update(twtpur041,db.retry)
count = count + 1
if count > 50 then
count = 0
endif
commit.transaction()
endselect
commit.transaction()
endselect
message("Session Completed")

exit()


}

nneilitz
27th February 2004, 23:09
You want to use an "insert statement" for inserting records (whether you need to leave update their depends if you want the session to update existing wtdpur041 records"). Add in pono into select for wtdpur041 or better yet use index reference

function read.main.table()
{
long count
db.retry.point()

select tdpur041.*
from tdpur041
where tdpur041.orno = :hold.orno
selectdo


select wtpur041.*
from wtpur041 for update
where wtpur041.orno = :tdpur041.orno
and wtdpur041.pono = :tdpur041.pono
order by wtpur041.orno
selectdo

|update set
display("wtpur041.orno")
refresh()

wtpur041.pono = tdpur041.pono
wtpur041.item = tdpur041.item
wtpur041.dim4 = tdpur041.dim4
db.update(twtpur041,db.retry)
count = count + 1
if count > 50 then
count = 0
endif
selectempty
wtpur041.pono = tdpur041.pono
wtpur041.item = tdpur041.item
wtpur041.dim4 = tdpur041.dim4
db.insert(twtpur041)

endselect
commit.transaction()



endselect | For outer select
message("Session Completed")

exit()

ltannous
27th February 2004, 23:57
That worked.