cherokee
16th February 2005, 16:38
Hello everyone,

I want to insert some Item Codes by Item Code System but this session (tiitm0112m00) gives this error "Record Already Exists".. which isn't.


.....
select tiitm012.*
from tiitm012
where tiitm012._index1 = {:citt,:dummy.cuno,:suno,:tiitm001.item,:dummy.cntr}
selectdo
selectempty
stpapi.put.field("tiitm0112m000","tiitm012.citt",citt)
stpapi.put.field("tiitm0112m000","tiitm012.cuno","")
stpapi.put.field("tiitm0112m000","tiitm012.suno",suno)
stpapi.put.field("tiitm0112m000","tiitm012.item",tiitm001.item)
stpapi.put.field("tiitm0112m000","tiitm012.cntr","")
stpapi.change.view("tiitm0112m000")
stpapi.put.field("tiitm0112m000","tiitm012.citt",citt)
stpapi.put.field("tiitm0112m000","tiitm012.cuno","")
stpapi.put.field("tiitm0112m000","tiitm012.suno",suno)
stpapi.put.field("tiitm0112m000","tiitm012.item",tiitm001.item)
stpapi.put.field("tiitm0112m000","tiitm012.cntr","")
stpapi.put.field("tiitm0112m000","tiitm012.aitc",aitc)
stpapi.insert("tiitm0112m000",true, err.mesg) |it returns ("Record already Exists")
if not isspace(err.mesg) then
stpapi.recover("tiitm0112m000",err.mesg)
endif
stpapi.end.session("tiitm0112m000")
endselect

Any idea what can be the problem?

Thanks in advance.

Carlos :confused:

Juergen
16th February 2005, 17:41
Hi Carlos,

did you try to check the return value for stpapi.change.view(...)?

If the function returns 1 (view found) then the header fields has not to be set again with stpapi.put.field(...).

Juergen

cherokee
16th February 2005, 17:51
Hi Juergen,

I changed like this (below here) and it finds it and returns 1 but gives another error... "Item Not allowed"

...stpapi.put.field("tiitm0112m000","tiitm012.citt",citt)
stpapi.put.field("tiitm0112m000","tiitm012.cuno","")
stpapi.put.field("tiitm0112m000","tiitm012.suno",suno)
stpapi.put.field("tiitm0112m000","tiitm012.item",tiitm001.item)
stpapi.put.field("tiitm0112m000","tiitm012.cntr","")
if stpapi.change.view("tiitm0112m000") <> 1 then
stpapi.put.field("tiitm0112m000","tiitm012.citt",citt)
stpapi.put.field("tiitm0112m000","tiitm012.cuno","")
stpapi.put.field("tiitm0112m000","tiitm012.suno",suno)
stpapi.put.field("tiitm0112m000","tiitm012.item",tiitm001.item)
stpapi.put.field("tiitm0112m000","tiitm012.cntr","")
endif
stpapi.put.field("tiitm0112m000","tiitm012.aitc",aitc)
stpapi.insert("tiitm0112m000",true, err.mesg)
if not isspace(err.mesg) then
stpapi.recover("tiitm0112m000",err.mesg)

Juergen
16th February 2005, 18:08
Hello Carlos,

sounds not good.

Are you able to insert the record for which you receive the error manually with session tiitm0112m000.

Juergen

cherokee
16th February 2005, 18:14
Juergen,

Yes, trough the session manually it is possible, but if I try this code below here... doesn't it. it goes back to the retry.point() ...since can't insert. I just noticed it is happening with one Item, I might have a problem with the table index.

db.retry.point()
db.set.to.default(ttiitm012)
tiitm012.citt = citt
tiitm012.suno = suno
tiitm012.item = tiitm001.item
tiitm012.aitc = aitc
db.insert(ttiitm012, db.retry)
commit.transaction()

Thanks,

Carlos :cool:

cherokee
16th February 2005, 20:04
Hey guys ... I found the problem.

The aitc value it is a part of index 2 which is only citt,cuno,suno,aitc. Index 1 is citt,cuno,suno,item,cntr. So, by checking if exists in index1 doesn't warranty that won’t be a duplication in another index.

BTW, the testing I did manually (entering through the session), I did not bother to enter the exact aitc code(left blank) that is why it did work.

Sorry about that, I should battled bit harder this one before post it... hope this will help someone else….

Thanks again,

Carlos
;)