Friday, February 24, 2012

Calculations among Subreports

I have three subreports on my main reports.what I need is that on third subreport i have a formula thats subtracting two values from two subreports beside it.Values are defined in shared variable on subreports.Formula on third subreport is accessing those shared
variables and doing calculation.Problem is:

Formula is displaying result only for the first record on subreports ,whereas i want the result of calculation for all the corresponding records.

(First 2 subreports are linked with main report)check in formula functions have you added
WhilePrintingRecords to the start of your formulas.|||I have whileprintingrecods statment in mu formula.formula is :

whileprintingrecords;

shared numbervar firstnumber;
shared numbervar secondnumber;

firstnumber - secondnumber|||Are the variables also defined in the main report?
Do you have WhilePrintingRecords in all formulas using these variables?
And what do you mean by 'from two subreports beside it'. Where are the subreports in the design?|||Here's what i am doing:

1) three subreports on main report.

2) third subreport is using shared variables from two subreport

3) before describing the shared variables in 1st two subreports i am using

whileprintingrecords;
shared numbervar firstnumber := command.hours
(same in 2nd subreport)

4) Formula in 3rd subreport:

whileprintingrecords;
shared numbervar firstnumber;
shared numbervar secondnumber;

secondnumber - firstnumber

5) When report is printing ,its displaying result only for first record.|||Where are the subreports in the main report's design?
What do you mean by "its displaying result only for first record"? The first record in the main report? The first record per subreport? How many records can the subreports have? Can the first two subreports have no records, meaning the variables won't be (re)set.
So many questions...|||Formula is displaying result only for the first record on subreports ,whereas i want the result of calculation for all the corresponding records.

firstly create a formula on main report
called for sample :

init_var

shared numbervar firstnumber:=0;
shared numbervar secondnumber:=0;


it formula put in header of main report.

now on sub report, create formulla
called for sample :

/************************************************/
calculate_values_SR1

shared numbervar firstnumber;
firstnumber:=myfield_value + firstnumber;

it formula put in detail of first sub report.(I assume your data are there.)
in each detail the formula does work again

/************************************************/
calculate_values_SR2

shared numbervar secondnumber;
secondnumber:=myfield_value + secondnumber;

it formula put in detail of second sub report.
/************************************************/
now on yur third sub report

shared numbervar firstnumber;
shared numbervar secondnumber;
secondnumber - firstnumber


I hope it gives a idea.|||Reply to JaganEllis questions:

1) The first record per subreport?

Yes, i need to print resluts of all records on 1st 2 subreport on 3rd subreport correspondingly.
5 10 15
9 11 20

2) How many records can the subreports have?
depends on records in table

3) Can the first two subreports have no records, meaning the variables won't be (re)set.

it is possible.
Subreports are in detail section of Main report.

Reply to Hensa22
--------

Your solution is not working on dummy data (my own test report) but seemed to work on actual report but as table has not enough values so not able to tell how reliable it is.

No comments:

Post a Comment