tianalita
24th October 2001, 17:03
hi,

I'd like to simulate the session tdilc1120m000 by using tha API.

I want to insert a new record and i always obtain an error message : " the record already exists" = err

My script is:

stpapi.put.field("tdilc1120m000","tdinv100.item","Ref_article")
stpapi.put.field("tdilc1120m000","tdinv100.cwar","Mag")
stpapi.put.field("tdilc1120m000","tdinv100.sern","1")
stpapi.put.field("tdilc1120m000","tdinv100.kowt","5")
stpapi.put.field("tdilc1120m000","tdinv100.comp","200")
stpapi.put.field("tdilc1120m000","tdinv100.pqan","1")

stpapi.insert("tdilc1120m000",1,err)

stpapi.update("tdilc1120m000",1,err)

stpapi.save("tdilc1120m000",err)

stpapi.end.session("tdilc1120m000")

Please help me

mark_h
24th October 2001, 19:36
I do not think you need the sern field. If you try to do the same part multiple times on the say date you would get the error you mention. I do not use this field in my inventory adjustment FS. Remove this line and try again:
stpapi.put.field("tdilc1120m000","tdinv100.sern","1")


Good Luck!

gfasbender
24th October 2001, 20:16
As a good practice, I always try to use the find function to control an insert or update process. Then you don't have to worry when processing the same input data multiple times.

If you only plan on processing the data once, then Mark is correct in removing the sern put.

|* put key fields
rc = stpapi.find(api.session)
if rc = 1 then
api.err.msg = "Record already exists"
return
endif

|* Put key fields again plus the rest
stpapi.insert(api.session, 1, api.err.msg)
if not isspace(api.err.msg) then
return
endif

mark_h
25th October 2001, 23:49
Gordons message and email reminded me of another problem which you may not have thought about with this session. When you process an inventory adjustment I believe a subsession will pop up and require info. If the transaction fails in this case you will need to drop back to the tdilc1120m000 session and delete the original transaction. If you do not do this you could end up with a bunch of transactions that are not closed.

On a side note I see that Gordon is available for work (from his post in the job forum) and I can tell you that he is an expert in the programming arena. And he developed several DDC function servers that are still in use by the company I work for.

Good Luck!!!!

Mark

tianalita
29th October 2001, 10:14
It works very well

tianalita
29th October 2001, 11:10
I have a problem on subsession
it doesn't work

my syntax is :

stpapi.put.field("tdilc1120m000","tdinv100.item","article")
stpapi.put.field("tdilc1120m000","tdinv100.cwar","PA1")
stpapi.put.field("tdilc1120m000","tdinv100.kowt","5")
stpapi.put.field("tdilc1120m000","tdinv100.comp","200")
stpapi.put.field("tdilc1120m000","tdinv100.pqan","1")

stpapi.insert("tdilc1120m000",1,err)

stpapi.update("tdilc1120m000",1,err)

stpapi.save("tdilc1120m000",err)

stpapi.handle.subproc("tdilc1120m000","tdilc1121s000","add")

stpapi.put.field("tdilc1121s000","tdilc102.clot","001013000294")
stpapi.put.field("tdilc1121s000","tdilc102.qstk","1")

stpapi.update("tdilc1121s000",1,err)

stpapi.save("tdilc1121s000",err)

stpapi.end.session("tdilc1121s000")

stpapi.handle.subproc("tdilc1120m000","tdilc1121s000","kill")

stpapi.end.session("tdilc1120m000")


Help me please







Originally posted by mark_h
Gordons message and email reminded me of another problem which you may not have thought about with this session. When you process an inventory adjustment I believe a subsession will pop up and require info. If the transaction fails in this case you will need to drop back to the tdilc1120m000 session and delete the original transaction. If you do not do this you could end up with a bunch of transactions that are not closed.

On a side note I see that Gordon is available for work (from his post in the job forum) and I can tell you that he is an expert in the programming arena. And he developed several DDC function servers that are still in use by the company I work for.

Good Luck!!!!

Mark

mark_h
29th October 2001, 16:28
I see a lot of things I am not sure about. What I have done is attached a copy of my inventory adjustment library. I always use ttstpcreatdll on the sessions just to see what kind of commands I get. So you can compare my code against your code and see if you can get it working. Just keep in mind that my code was for an A&D system so I stripped the pegging lines out - at least I think so.

A couple of things I see right offhand are that the quantity fields should be passed as strings. And the transaction type should be tckowt.stc.correction and not "5". On the 1120 session you do an insert, update and save. My code only does an insert and then a continue. Anyway compare my code to yours and see if that helps you out.

Good Luck!!

Mark