Paul P
18th September 2006, 12:26
Hi guys,
We're in the process of making cycle counting data entry barcode-enabled by using BaanIV API. Before any physical count data fly from the warehouse to BaanIV, however, we'd like to "reset" all the counted inventory to zero (this feature is built-in in BaanERP). This is assuming that if they can't find the stuff in the actual warehouse, then the counted physical stock should be set to zero. We're implementing this "reset" function through API inside a new BaanIV session. We've debugged this script as well as looked through the API log (afs.log) and found nothing wrong with it. But somehow, when I go back to the session manually (not through API), only the first line in each "view" is reset properly to zero. Could you give me a hand on this, please? Thanks
|****************************** DECLARATION SECTION
declaration:
#pragma used dll ottstpapihand
extern domain tcorno cco
string TempStr(30)
|****************************** CHOICE SECTION
choice.cont.process:
on.choice:
stpapi.browse.view("tdilc5110m000","first.view")
stpapi.get.field("tdilc5110m000","tdilc501.orno",TempStr)
stpapi.enum.answer("tdilc5110m000","tdilc50001",tcyesno.yes)
while lval(TempStr)<>cco
NextView()
endwhile
ZeroAllSets()
NextView()
while lval(TempStr)=cco
ZeroAllSets()
NextView()
endwhile
stpapi.end.session("tdilc5110m000")
|****************************** FIELD SECTION
field.cco:
check.input:
select orno
from tdilc501
where orno=:cco
as set with 1 rows
selectempty
set.input.error("Order not present")
endselect
|****************************** FUNCTION SECTION
functions:
function ZeroCountedQty()
{
stpapi.put.field("tdilc5110m000","tdilc501.cstk","0")
stpapi.update("tdilc5110m000",TRUE,TempStr)
}

function ZeroAllSets()
{
stpapi.browse.set("tdilc5110m000","first.set")
ZeroCountedQty()
while stpapi.browse.set("tdilc5110m000","next.set")=1
ZeroCountedQty()
endwhile
}

