sghatge
19th August 2013, 18:54
Dear Friends,

I am trying to insert record through AFS in items - routing (tirou1101m000) for new routing code "002" (Routing is already exist for code "001") but its inserting default routing withou filling item code. Please help me to resolve this. The code is as below.

select tcibd001.*
from tcibd001
where tcibd001.kitm in (1,2)
and tcibd001.item inrange {:item.f} and {:item.t}
and not exists (select 1 from tirou101 where tirou101.mitm = tcibd001.item and tirou101.opro = " 002")
selectdo
proj = tcibd001.item(1;9)
item = tcibd001.item(10;38)
stpapi.put.field("tirou1101m000", "tirou101.mitm.segment.1", proj)
stpapi.put.field("tirou1101m000", "tirou101.mitm.segment.2", item)
ret = stpapi.change.view("tirou1101m000", error)
if ret > 0 then
ret = stpapi.synchronize.dialog("tirou1101m000", "Add", error)
if ret then
stpapi.put.field("tirou1101m000", "tirou101.opro", " 002")
stpapi.put.field("tirou1101m000", "tirou101.dsca", "AFS - REVISED ROUTING")
stpapi.put.field("tirou1101m000", "tirou101.stor", str$(etol(tcyesno.no)))
stpapi.put.field("tirou1101m000", "tirou101.maru", str$(etol(tcyesno.no)))
ret = stpapi.insert("tirou1101m000", true, error)
if ret then
ret = stpapi.save("tirou1101m000", error)
endif
endif
endif
stpapi.end.session("tirou1101m000", error)

vinceco252
19th August 2013, 21:43
I am not sure, but after the change view fails, I think you may need to do the puts for the item again.

Vince

bhushanchanda
19th August 2013, 21:57
Hi,

Your profile says you are on LN. So, you can go with DAL too. That might be a simpler way.

Anyways, I found a similar AFS thread. I hope this helps:-

Thread 1 (http://www.baanboard.com/baanboard/showthread.php?t=26767)

And as Vince said, you might need to update the item field again.

A sample code snipplet:--

stpapi.put.field( "ticst0101m100", "ticst001.pdno", pdno)
ret = stpapi.change.view( "ticst0101m100", error1 )
stpapi.put.field( "ticst0101m100", "ticst001.pono", str$(pono) )
ret = stpapi.find( "ticst0101m100" , error1 )
if ret = 1 then
ret = stpapi.mark( "ticst0101m100" , error1 )
ret = stpapi.synchronize.dialog("ticst0101m100", "modify", err.mesg)

stpapi.enum.answer( "ticst0101m100", "ticst01011",tcyesno.yes )
stpapi.set.report("ticst0101m100", "rtisfc020701000", spool.device , error1)
stpapi.form.command( "ticst0101m100", 5, "initiate.inventory", error )
endif

stpapi.end.session( "ticst0101m100" , error1 )
stpapi.end.session( "ticst0101m100" , error1 )

sghatge
20th August 2013, 10:07
As suggested, i have tried, but not working. Anybody can correct my given code and help me.

Regards,

Shashikant

sghatge
20th August 2013, 10:53
It is very urgent. Anybody can help me to add the routing with item code. currently item code is taking as blank.

bhushanchanda
20th August 2013, 12:34
Hi,

Here's the working code. I tried it at my end and works perfectly.

select tcibd001.*
from tcibd001
where tcibd001.item(10;5) = "TESTI" | I am trying to insert Routing Data for "TESTING". This is not needed, but I have just used a similar loop.
selectdo



stpapi.put.field("tirou1101m000", "tirou101.mitm.segment.1", tcibd001.item(1;9))
stpapi.put.field("tirou1101m000", "tirou101.mitm.segment.2", tcibd001.item(10;38))
error = get.string.arg(1)
ret = stpapi.change.view( "tirou1101m000", error )
put.string.arg(1, error)
if ret = 0 then
ret = stpapi.synchronize.dialog("tirou1101m000", "add", error)
if ret then
stpapi.put.field("tirou1101m000", "tirou101.opro", "100")
stpapi.put.field("tirou1101m000", "tirou101.dsca", "TESTING ROUTING")
stpapi.put.field("tirou1101m000", "tirou101.stor", str$(etol(tcyesno.no)))
stpapi.put.field("tirou1101m000", "tirou101.maru", str$(etol(tcyesno.no)))
ret = stpapi.insert("tirou1101m000", true, error)
if ret then
ret = stpapi.save("tirou1101m000", error)
endif
endif
endif
stpapi.end.session("tirou1101m000", error)

endselect

Hope this helps.

mark_h
20th August 2013, 15:34
I got to ask - what is with the synchronize dialog? If it needs that then why wouldn't you be putting the fields on the synchronized form - then doing the insert on the main form.

The most important thing I would do is check the value for stpapi.changeview - if the return value is anything but 1 then I would definetly put all the fields again to make sure the item was correct. Then again I am on 4c4. I could probably just put all the fields and do an insert without the change.view - not always, but usually.


stpapi.put.field("dtfsa1501m000", "dtfsa101.seno", str$(i.seno))
ret = stpapi.find("dtfsa1501m000", error.msg)
if ret then
ret = stpapi.synchronize.dialog("dtfsa1501m000", "modify", error.msg)
if ret then
stpapi.put.field("dtfsa1101s000", "dtfsa101.name", new.name)
ret = stpapi.update("dtfsa1501m000", true, error.msg)
endif
endif

bhushanchanda
20th August 2013, 19:46
Hi Mark,

I am not into AFS much as I use DAL when required. I just did a bit trial and errors and got the result.

Well,in one of the thread (referred your post) I learnt about stpapi.find replacing stpapi.change.view and I have used that too. Which gives solution as well. A bit change to your script will do the job.

In this case, stpapi.find return's 0. So the other working code will be:-

select tcibd001.*
from tcibd001
where tcibd001.item(10;5) = "TESTI"
selectdo


error = tcibd001.item(1;9)
error = tcibd001.item(10;38)
stpapi.put.field("tirou1101m000", "tirou101.mitm.segment.1", tcibd001.item(1;9))
stpapi.put.field("tirou1101m000", "tirou101.mitm.segment.2", tcibd001.item(10;38))

ret = stpapi.find("tirou1101m000", error)
if ret = 0 then
ret = stpapi.synchronize.dialog("tirou1101m000", "add", error)
if ret then
stpapi.put.field("tirou1101m000", "tirou101.opro", "100")
stpapi.put.field("tirou1101m000", "tirou101.dsca", "TESTING ROUTING")
stpapi.put.field("tirou1101m000", "tirou101.stor", str$(etol(tcyesno.no)))
stpapi.put.field("tirou1101m000", "tirou101.maru", str$(etol(tcyesno.no)))
ret = stpapi.insert("tirou1101m000", true, error)
if ret then
ret = stpapi.save("tirou1101m000", error)
endif
endif
else
message("Record exists!") | This can be excluded.
endif
stpapi.end.session("tirou1101m000", error)

endselect

So, two solutions now, I hope he will get this :) If any mistakes, Mark please correct me.

