Neal Matthews
3rd April 2010, 14:21
Hello can anyone spot what I'm doing wrong in the code below. Thanks Neal

I have 2 records in tdpsc964. The first record is added ok to tdpsc965 but the second record isn't added and then the script fails with error 100 duplicates.

select tdpsc964.date,tdpsc964.lotn,tdpsc964.flg1,tdpsc964.user,tdpsc964.time from tdpsc964
where tdpsc964._index1 = {:m_date1}
selectdo
|if tdpsc964.flg1(1;2) <> "OK" then
|*Set memvars and get other info from asn inbound file tdpsc961
m_date2=tdpsc964.date
m_time=tdpsc964.time
m_user=tdpsc964.user
m_lotn=tdpsc964.lotn

|* Check lot not already in tdpsc965
db.retry.point()
select tdpsc965.lotn,tdpsc965.date,tdpsc965.time,tdpsc965.user from tdpsc965
for update
where tdpsc965._index2 = {:tdpsc964.lotn}
selectdo
m_flag="LOT ALREADY SCANNED"
selectempty
tdpsc965.date=m_date2
tdpsc965.time=m_time
tdpsc965.user=m_user
tdpsc965.lotn=m_lotn
message(m_lotn)
message(m_date2)
message(m_time)
db.insert(ttdpsc965,db.retry)
commit.transaction()
m_flag="OK"
endselect


|Mark 964 as OK
|db.retry.point()
|db.eq(ttdpsc964,db.lock)
|tdpsc964.flg1 = m_flag
|db.update(ttdpsc964,db.retry)
|count = 0
|FOR count = 1 TO 50 STEP 1
| if count = 50 then
| commit.transaction()
| endif
|ENDFOR
|endif
endselect

mark_h
3rd April 2010, 16:04
What are all the indexes on tdpsc964? Do the secondary indexes allow duplicates? To me it looks like the records could be a duplicate record based off index1.

Neal Matthews
4th April 2010, 00:05
Cheers Mark (I was hoping you were around !) you pointed me in the right direction.

My third index on tdpsc965 (which I forgot I'd added) was on date + item. As the item field has yet to be populated this was therefore the same date and blank item for each record.

Thanks again.
Neal