Jump to content
Changes to the Jaspersoft community edition download ×

pass dataset from main report to subreport without using java code


Recommended Posts

I have a main report and three subreport which use the same sql, that sql is quite time consuming, so for the same sql it runs total four times ( one main + 3 subreport), I want to speed up the processing time by passing the main report dataset result to these three subreport, without using any java code. As I see some post mention to pass the dataset from java to main report parameter, then to subreport parameter, but this is not a option for me, my application is .net based.

Link to comment
Share on other sites

  • Replies 3
  • Created
  • Last Reply

Top Posters In This Topic

Are you passing any custom dataSource to the main report from outside or is the SQL-query just placed within the main-report and takes so long at filling level?

What should happen if you pass the whole main-dataset to the first subreport and this subreport iterates further through the records? If the subreport is finish the internal cursor in your main-dataset is moved forwards and the main-report is actually at the end?!?! So the main and also the next SubReport(s) won't render anything because the first SubReport consumed all records!?!

So you would need a kind of a "copy" of your DataSet. I know that the JRBeanCollectionDataSource does have a cloneDataSource-Method - so I used it within the last years intensive, but not sure, whether you could "copy" or "rewind" a "normal JRDataSource" also. 

Why do you actually use SubReports for the same datasource? What is your intention behind? Do you just want to display some rows from the main-dataset in different ways and filter them out within the SubReport itself?!?



Link to comment
Share on other sites

Hi C-Box

The sql is placed in main report <queryString>, and the three subreport is placed in main report  three different group header, each with expression 


In fact the report is not written by me but I need to maintain this report,

what is group header with expression  $P{REPORT_CONTEXT} means? Mostly I see group heder expression is a field like $F{FIELD_A}, this means the group header will reprint when value of $F{FIELD_A} change. But what happen when group header expression is $P{REPORT_CONTEXT}? it means that group header will just run once for the whole report?

2) Why do you actually use SubReports for the same datasource?

Yes, in fact I think can just copy the content of subreport to the main report corresponding subreport component group header, just set the group header to the size of subreport, right?

Link to comment
Share on other sites

Well, I've never used the REPORT_CONTEXT ... so I guess this is more a workaround in your JRXML to have any expression for your group(s). For let's call "Dummy Groups" you also could leave the groupexpression emtpy or set it to null ... so as the REPORT_CONTEXT probably won't change it's value your groups will be something like "dummy groups" just to have different group header/footer to call different SubReports - so this is my guess.

So as you just have the SQL query inside the main report - there are two ways:

1.) Run this query outside and "wrap" the ResultSet into a DataSource that is cloneable (like JRBeanCollectionDataSource). So you can "reuse" this datasource with the clone() Method in DataSourceExpression  for your SubReport. ... But of course this would need some work in Java, what your initial subject doesn't wanted.

2.) Redesign your main-report to present the records directly within the MainReport and delete your SubReport(s) - if this is feasible. (be aware, if the SubReports itself doesn't have a filter-expression or something like this)

or even 3.) optimize your query.... perhaps there is just an index missing!?!? :-)


hth + regards from sunny Dresden/Germany


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