Using one subreport several times with different results

0

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.

 

michael.melisek's picture
Joined: Oct 12 2018 - 5:15am
Last seen: 1 year 1 month ago

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.

 

michael.melisek - 1 year 1 month ago

Okay so now i have the three main groups and i use a simple list in the group footer to display the data.

Is it possible to create sub groups in each group, with different smaller headers?

I would like to order and label the articles by their sub-type.

Thank you.

michael.melisek - 1 year 1 month ago

1 Answer:

1

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







 

joseng62's picture
732
Joined: Dec 5 2014 - 2:43am
Last seen: 5 days 4 hours ago
Feedback
randomness