function NextView()
{
stpapi.browse.view("tdilc5110m000","next.view")
stpapi.get.field("tdilc5110m000","tdilc501.orno",TempStr)
}
And here's the API log
LOGGING STARTED
18-09-2006
>tdilc5110m000 browse.view
3dll->serv (getxml)
3dll->serv (starttdilc5110m000100)
5serv<-4gl (api.child.startedtdilc5110m0003)
5serv<-4gl (init.ready)
tdilc5110m000(5)-RUNNING:
3dll->serv (first.view5)
tdilc5110m000(5)-RUNNING:first.view
5serv<-4gl (first.view0)
tdilc5110m000(5)-RUNNING:
<tdilc5110m000 1 ok
>tdilc5110m000 get.field:tdilc501.orno
<tdilc5110m000(5) get.field:tdilc501.orno=700190
>tdilc5110m000 enum.answer tdilc50001:1
3dll->serv (enum.answertdilc5000115)
tdilc5110m000(5)-RUNNING:enum.answer
5serv<-4gl (enum.answer0)
tdilc5110m000(5)-RUNNING:
>tdilc5110m000 browse.view
3dll->serv (next.view5)
tdilc5110m000(5)-RUNNING:next.view
5serv<-4gl (next.view0)
tdilc5110m000(5)-RUNNING:
<tdilc5110m000 1 ok
>tdilc5110m000 get.field:tdilc501.orno
<tdilc5110m000(5) get.field:tdilc501.orno=700190
>tdilc5110m000 browse.view
3dll->serv (next.view5)
tdilc5110m000(5)-RUNNING:next.view
5serv<-4gl (next.view0)
tdilc5110m000(5)-RUNNING:
<tdilc5110m000 1 ok
>tdilc5110m000 get.field:tdilc501.orno
<tdilc5110m000(5) get.field:tdilc501.orno=700190
>tdilc5110m000 browse.view
3dll->serv (next.view5)
tdilc5110m000(5)-RUNNING:next.view
5serv<-4gl (next.view0)
tdilc5110m000(5)-RUNNING:
<tdilc5110m000 1 ok
>tdilc5110m000 get.field:tdilc501.orno
<tdilc5110m000(5) get.field:tdilc501.orno=700191
>tdilc5110m000 browse.set
3dll->serv (first.set5)
tdilc5110m000(5)-RUNNING:first.set
5serv<-4gl (first.set0)
tdilc5110m000(5)-RUNNING:
<tdilc5110m000 1 ok
>tdilc5110m000(5) put.field:tdilc501.cstk 0
>tdilc5110m000 update
3dll->serv (modify.set+save5)
tdilc5110m000(5)-RUNNING:modify.set+save
5serv<-4gl (modify.set+save0)
tdilc5110m000(5)-RUNNING:
<tdilc5110m000
>tdilc5110m000 get.field:tdilc501.cstk
<tdilc5110m000(5) get.field:tdilc501.cstk=0
>tdilc5110m000 browse.set
3dll->serv (next.set5)
tdilc5110m000(5)-RUNNING:next.set
5serv<-4gl (next.set0)
tdilc5110m000(5)-RUNNING:
<tdilc5110m000 1 ok
>tdilc5110m000(5) put.field:tdilc501.cstk 0
>tdilc5110m000 update
3dll->serv (modify.set+save5)
tdilc5110m000(5)-RUNNING:modify.set+save
5serv<-4gl (modify.set+save0)
tdilc5110m000(5)-RUNNING:
<tdilc5110m000
>tdilc5110m000 get.field:tdilc501.cstk
<tdilc5110m000(5) get.field:tdilc501.cstk=0
>tdilc5110m000 browse.set
3dll->serv (next.set5)
tdilc5110m000(5)-RUNNING:next.set
5serv<-4gl (next.set0)
tdilc5110m000(5)-RUNNING:
<tdilc5110m000 1 ok
>tdilc5110m000(5) put.field:tdilc501.cstk 0
>tdilc5110m000 update
3dll->serv (modify.set+save5)
tdilc5110m000(5)-RUNNING:modify.set+save
5serv<-4gl (modify.set+save0)
tdilc5110m000(5)-RUNNING:
<tdilc5110m000
>tdilc5110m000 get.field:tdilc501.cstk
<tdilc5110m000(5) get.field:tdilc501.cstk=0
>tdilc5110m000 browse.set
3dll->serv (next.set5)
tdilc5110m000(5)-RUNNING:next.set
5serv<-4gl (next.set0)
tdilc5110m000(5)-RUNNING:
<tdilc5110m000 1 ok
>tdilc5110m000(5) put.field:tdilc501.cstk 0
>tdilc5110m000 update
3dll->serv (modify.set+save5)
tdilc5110m000(5)-RUNNING:modify.set+save
5serv<-4gl (modify.set+save0)
tdilc5110m000(5)-RUNNING:
<tdilc5110m000
>tdilc5110m000 get.field:tdilc501.cstk
<tdilc5110m000(5) get.field:tdilc501.cstk=0
>tdilc5110m000 browse.set
3dll->serv (next.set5)
tdilc5110m000(5)-RUNNING:next.set
5serv<-4gl (next.setEOF)
tdilc5110m000(5)-RUNNING:
<tdilc5110m000 0 No record found
>tdilc5110m000 browse.view
3dll->serv (next.view5)
tdilc5110m000(5)-RUNNING:next.view
5serv<-4gl (next.view0)
tdilc5110m000(5)-RUNNING:
<tdilc5110m000 1 ok
>tdilc5110m000 get.field:tdilc501.orno
<tdilc5110m000(5) get.field:tdilc501.orno=700191
>tdilc5110m000 browse.set
3dll->serv (first.set5)
tdilc5110m000(5)-RUNNING:first.set
5serv<-4gl (first.set0)
tdilc5110m000(5)-RUNNING:
<tdilc5110m000 1 ok
>tdilc5110m000(5) put.field:tdilc501.cstk 0
>tdilc5110m000 update
3dll->serv (modify.set+save5)
tdilc5110m000(5)-RUNNING:modify.set+save
5serv<-4gl (modify.set+save0)
tdilc5110m000(5)-RUNNING:
<tdilc5110m000
>tdilc5110m000 get.field:tdilc501.cstk
<tdilc5110m000(5) get.field:tdilc501.cstk=0
>tdilc5110m000 browse.set
3dll->serv (next.set5)
tdilc5110m000(5)-RUNNING:next.set
5serv<-4gl (next.set0)
tdilc5110m000(5)-RUNNING:
<tdilc5110m000 1 ok
>tdilc5110m000(5) put.field:tdilc501.cstk 0
>tdilc5110m000 update
3dll->serv (modify.set+save5)
tdilc5110m000(5)-RUNNING:modify.set+save
5serv<-4gl (modify.set+save0)
tdilc5110m000(5)-RUNNING:
<tdilc5110m000
>tdilc5110m000 get.field:tdilc501.cstk
<tdilc5110m000(5) get.field:tdilc501.cstk=0
>tdilc5110m000 browse.set
3dll->serv (next.set5)
tdilc5110m000(5)-RUNNING:next.set
5serv<-4gl (next.set0)
tdilc5110m000(5)-RUNNING:
<tdilc5110m000 1 ok
>tdilc5110m000(5) put.field:tdilc501.cstk 0
>tdilc5110m000 update
3dll->serv (modify.set+save5)
tdilc5110m000(5)-RUNNING:modify.set+save
5serv<-4gl (modify.set+save0)
tdilc5110m000(5)-RUNNING:
<tdilc5110m000
>tdilc5110m000 get.field:tdilc501.cstk
<tdilc5110m000(5) get.field:tdilc501.cstk=0
>tdilc5110m000 browse.set
3dll->serv (next.set5)
tdilc5110m000(5)-RUNNING:next.set
5serv<-4gl (next.setEOF)
tdilc5110m000(5)-RUNNING:
<tdilc5110m000 0 No record found
>tdilc5110m000 browse.view
3dll->serv (next.view5)
tdilc5110m000(5)-RUNNING:next.view
5serv<-4gl (next.view0)
tdilc5110m000(5)-RUNNING:
<tdilc5110m000 1 ok
>tdilc5110m000 get.field:tdilc501.orno
<tdilc5110m000(5) get.field:tdilc501.orno=700192
>tdilc5110m000 end.session
3dll->serv (end.program5)
tdilc5110m000(5)-RUNNING:end.program
5dll->serv (tdilc5110m000: exit(5))
3dll->serv (afsscript: exit(3))

