sgoupil
29th September 2015, 22:58
Hey guys, I've look around and got some very good help for that AFS, but I'm getting into a problem that I did not find any post for it. The AFS hangs forever when I try to end tdilc4113s000. Here is my code. Any idea? BaanIVc4, SP32

| Create Receipts
stpapi.handle.subproc("tdpur4120m000", "tdpur4224s000", "add")
stpapi.put.field("tdpur4120m000", "form.dino", str$(f.pacn))
ret.v = stpapi.change.view("tdpur4120m000")
stpapi.put.field("tdpur4224s000", "form.orno", str$(keep.orno))
stpapi.continue.process("tdpur4224s000", p.error.code )
stpapi.end.session("tdpur4224s000")
stpapi.get.field("tdpur4120m000", "tdpur045.reno", hold.reno)
stpapi.end.session("tdpur4120m000")

| Modify receipt
boi.call = "tdboidll0011.Create"
stpapi.put.field("tdpur4120m000", "tdpur045.reno", str$(hold.reno))
stpapi.put.field("tdpur4120m000", "tdpur045.orno", str$(keep.orno))
stpapi.put.field("tdpur4120m000", "tdpur045.pono", str$(keep.pono))
r = stpapi.find("tdpur4120m000", p.error.code)
if r = 1 then
if tiitm001.kltc <> tckltc.none then
stpapi.handle.subproc("tdpur4120m000", "tdilc4113s000", "add")
endif
stpapi.put.field("tdpur4120m000", "tdpur045.diqu", str$(f.oqua))
stpapi.put.field("tdpur4120m000", "tdpur045.date", str$(receipt.date))
if tiitm001.kltc <> tckltc.none then
stpapi.put.field("tdpur4120m000", "tdpur045.dqua", str$(f.oqua))
endif
stpapi.update("tdpur4120m000", 1, p.error.code) |update
if not isspace(p.error.code) then
message(p.error.code")
stpapi.end.session("tdilc4113s000")
stpapi.end.session("tdpur4120m000")
else
if tiitm001.kltc <> tckltc.none then
stpapi.put.field("tdilc4113s000", "tdilc402.clot", str$(f.clot))
stpapi.put.field("tdilc4113s000", "tdilc402.date", str$(receipt.date))
stpapi.put.field("tdilc4113s000", "tdilc402.stun", str$(f.cuni))
stpapi.put.field("tdilc4113s000", "tdilc402.qstr", str$(f.oqua))
stpapi.insert("tdilc4113s000", 1, p.error.code) |update
if not isspace(p.error.code) then
message("p.error.code")
stpapi.end.session("tdilc4113s000")
else
stpapi.end.session("tdilc4113s000") |||| Hangs here
endif
endif

else
p.error.code = "Receipt not found"
message("p.error.code")
endif
stpapi.end.session("tdpur4120m000")

sgoupil
29th September 2015, 23:04
Please see attachment, a lot more readable. Thanks.

bhushanchanda
30th September 2015, 09:44
Hi,

To format your code, you can add code tags around it.

At which point does the session hangs? I can see you have couple of end.session() for that session.

Also, have a look at this - > thread (http://www.baanboard.com/baanboard/showthread.php?t=66581)

sgoupil
30th September 2015, 15:39
Hello Bhushan,

IT hangs when I try to end tdilc4113s000. If you look at the code, at the right I have a comment saying where it hangs.

bhushanchanda
30th September 2015, 15:45
Yes, somehow missed that comment. Unfortunately, I can't try this as I don't have this session in my environment. Probably someone else can try. One question, can you debug the code and check the process browser when that statement is executed? There might be some other session still running/not killed. In that case, you might need to use suspend() after every end.session() to make sure the session is destroyed before going forward.

Also, there are scenarios where you might need to execute end.session() 2 times.

mark_h
30th September 2015, 16:07
My code is a little different from yours. Bhushan is correct - you might want to put in debug mode and make sure the parent process ID is tdilc4120m000. Sometimes when a session hangs on the end you really do not have control of it. Also note - my code may not work on your system. There could be difference in the session or in the libraries themselves. I believe we are on SP32 or SP33 - this code works. I create the receipt in a different routine.

Here is my routine:


function extern modify_receipt( domain tcrcno receipt.number,
domain tcorno purchase.order,
domain tcpono purchase.line,
domain tcqiv1 packingslip.qty,
domain tcqiv1 received.qty,
domain tcdate received.date,
domain tdltc.clot purchase.lot,
domain tcdate purchaselot.date,
domain tcconv conv.factor,
domain tccuni purchase.unit,
domain tcitem purchase.item,
ref string msg())
{
string dummy(6), error_code(16)
domain tcorno get.orno
domain tcpono get.pono

select tiitm001.stgu, tiitm001.kitm
from tiitm001
where tiitm001._index1 = {:purchase.item}
as set with 1 rows
selectdo
endselect

msg = ""
boi.call = "tdboidll0011.Create"
stpapi.put.field("tdpur4120m000","tdpur045.reno",str$(receipt.number))
stpapi.put.field("tdpur4120m000","tdpur045.orno",str$(purchase.order))
stpapi.put.field("tdpur4120m000","tdpur045.pono",str$(purchase.line))
rc = stpapi.find("tdpur4120m000",msg)
if not isspace(msg) or rc<>1 then
stpapi.end.session("tdpur4120m000")
return
endif
stpapi.get.field("tdpur4120m000","tdpur045.orno",dummy)
get.orno = val(dummy)
stpapi.get.field("tdpur4120m000","tdpur045.pono",dummy)
get.pono = val(dummy)
| Prepare to handle lot controlled items.
if ((not isspace(purchase.lot) or conv.factor>1 or purchase.unit <> tiitm001.stgu)
and (tiitm001.kitm=tckitm.purchase or tiitm001.kitm = tckitm.manufacture)) then
stpapi.handle.subproc("tdpur4120m000","tdilc4113s000","add")
endif

stpapi.put.field("tdpur4120m000","tdpur045.diqu",str$(packingslip.qty))
stpapi.put.field("tdpur4120m000","tdpur045.date",str$(received.date))
stpapi.put.field("tdpur4120m000","tdpur045.dqua",str$(received.qty))
rc = stpapi.update("tdpur4120m000",1,msg)
if not isspace(msg) or rc<>1 then
if not isspace(purchase.lot) or conv.factor>1 then
stpapi.end.session("tdilc4113s000")
endif
stpapi.end.session("tdpur4120m000")
return
endif

| Need to handle the conversion factor.
if ((not isspace(purchase.lot) or conv.factor>1 or purchase.unit <> tiitm001.stgu)
and (tiitm001.kitm=tckitm.purchase or tiitm001.kitm = tckitm.manufacture)) then
stpapi.put.field("tdilc4113s000", "tdilc402.clot",purchase.lot)
stpapi.put.field("tdilc4113s000", "tdilc402.date",str$(purchaselot.date))
stpapi.put.field("tdilc4113s000", "tdilc402.qstr",str$(received.qty*conv.factor))
stpapi.put.field("tdilc4113s000", "tdilc402.qstc",str$(received.qty*conv.factor))
rc = stpapi.insert("tdilc4113s000",1,msg)
error_code = stpapi.get.mess.code("tdilc4113s000",msg)
|20080331.st Add the command cancelled check.
if strip$(error_code) = "tdilc40062" or strip$(msg) = "Command cancelled" then
msg = ""
endif
stpapi.end.session("tdilc4113s000")
endif
stpapi.end.session("tdpur4120m000")
}

mark_h
30th September 2015, 16:13
OH - I forgot to mention. When the session hands on you if you go kill it manually using option dialog, start shell - does it finish and work?

I have a could of sessions that work, but I have to kill a session myself in the code to keep it going. I have a routine somewhere that does that also. I don't like this solution, but it was the only solution in a few cases.

sgoupil
30th September 2015, 22:40
Thanks Mark,

I based my code pretty much on yours. It's funny, because when I look at the process running, befor I hit the end.session of tdilc4113s000, I only have tdpur4120m000 and tdilc4113s000, when I hit the line, the tdilc4113s000 process is gone, but it hangs there and there is no hints in the afs.log file. No message, nothing, just does not totally completes the end.session....

bhushanchanda
30th September 2015, 22:46
Hi,

There is almost a similar thread which relates to same session and has a hanging issue. This (http://www.baanboard.com/baanboard/showthread.php?t=6201) is the link.

The last comment says -

I looked at your code and based on where you indicated that you had a problem. I think that your problem is that you need to create the Lot Number in tdltc0101s000 before doing the put in tdilc402.clot. I think that you are getting a “Not Found” error.

So, may be the Lot doesn't exists and its just not popping up the error. Are you able to process it manually? May be the update is not working in your case and hence the session hangs on some unshown error message.

bhushanchanda
30th September 2015, 22:52
And on little investigation -

This thread (http://www.baanboard.com/baanboard/showthread.php?t=13037) gives a nice hack! Try it.

bhushanchanda
30th September 2015, 22:54
One more search and an indepth solution.

Wow, the board is full of solutions -> Solution (http://www.baanboard.com/baanboard/showthread.php?t=52857&highlight=tdpur4102s000)

mark_h
30th September 2015, 23:11
Some good finds Bhushan. Not sure what will happen with an invalid lot. My code creates the lot if it does not exist(another stpapi function server). Never tried it with an invalid lot. I would look at that and make sure all the data is valid.

sgoupil
1st October 2015, 16:38
Hey guys, I was able to make it progress with Mark and Bhushan. Here is my code that (almost) work. It now does not hang on the tdilc4113s000 end.session, it hangs on the tdpur4120m000 end.session (last line). When I look at the prosesses, after executing the end.session on tdltc0101m000, the process realy ends, when the code execute the end.session on tdilc4113s000, it does not hang, but the session is still running in the processes, so when it tries to end.session tdpur4120m000, it hangs. In debug mode, after executing tdilc4113s000 end.session, I killed the process manually and then executed the end.session of tdpur4120m00, it then worked fine. I tried putting a handle sub.session with "kill" on tdilc4113s000 and it did not change anything. Also putting lines of the afs.log file. It seems like tdpur4120m000 is waiting for some cont.proc, there are none in the code. Also, seems to have a switch.to.process on tdilc4113s000, which I am not sure exactly what it means.

boi.call = "tdboidll0011.Create"

stpapi.put.field("tdpur4120m000","tdpur045.reno",str$(hold.reno))
stpapi.put.field("tdpur4120m000","tdpur045.orno",str$(keep.orno))
stpapi.put.field("tdpur4120m000","tdpur045.pono",str$(keep.pono))
r = stpapi.find("tdpur4120m000",p.error.code)
if not isspace(p.error.code) or r<>1 then
stpapi.end.session("tdpur4120m000")
return
endif

stpapi.put.field("tdpur4120m000","tdpur045.diqu",str$(f.oqua))
stpapi.put.field("tdpur4120m000","tdpur045.date",str$(receipt.date))
stpapi.put.field("tdpur4120m000","tdpur045.dqua",str$(f.oqua))
r = stpapi.update("tdpur4120m000",1,p.error.code)
if not isspace(p.error.code) or r<>1 then
stpapi.end.session("tdpur4120m000")
return
endif

stpapi.put.field("tdilc4113s000", "tdilc402.clot",f.clot)
stpapi.put.field("tdilc4113s000", "tdilc402.date",str$(receipt.date))
stpapi.put.field("tdilc4113s000", "tdilc402.qstr",str$(f.oqua))
stpapi.handle.subproc("tdilc4113s000", "tdltc0101s000", "add")
r = stpapi.insert("tdilc4113s000",1,p.error.code)
stpapi.end.session("tdltc0101s000")
stpapi.end.session("tdilc4113s000")
stpapi.end.session("tdpur4120m000")

AFS.LOG entries:

>tdilc4113s000 end.session
51dll->serv (end.program^A58)
tdilc4113s000(58)-RUNNING:end.program
58serv<-4gl (switch^A57)
<tdilc4113s000 switch.to.process
57serv<-4gl (switch^A58)
58serv<-4gl (end.program^A0)
tdilc4113s000(58)-RUNNING:
>tdpur4120m000 end.session
tdpur4120m000waiting for prev cont.proc
tdpur4120m000waiting timed out
51dll->serv (end.program^A57)

mark_h
1st October 2015, 20:41
Do you have the source code? That would make this so much easier. I am also curious why tdltc0101s000 is popping up on your system. I tried finding something to receive on our end to see if I could make it pop manually, but no luck so far.