mark_h
21st August 2013, 00:36
I think either of the solutions should work. The only think I think they need to be aware of is if it finds a different item or view. Then they might need to re-put the item for the insert. The only other thing that might cause an issue is the session version or stpapi libraries are different. I have seen those cause issues. On a session like this you would think it would be simple, but that is not always the case.

bhushanchanda
21st August 2013, 05:41
Agreed Mark. The best way is to write your code, put it under debugger, check return values for evry function and check the results. Accordingly, the changes should be made in the script where required.

Patience is the key to succeess!

zhilenko_myu
17th October 2022, 03:51
Hi,

Here's the working code. I tried it at my end and works perfectly.

select tcibd001.*
from tcibd001
where tcibd001.item(10;5) = "TESTI" | I am trying to insert Routing Data for "TESTING". This is not needed, but I have just used a similar loop.
selectdo



stpapi.put.field("tirou1101m000", "tirou101.mitm.segment.1", tcibd001.item(1;9))
stpapi.put.field("tirou1101m000", "tirou101.mitm.segment.2", tcibd001.item(10;38))
error = get.string.arg(1)
ret = stpapi.change.view( "tirou1101m000", error )
put.string.arg(1, error)
if ret = 0 then
ret = stpapi.synchronize.dialog("tirou1101m000", "add", error)
if ret then
stpapi.put.field("tirou1101m000", "tirou101.opro", "100")
stpapi.put.field("tirou1101m000", "tirou101.dsca", "TESTING ROUTING")
stpapi.put.field("tirou1101m000", "tirou101.stor", str$(etol(tcyesno.no)))
stpapi.put.field("tirou1101m000", "tirou101.maru", str$(etol(tcyesno.no)))
ret = stpapi.insert("tirou1101m000", true, error)
if ret then
ret = stpapi.save("tirou1101m000", error)
endif
endif
endif
stpapi.end.session("tirou1101m000", error)

endselect

Hope this helps.

bhushanchanda, Thanks. Here it works. I suffered for a week with tirou1101m000

zhilenko_myu
1st November 2022, 03:47
hello.
I do like this.
but if the error is in the product, then the AFS does not issue it. for example, there is no cost per product.


session = "tdsls4101m000"

stpapi.put.field(session, "tdsls401.orno", orno.o)
error.msg = get.string.arg(1)
retval = stpapi.change.view(session, error.msg)
put.string.arg(1, error.msg)
if retval = 0 then
retval = stpapi.synchronize.dialog(session, "add", error.msg)
session1 = "tdsls4101m000"
if retval then
stpapi.put.field(session1, "tdsls401.item.segment.1", "")
| stpapi.put.field(session1, "tdsls401.item.segment.2", itep(1;38))|#ZMU-20221031.o
stpapi.put.field(session1, "tdsls401.item.segment.2", item.i(1;38))

select *
from zazir101
where zazir101.onum = :onum.i
selectdo
effn.i = zazir101.effn
endselect
stpapi.put.field(session1, "tdsls401.effn", str$(effn.i))
stpapi.put.field(session1, "tdsls401.cprj", cprj.i)
stpapi.put.field(session1, "tdsls401.cact", "1")
stpapi.put.field(session1, "tdsls401.qoor", "1")
| stpapi.put.field(session1, "tdsls401.odat", str$(ddat))
stpapi.put.field(session1, "tdsls401.stbp", stbp)
stpapi.put.field(session1, "tdsls401.stad", ofad)
stpapi.put.field(session1, "tdsls401.pric", "10000")
stpapi.put.field(session1, "tdsls401.oamt", "10000")
stpapi.put.field(session1, "tdsls401.ccty", "1")
stpapi.put.field(session1, "tdsls401.cvat", cvat)
retval = stpapi.insert(session1, true, error.msg)
if not isspace(error.msg) then
print.errors(
"1",
session1,
error.msg,
trim$(item.i),
orno.o)

endif
if retval then
session2 = "tdsls4830s000"
stpapi.put.field(session2, "inventory.short", str$(etol(tdsls.ssop.no.action)))
stpapi.end.session (session2, error.msg)
retval = stpapi.save(session1, error.msg)
if not isspace(error.msg) then
print.errors(
"2",
session1,
error.msg,
trim$(item.i),
orno.o)

endif
endif
endif
endif
stpapi.end.session(session1, error.msg)

stpapi.end.session(session, error.msg)