smusba
10th February 2009, 09:31
Dear Gurus,

I have developed a report for "Prev cost price history" with single date input at a time. this scripts works very well. Now i want to enter from and to date
in the form and subseqent addition in script.
My script is

field.item.f:
when.field.changes:
item.t = item.f


|****************************** function section ******************************
functions:
function read.main.table()
{
|sno = 0
item = ""
indt.t = indt.f - 1
amntc = 0.0
amntp = 0.0
select tiitm001.*
from tiitm001
where tiitm001.item between :item.f and :item.t
and tiitm001.ltcp = :indt.f
|and tiitm001.copr <= 0.0
selectdo
if etol(tiitm001.kitm) = 3 then
else
|amntc = find.curr()
amntp = find.prev()
rprt_send()
endif

endselect
}
function double find.curr()
{
extern domain tcorno count1
extern domain tccopr amcr
amcr = 0.0
count1 = 0
indtc = 0
select ticpr300.*
from ticpr300
where ticpr300.item = :tiitm001.item
and ticpr300.amnt <> 0.0
and ticpr300.indt = :indt.f
|order by ticpr300.item, ticpr300.indt
selectdo
if count1 = 1 then
else
indtc = ticpr300.indt
count1 = count1 + 1
amcr = ticpr300.amnt
endif
endselect
return(amcr)

}

function double find.prev()
{
extern domain tcorno count
extern domain tccopr ampr
count = 0
ampr = 0.0
indtp = 0
select ticpr300.*
from ticpr300
where ticpr300.item = :tiitm001.item
and ticpr300.indt < :indt.f
order by ticpr300.indt desc
selectdo
if count = 1 then
else
indtp = ticpr300.indt
ampr = ticpr300.amnt
count = count + 1

endif
endselect
|message("Cost%d",amntp)
return(ampr)

}

toolswizard
12th February 2009, 16:33
You don't show what domain you are using for date. You either have to work in seconds (the baan default), UTC or asci and use the proper quantity to add or subtract. I think you want to add to your from date, not subtract., to get to your to date. From must be less than TO. In you SQL you should then use a range like between to get the from/to that you expect.