Same Code, Different Results, Reason? [message #553758] |
Tue, 08 May 2012 06:28 |
|
bluetooth420
Messages: 146 Registered: November 2011
|
Senior Member |
|
|
Hi,
I am making a report in which i have to calculate the value of ending inventory.
I wrote code in SQL and able to get perfect result. But when i copy/pasted the same code in "Oracle Reports 6", it has given me the different result which is wrong.
What are the possibilities? what am i missing in report?
Here is the code.
select sum((VALUE_OF_BAL_QTY_DATED(sum(qty), sale_type, sale_code, to_date('31012012', 'ddmmyyyy') ) ))
from
(Select sale_type, sale_code, qty
from invp
where invdate <=to_date('31012012', 'ddmmyyyy')
union all
Select sale_type, sale_code, qty*-1
from invs
where invdate <=to_date('31012012', 'ddmmyyyy') )
group by sale_type, sale_code
One more observation: I made a brand new report and copy/pasted the above code. And it was giving the perfect rquired result of 1.7 millions.
So could not figure out that what is going on? Is there any parameter which affects report'sparameter?????( i cant the question even as this had made me sick)
|
|
|
|
|
|
Re: Same Code, Different Results, Reason? [message #553775 is a reply to message #553768] |
Tue, 08 May 2012 08:13 |
cookiemonster
Messages: 13959 Registered: September 2008 Location: Rainy Manchester
|
Senior Member |
|
|
I doubt the problem is the function. I assume the problem is due to the select finding different records.
In the select you compare invdate to a value. In your example that value is hard-coded, but I would assume in the actual report you are using a parameter instead of the hard-coded value.
Is that correct?
If it is what is the datatype of that parameter (you can see the datatype in the parameters property pallete)?
|
|
|
Re: Same Code, Different Results, Reason? [message #553783 is a reply to message #553775] |
Tue, 08 May 2012 08:56 |
|
bluetooth420
Messages: 146 Registered: November 2011
|
Senior Member |
|
|
Yes, you are right.
I am using a parameter (medate) in the actual situation. It has date type in declare section. This paramter, medate, is used many times in calculating many things as part of financial statements in the current report. Hence no problem is found in it except when calculating the ending inventory value as described above.
The function VALUE_OF_BAL_QTY_DATED is working perfectly in SQL environment and in NEW REPORT with to_date('31012012', 'ddmmyyyy') as input paramter of the function.
I also though that there might be a problem in medate variable so i replace it with to_date('31012012', 'ddmmyyyy'). Theroatically speaking, it must not have any difference. But in practical its giving false result.
Whereas if i start making new report is just like reinvneting the wheel for me.
The function is somewhat fine as giving me perfect result in SQL or in new report.
[Updated on: Tue, 08 May 2012 08:59] Report message to a moderator
|
|
|
|
|
Re: Same Code, Different Results, Reason? [message #553796 is a reply to message #553786] |
Tue, 08 May 2012 09:36 |
cookiemonster
Messages: 13959 Registered: September 2008 Location: Rainy Manchester
|
Senior Member |
|
|
Add an item to the report to display the value of the date parameter. Check it's what you think it is.
If it's correct then there must be a bug in the function code, in which case you would have to share the code with us for further help.
|
|
|
Re: Same Code, Different Results, Reason? [message #553802 is a reply to message #553796] |
Tue, 08 May 2012 10:18 |
|
bluetooth420
Messages: 146 Registered: November 2011
|
Senior Member |
|
|
CREATE OR REPLACE FUNCTION VALUE_OF_BAL_QTY_DATED
(pin_balqty IN NUMBER,
pin_sale_type IN CHAR,
pin_sale_code IN char,
pin_dated IN DATE) RETURN number IS
a NUMBER := 0;
b NUMBER := pin_balqty;
BEGIN
b := pin_balqty;
FOR j in ( Select *
FROM V0PROD
where sale_type=pin_sale_type and sale_code=pin_sale_code
and (invdate <=pin_dated or invdate is null)
ORDER BY sale_type, sale_code, decode(invdate, null, 0, 1) desc , INVDATE DESC, INVNO DESC ) LOOP
IF b <= j.qty THEN
a:= (b * j.uprice)+a;
RETURN a;
ELSE
a:= (j.qty * j.uprice)+a;
b:= b-j.qty;
END IF;
END LOOP;
RETURN a;
END;
/
|
|
|
|
|
|
Re: Same Code, Different Results, Reason? [message #553820 is a reply to message #553817] |
Tue, 08 May 2012 11:04 |
|
bluetooth420
Messages: 146 Registered: November 2011
|
Senior Member |
|
|
select sum(VALUE_OF_BAL_QTY_DATED(sum(qty), sale_type, sale_code, medate))
into einv
from
(Select sale_type, sale_code, nvl(qty,0) qty
from invp
where invdate <=medate
union all
Select sale_type, sale_code, nvl(qty,0)*-1
from invs
where invdate <=medate)
group by sale_type, sale_code;
Adding NVL function has solved the problem.
and by the way there is no row selected in SQL with following code
Quote:Select *
from invp
where qty is null;
Select *
from invs
where qty is null;
Dear cookiemonster, thank you for your support in my "sickness".
By the way what and why of this porblem and then the solution according to you?
|
|
|
|
|
|
|
|