neeraj_vasudeva
18th December 2002, 19:53
Hello,

I a new to BaaN. I have the following set of data i.e. Cost Price , which is being picked up after doing certain calculaion in report script.

Item Cost Price

A 100
B 20
C 40
D 60

--------
Total 220
--------

I have to calculate Cumalative Value %

Item Cost Price Cumalative Value %

A 100 45.45
B 20 9.09
C 40 18.18
D 60 27.27

--------
Total 220
--------

Formaulae for Cumalative Value % is :

Cost Price / Sum of Cost Price * 100

Now I have written in after.field of item in report script to do calculation for cost price so that i could send
data on report, problem is how do i calculate Cumalative Value % because for that i need Cost Price Total. I can only know at the end of all records...

how should i proceed with this problem.....???

which events should i use ? which sections should i use ?

for better indentation of data i am also attaching a text file, please open it in notepad with word wrap ON

mark_h
19th December 2002, 04:55
There are two ways to do this that I can think of. The first one is to change the session script. In changing the session script to get the grand total before sending it to the report.

Or you could use the after.receive.data like this thread (http://www.baanboard.com/baanboard/showthread.php?s=&threadid=7020&highlight=report) to total the records in the report, before letting the report run.

Good Luck!

Mark

KlayVessel
2nd January 2003, 08:35
Interesting thought about after.receive.data.

There is a third way, which I find easier to use. Let me start by clearly stating how the session and report scripts interact. Basically you have open report, send data, close report. The sort hase and print phase fit in here somewhere, the timing of which is effected by your sort settings in the report input fields, as follows:

If all sort fields are marked as "presorted" then you get:
1 - open report
2 - send data; the report immediately prints detail lines (and header/footer/breaks as necessary) as they are sent.
4 - close report

On the other hand, if you mark at least one field as "ascending" or "descending" which means the report object has to sort you get:
1 - open report
2 - send data, report writes data fields to sort file
3 - close report, report closes sort file and sorts it, report then reads all records in sort file and prints detail lines (etc.).

Note the important difference. In the second case nothing is printed until after the sort. You can use this to your advantage in this case. Add one new input data field to your report, a record type field (for this example, well assume a numeric value with 1=Total and 2=Data). In your session script, set the record type to 2 for any data rows, sum up the totals and send them after the data with the record type set to 1.

When the report sorts this, the total (or sub-totals if you wish) will be sorted just before the data records they would be used for. Create two detail layouts. Layout 1 would trigger if record-type = 1 (the total/sub-total data), capture this value in a local variable and set lattr.print = false (so these don't actually print). Layout 2 would trigger for the actual data records (record-type =2) and you can use that local variable with the total to compute your ratio.

KlayVessel
2nd January 2003, 08:54
I reread those posts discussing after.receive.data. I have some concerns about that, though I have done something similar in the past (that is reread and resorted the temporary sort file manually). The problem that adds is that it becomes a lot more difficult to maintain. I prefer just to use a second report script. See my "hint" here (http://www.baanboard.com/baanboard/showthread.php?s=&postid=30817#post30817)