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

Pass value from SubReport to Main Report and again back to another Sub Report using Shared Variable


meeza4u

Recommended Posts

Hi

I am designing my report using iReport4.5.  I am new to Jasper Reports...

1. My main report displays the detailed transaction

2. First Sub Report say "SUMMARY_RPT" displays the summary by category

3. Second Sub Report say "PARAMETER_RPT" displays the input parameter's used

Here is the requirement.

In my second sub report PARAMETER_RPT I have a field that will give me a title value lets say the Field Name is "MY_TITLE" and the value is "THIS IS MY TITLE" as the output of my query.

How do I pass this MY_TITLE from the second sub report to the main report and would like to display the value in my first sub report SUMMARY_RPT

Or is there a way that I can pass the MY_TITLE directly from my Second Sub report to my First Sub Report using Shared Variable...

if so could you please give me a step by step instruction with what and how to do.. Please help...

 

Thanks

Meeza

 

Link to comment
Share on other sites

  • Replies 5
  • Created
  • Last Reply

Top Posters In This Topic

Top Posters In This Topic

You cannot go backwards with the sharing. If the first subreport literally comes first on the report then it is evaluated prior to the second subreport. If there is a reason it is first and can't be moved after the second then your only real option is to provide another subreport before the first that is only used to run the same query as the second and is blank otherwise. Then you can pass the values from the new subreport to the main and then into the previously labeled first subreport. The second will only be used to display the data that was also queried in the new subreport.

Link to comment
Share on other sites

Agree with theclosh.  But, I'm not sure we're diagnosing the real problem here.

When you say you want to report on the parameters used, which parameters are you talking about?  The parameters that were entered to create your master report (the one with the subreports) or those used from the master to generate the first subreport?

If you want to create a Master report with a SQL Statement based on three params: pOne, pTwo, pThree (for instance).  Then this report calls a SubReport (srOne) using information based on either: pOne, pTwo, pThree or the contents of any/all the retrieved fields ($F{<fieldname>}).  Is that correct so far?

Then, based on what I'm reading, you want the results of some third report, another SubReport (srTwo), to be displayed on the srOne?  Is that correct?

If so, what I've done previously is to create the Master report and place a SubReport onto it.  This SubReport would be passed the necessary information (parameters or $F{<fieldname>} values) and retrieve it's data.  At this point, this SubReport (srOne) already knows about the parameters used to create itself.  They were passed into the report and you should be able to display them in any band you'd like on srOne (since they were available at the time of execution).

IF you are looking for the parameters entered to create the Master report here, why?  You can print them in another band (Summary for instance) on the Master report form.  But, if you really want to show the values from the Master report, you can just pass them to the SubReport (sbOne) - even if they are not used to help retrieve the data, you can still pass them if you want them to be displayed on sbOne.

IF you are looking for 'friendly names' for the criteria, you can still build a SubReport on which ever report you want to display the Parameters_Used for.  I've built reports that call SubReports, that in turn call multiple SubReports, which each call various other SubReports.  I think the one of the invoices I created was a mix/match of One Master collection of SubReports running (optionally based on the data) through 6 -10 layers of SubReports.  So I know you don't have to worry about 'only one layer' of subreports like you may have had to with other products out there.

Hope this helps.  Good luck.



Post Edited by CaptnTony at 04/18/2012 13:54
Link to comment
Share on other sites

Hi CaptnTony,

First thank for a quick response

Sorry if my question was not that clear....

I have 1 master report which is populated using a Oracle Stored Procedure --- till this it works fine.

I then added two sub Reports.

lets say Sub1 and Sub2 in the summary band.

Sub1 displays the summary by category  - uses the same stored procedure used by the master sub report

Sub2 displays the input parameter - this uses a different stored procedure

Sample

Master Report

No.       Name        Categroy       Amount

01        WXY           W001           10.00
02        MMM          W001           10.00
03        WXYZ         W002           10.00
04        MMMZ        W002           10.00

Sub1 <Summary by Category Report>

Category        MyTitle                  <------  this comes from the second sub report
W001              20.00
W002              20.00

Sub2 <The Parameter Report>

User: MeeZa
Title: MyTitle                        <----- this title that you are seeing in the second sub report this is what I want to pass as a shared variable to the Sub1 report.....

Thanks for the help again....

 

Meeza

 

 

Link to comment
Share on other sites

You are able to pass values back to the calling report from any of the SubReports if I recall correctly.  I have been away from iRepors for about a year, so I don't recall 100% but I believe the configuration of the subreport not only has incoming parameters from the report calling it, but also a tab for returned values.

You should then be able to return a value from a subreport to the main report, then pass it to the 2nd subreport and use it there.

 

Todd

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