benter
17th January 2007, 03:51
Hi, Dear all,
I made a session to realize the auto maintain receipt function, I test the program, I found the session can work in Baan4c4(SP9), but if I migrate this program to Baan4c4(SP16), the session could not work.
My source code as following:

| Creating a receipt always use 0 for the tdpur045.reno field.

purchase.order=101935

stpapi.handle.subproc("tdpur4120m000","tdpur4224s000","add")
stpapi.put.field("tdpur4120m000","tdpur045.reno",str$(0))
stpapi.change.view("tdpur4120m000")
if not isspace(msg) then
stpapi.end.session("tdpur4120m000")
message(receipt.number)
endif
| Always use tdpur4224s000 to create receipt for all lines.

stpapi.put.field("tdpur4224s000","form.orno",str$(purchase.order))
stpapi.continue.process("tdpur4224s000",msg)
stpapi.end.session("tdpur4224s000")
|Currently tdpur4224s000 continue returns Process is gone
if not isspace(msg) and strip$(msg)<> "Process is gone" then
stpapi.end.session("tdpur4120m000")
message(receipt.number)
endif
msg = ""
suspend(3000)
stpapi.get.field("tdpur4120m000","tdpur045.reno",dummy)
receipt.number = dummy
receipt.number1=val(dummy)


select tdpur045.*
from tdpur045
where tdpur045.reno=:receipt.number1 and tdpur045.dqua=0
selectdo
purchase.order=tdpur045.orno
purchase.line =tdpur045.pono
stpapi.put.field("tdpur4120m000","tdpur045.reno",receipt.number)
stpapi.put.field("tdpur4120m000","tdpur045.orno",str$(purchase.order))
stpapi.put.field("tdpur4120m000","tdpur045.pono",str$(purchase.line))
stpapi.find("tdpur4120m000")

get.quan.and.lot()

received.date=date.num()
purchaselot.date=date.num()
conv.factor =1
modify_receipt(lval(receipt.number),
purchase.order,
purchase.line,
packingslip.qty,
received.qty,
received.date,
purchase.lot,
purchaselot.date,
conv.factor,
purchase.unit,
purchase.item,
msg)
suspend(3000)
endselect
stpapi.end.session("tdpur4120m000")

}
function get.quan.and.lot()
{
select *
from tdpur041
where tdpur041.orno=:purchase.order and tdpur041.pono=:purchase.line
selectdo
purchase.lot = tdpur041.clot
packingslip.qty =tdpur041.oqua
received.qty = tdpur041.oqua
purchase.item=tdpur041.item
purchase.unit=tdpur041.cuqp
endselect
}
|******************************************************************************
|* API Code for modifying an existing receipt.
|******************************************************************************
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())
{
long rc, cnt
string dummy(6), error_code(16)
domain tcorno get.orno
domain tcpono get.pono
conv.factor =1

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

msg = ""
| boi.call = "tdboidll0011.Create"

| Prepare to handle lot controlled items.
if ((not isspace(purchase.lot) or conv.factor>1 )
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))
stpapi.update("tdpur4120m000",1,msg)
if not isspace(msg) then
if not isspace(purchase.lot) or conv.factor>1 then
stpapi.end.session("tdilc4113s000")
endif
stpapi.end.session("tdpur4120m000")
abort()
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))
stpapi.insert("tdilc4113s000",1,msg)
error_code = stpapi.get.mess.code("tdilc4113s000")
if strip$(error_code) = "tdilc40062" then
msg = ""
endif
stpapi.end.session("tdilc4113s000")
endif
| stpapi.end.session("tdpur4120m000")
}


In SP16 enviroment, the program was hold in the script ' stpapi.update("tdpur4120m000",1,msg)' , How can do for this case?

Help me! Thanks a lot!

mark_h
17th January 2007, 15:31
Hmmm - this code looks familiar. :)

Do you have source code for tdpur4120m000? I know I had to use qkey(source extender) to modify tdpur4120m000 to get it to work, but I think I did that on SP18 or SP19. You might have to play with the boi.call variable to see if that will work for you. You should search on this forum for boi.call.

benter
18th January 2007, 01:55
Of course I have the source code of tdpur4120m000, but don't know how to modify the script. I want to know in Baan system, wether have function or procedure to take place the key action ' TAB'? If I can simulate the key action, I think perhaps the problem could slove!

Thanks Mark!

benter
18th January 2007, 01:59
Dear Mark,
You said you had did in SP18 /SP19, could you tell me the way you did?
I think if you could do in SP18/SP19, I also can do it in SP16!
Ths

Thomasm
18th January 2007, 08:56
Familiar code indeed. Thanks Mark for sharing with us all.

I agree with Mark, you might need to uncomment the boi.call variable. I see my code is slightly different but I cannot remember exactly why. I had to experiment a bit and this is the result. I implemented it on SP12 and we are now on SP20, with no stops in between.

Good luck,
/Thomas

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())
{
long rc
string dummy(6), error_code(16)

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)
| 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))
stpapi.insert("tdilc4113s000",1,msg)
error_code = stpapi.get.mess.code("tdilc4113s000",msg)
if strip$(error_code) = "tdilc40062" then
msg = ""
endif
stpapi.end.session("tdilc4113s000")
endif
stpapi.end.session("tdpur4120m000")
}

mark_h
18th January 2007, 15:59
Thanks Thomas. I am wondering how you got past all the WM code they inserted in one of the service packs. That is what caused my problem.


|******************************************************************************
|* 20050418 Mark Holland 04/18/2005
|* Added boi variables and set g.sub.session for service pack changes. These
|* changes allow the receipt afs programs to work.
| 20050418.st Added these variables
extern domain tcmcs.str132 boi.call
extern long boi.bqua.flag
extern domain tcbool g.sub.session | 20050418.end
field.tdpur045.dqua:
before.input:
|20050418.st Added this if statement. Might need to modify this to check
| the calling session to make sure it was tdapi.
if api.mode then
g.sub.session = true
endif |20050418.end
|#call
|#pobj added by QKEY 3.70
_pobj_exe1("before.input.tdpur045.dqua")
|#end add by QKEY

The above code worked for me on that SP. We just did 20 and I did not need to make any changes to these sessions. I only had to change one of my API sessions.

Thomasm
18th January 2007, 16:08
Mark,

Not sure what you are referring to here... I do not have the source so I have not made any adjustments to the called session. This is how I understand you at least...

So the code in my example works for calling the session to modify the receipt, in SP12 and SP20. However, we are not using lot control, which I believe you are? Maybe that is the difference.

/Thomas

mark_h
18th January 2007, 16:15
Oops - what I was talking about was in that SP in 2005. The tdpur4120m000 session and someothers was being integrated with a warehouse management system they were marketing at that time. There was just a ton of new code in the sessions that caused me some problems.

And yes you are correct it was lot controlled items causing the problem. If I recall correctly we discovered this when trying to receive lot controlled items. That is where the SSA baan code(with the new warehouse management code) was doing funny stuff. My little qkey fix just set a variable to make it do the right thing that I needed. Not elegant, but it worked.

benter
19th January 2007, 08:59
Thanks Mark and Thomas!

The way you sugguested to uncomment the Boi.call, I tried, but still could not hold on the 'stpapi.update("tdpur4120m000",1,msg)' script.
I think perhaps some solution could slove this problem.
I will modify the source code of tdpur4120 to test, I will tell you the test result.
Next two days I will enjoy weekend, so it need to wait for two days.

Anyway, thanks for your help!