smusba
11th June 2008, 11:54
Dear Gurus,

I am facing an initialisation problem in program flow. The program works perfectly if the order date is given of different range but fails to get the correct data if order date is of same range. I had tried very much to solve but the problem still exists. Does anyone have any ideas for fixing this?
Here is my code(Script)

functions:
function read.main.table()
{ dramnt=0.0
ddat=date.num()
if etol(reg) = 1 then
cuno.f = " CG401"
cuno.t = " CG499"

select tdsls041.*
from tdsls041
where tdsls041.odat between :ddat.f and :ddat.t
and tdsls041.cuno between :cuno.f and :cuno.t
|and tdsls041.odat between :ddat.f and :ddat.t
|order by tdsls041.odat,tdsls041.cuno
selectdo

select tdsls040.*
from tdsls040
where tdsls040.orno = :tdsls041.orno
and tdsls040.odat = :tdsls041.odat
|and tdsls045.cuno = :tdsls040.cuno
selectdo

cuno = tdsls041.cuno

if ddat = tdsls040.odat then

dramnt = dramnt+ tdsls041.amta
else
dramnt = 0.0
endif
ddat = tdsls041.odat

select tccom010.*
from tccom010
where tccom010.cuno = :tdsls041.cuno
selectdo
endselect

rprt_send()
endselect
endselect
endif

}



Suhaib

mark_h
11th June 2008, 20:07
Use inrange instead of between.

smusba
14th June 2008, 08:58
Dear Mark,

It didn't solve the problem for me

zardoz
14th June 2008, 12:52
inrange and between instructions acts in different way only if they refers to combined fields, otherwise they act in the same way....

In the script, you don't use any order by. This means that the tdsls041 is read in random way (the db driver choose an index and use it to give you records in that order, maybe index1), and you do some sum based on a date (ddat), and the date starts on today but is changed in the select.
So, the data could be not read in the order you expect...
Why don't use order by (and maybe do only one select with refers to tdsls040 and tccom010 instead of nested select, that are very poor performants)?
Even the total dramnt could be calculated by the report instead of do this in the script.
The result will be a more short and performant script even more easy to debug.

smusba
14th June 2008, 14:37
Dear Zardoz,

No,it didn't solve the problem

mark_h
16th June 2008, 14:48
Zardoz is correct and yes at one point I had to change a query on a date field. So I had to change inrange to (table.date>= :date.f and table.date<=:date.t). I can not remember why I had to do that.

smusba
16th June 2008, 15:52
Dear Mark,

I had tried this method earlier and got the same result

mark_h
16th June 2008, 16:06
Okay then it has to be in this code

cuno = tdsls041.cuno
if ddat = tdsls040.odat then
dramnt = dramnt+ tdsls041.amta
else
dramnt = 0.0
endif
ddat = tdsls041.odat

With a different sequence of orders from tdsls041 I can see where ddat would change and thus the value that goes in dramnt. You should debug it and step thru this code making sure you get the same sequence of records for both the date ranges.

smusba
16th June 2008, 16:46
Sorry, it didn't help me out.