Jump to content
We've recently updated our Privacy Statement, available here ×

Using one subreport several times with different results


michael.melisek
Go to solution Solved by joseng62,

Recommended Posts

Hi, 

I would like to create a report which contains some header information and three tables under it, each of which contains a list of a different group or articles. i will call those A B and C.

I have been able to create a report with a single subreport showing only group A however, i cant wrap my head around how i could create it for all three.

The tables will have the exact same design so i wouldnt like to copy them and create new subreports.

If possible i would like to use the same report three times and just pass a different parameter for A B and C output (i can design the query in such way that it uses this parameter)

One of my requirements is that if the list of articles does not contain some groups (for example C) then that group will not be printed and will not leave any empty space (only lists of group A and B will be printed)

Currently the subreport is in the detail band, so that for every article i get a row.

My questions are:

Is it possible to use a single parameter three times with different value each time? (How would i set it up, pass the parameters, can i define them somewhere for a single report?..)

How do i place the same subreport three times in the master report? (Should i use three detail bands? single detail band with some print settings so that it prints it for each value of the parameters?..)

Is there maybe some better way i have not though of?

 

I was not able to find the solution for this so far. I am a beginner, please be patient with your explanations.

Thank you for your help.

 

Link to comment
Share on other sites

  • Replies 3
  • Created
  • Last Reply

Top Posters In This Topic

  • Solution

Hi Michael, seem you need some guidance on this one. 

So I am assuming your will get the groups from the sql. 
So first of all create a group and in the group epxression create the logic for the grouping there. 
So example of you have a $F{group} from sql then just use that fields or maybe some if logic. 
$P{group}.contains("GroupA")
? A : $P{group}.contains("GroupB")
? B : $P{group}.contains("GroupC") 
? C : ""

Then you make use of the group header band or footer band and add your subreport there. 
(Just a note, you mentioned using a table, so if the case , just use the table element instead of subreport.)

Ok so know you need to pass over a parameter from main report to subreport or table element. 
So if subreport, then click on the subreport element, in the property tab, select "subreport", then you see a "Edit Parameter". This is where you link any main parameter, field or variable with your subreport parameters. 
You need to create a parameter in your subreport. Remeber to update your subreport jrxml then safe, then compile to create/update the .jasper file. 

if table, then you will make use of a dataset, so create the parameter in the dataset. Then same logic above, click on table element in properties tab, select "Dataset", then "Parameters"
 
Other option is that you could make use of 3 table or 3 subreport and just use the print when expression, but do not add this in the detialed band as you will get a lot of subreport/tables generating based on you main report row count. 
So if your data returns 3 rows in main report and you have 3 tables/subreport in your main detailed band, you will generate 9 table or subreports. 
This is ok if it is what you want to achieve, but can create a out of memory and loop issues when you main and subreport returns a lot of row possibilites. 

Hope all of this helps. 

Kind Regards 
joseng







 

Link to comment
Share on other sites

Hi,

you perfectly answered what i needed to know.

When i created a group, i only pressed on the required field containing the types and thats it. No need for any expression.

Then i created a parameter in the subreport and linked it to the same field. I also use the same parameter in the subreport select.

The subreport now prints for every type in the main select, without the need of print when expressions. The key is to place it in the group.

It also works with tables and lists so i might be able to find a different solution than a subreport.

 

Link to comment
Share on other sites

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...