Rgds,
Paul

mark_h
18th September 2006, 15:18
Your code should work - but try this in your 0 qty routine:

while stpapi.browse.set("tdilc5110m000","next.set")=1
stpapi.find("tdilc5110m000",err)
stpapi.get.field("tdilc5110m000","tdilc501.cstk",err)
stpapi.put.field("tdilc5110m000","tdilc501.cstk","0")
stpapi.update("tdilc5110m000",true,err)
endwhile

I really think your code should work, but on my system it was like after the first update the next record was not made current. I tried stpapi.mark, but it did not work either. So I tried the find command and that seemed to do the trick.

Paul P
19th September 2006, 04:29
Wow, Mark, your generosity with your time to help the rest of us is remarkable. I tried quite a few acrobatic tricks to try to make it work, including using stpapi.mark() . After I hit a brick wall, I posted this thread at the end of the working day yesterday. I hadn't tried using stpapi.find() though. I'm at another client today, but I'll be back at this BaanIV API client tomorrow and will surely try it first thing in the morning (we're almost exactly half a world apart, so 9 AM tomorrow - 20 Sep 06 - here will be 9PM today - 19 Sep 06 - at your place). Thanks so much for the tip, man! You're indeed one of a kind

Rgds,
Paul

Paul P
20th September 2006, 11:46
Internet was down from morning til now. I did try it first thing in the morning. AND IT WORKS! Amazing! Thanks, Mark. So, according to Mark's suggestion, I modified ZeroCountedQty() as follows:
function ZeroCountedQty()
{
stpapi.find("tdilc5110m000")
stpapi.put.field("tdilc5110m000","tdilc501.cstk","0")
stpapi.update("tdilc5110m000",TRUE,TempStr)
}
On top of it, I had to make changes to NextView() to make it more error tolerant:
function NextView()
{
if stpapi.browse.view("tdilc5110m000","next.view")=1 then
stpapi.get.field("tdilc5110m000","tdilc501.orno",TempStr)
else
TempStr=""
endif
}
Rgds,
Paul