Jump to content

Subreport Parameter Sumattion


2004 IR Help

Recommended Posts

By: Chris Germano - netslayer

Subreport Parameter Sumattion

2004-12-10 08:04

I've had discussed this without much luck on this post:

https://sourceforge.net/forum/forum.php?thread_id=1105439&forum_id=217623

 

I need to figure out how to make a subreport pass parameters back to the main report so that I can sum them up in the following way:

----------------------------------------

Subreport A

1 6

4 3

3 1

Subreport A totals 8 10

----------------------------------------

Subreport B

7 3

2 1

1 1

Subreport B totals 10 5

--------------------------------------

Master Report Totals 18 15

 

I've tried the singleton scriplet that was posted in the previous topic but it was buggy, and came with little explanation on how to use it. Can someone give a working example, code paste of the scriplet, how to use it?

 

The other method I've heard of using a Map to store values, and iReports variables don't have a Map available. I tried casting my own from an Object, and it somewhat worked but I ran into problems.

 

I just need a way to pass parameters back to sum them up in the master report...

 

Thank you for any help

 

 

 

 

By: Chris Germano - netslayer

RE: Subreport Parameter Sumattion

2004-12-13 11:32

Bump... common this can't be that hard

 

 

 

 

By: Chris Germano - netslayer

RE: Subreport Parameter Sumattion

2004-12-13 14:48

I finally got this working..kinda but I would like some input on why it's behaving like this.

 

When there's more then one subreport I get summations at the bottom in the master report summary section, but if there is just one subreport run they're null. Of course there are values in that one row so it should be repeating them but they're null.

 

** After doing some calculations I noticed it's always one row off, so if there's just one row then it's not getting any data, any ideas? **

 

Here's how I did it following this url (http://jasperreports.sourceforge.net/tips.tricks.html#returnvalues)

 

Master Report:

-add the subreport section on the details band

-create a new variable named: returnedValuesMap. Set it Java.lang.Object and a Default Value Expression of new java.util.HashMap().

- Open your subreport properties from the master report . Goto the Subreport parameters section and add: Parameter: returnedValuesMap and Expression: $P{returnedValuesMap}

- Goto your subreport and add the same parameter, Parameter Name: returnedValuesMap, Class Type: java.lang.Object

- Creat a variable for the column you want added together by naming it say x, selecting the right Variable Class type, select "Sum" under Calculation Type, Reset Type Report and Variable Expression should be your field that will be continously.*

- Create a line in your summary band so that it gets evaluated at the end of the subreport run.

- Open the line properties window and in the "print when expression" area put: (((Map)$P{returnedValuesMap}).put("associationName1",$V{x}) == null)?Boolean.FALSE:Boolean.FALSE

- If you like set the dimensions of the line to 0 so that the are hidden, and make the summary band 0. You can then access these lines from the Document Structure tab window and then by going Summary.

- Go back to your main report and create a variable which will represent the summed up columns from all the subreports run. Select a Variable class type, Reset type of Report and Calcualtion type of Sum.* Then set the Variable Expression to ((Map)$P{returnedValuesMap}).get("associationName1")

- Now create a field in your summary band and use the new variable you created. When the report runs it will pass the empty hash map into the subreport, then using a new variable sum up the column, then add that variable to the hash map, and so on. After each run of a subreport the master report variable is extracting the hash map value, and summing it up :-P

 

* If you select the wrong Variable class type in a few places you will start seeing Class Cast Exceptions on compile, so check these. If you start to see infinite filling of report problems then make sure your Reset type here is Report.

 

 

 

 

By: Chris Germano - netslayer

RE: Subreport Parameter Sumattion

2004-12-13 15:35

Solved it :-P I created a new group in my master report and moved the subreport object inside the group header and now it's including all the subreports. Hope this helps anyone else having these issues.

 

 

 

 

By: Chris Germano - netslayer

RE: Subreport Parameter Sumattion

2004-12-13 17:00

^^ just realized there's an error in those instructions:

-create a new variable named: returnedValuesMap. Set it Java.lang.Object and a Default Value Expression of new java.util.HashMap().

 

SHOULD BE:

-create a new _parameter_ named: returnedValuesMap. Set it Java.lang.Object and a Default Value Expression of new java.util.HashMap().

 

and grammer:

- Create a variable for the column you want added together by naming it say x. Then select the right Variable Class type, select "Sum" under Calculation Type, Reset Type Report and Variable Expression should be your field that will be continously _added_.*

 

 

 

 

By: Whackjack - whackjack

RE: Subreport Parameter Sumattion

2004-12-15 19:37

Thank you netslayer. It took me a bit to figure out your directions, but I adapted them to my needs and they work perfectly. Good Job!

 

 

 

 

By: Chris Germano - netslayer

RE: Subreport Parameter Sumattion

2004-12-16 08:33

np, at least one of us figured it out :-P

Link to comment
Share on other sites

  • Replies 0
  • Created
  • Last Reply

Top Posters In This Topic

Popular Days

Top Posters In This Topic

Popular Days

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×
×
  • Create New...