Jasper Report - Return Sub Report Variable Value in to Main Report

Monday, June 02, 2014 Unknown 7 Comments


In here I’m using

Product Version: Jaspersoft iReport Designer Professional 5.0.0
Java                    : 1.6.0_45
System                  : Windows 7

First you need to create a variable inside your sub report
In this example I have created the variable called SUB_Rec_Year_2_249 as Big decimal.
And get Sum of the Variable expression value with reset type of Report

Then In your Main report, create variable with Name and Type. In this example it is GET_SUB_Rec_Year_2_249 as Big decimal.
So this variable calculation type should be System and also reset type should be None.
So the select the sub report that imported to the main report and view the properties. In the properties , you can find Return values 
Then click on Return value icon, and then you can see the set of return values from sub report in to main report. But initially it not display anything, After you setting the return values it display the Sub report Variable (A variable from sub report) and Destination Variable(Variable name inside main report)



In this Return value window, click on Add button then it display the Sub report and Main report variable mapping window. This window contains two drop down boxes, sub report variable and local destination variable.
In this sub report dropdown list normally not display the variable names that we created. So please copy the exact variable name from sub report the paste here. According to the example this sub report variable name should be SUB_Rec_Year_2_249. Then local destination variable drop down, select the variable that we created to get return value from sub report. According to the example this local destination variable name should be GET_SUB_Rec_Year_2_249. Calculation type is Nothing and click on Ok button.

Then you can see this sub report and main report variable mapping added in to the return values mapping list. In here you can modify or delete the variable mapping if you needed.

So now you can get the sub report variable value using the main report variable.
In practical scenario, You can get this return values below the sub report inclusion

7 comments:

  1. Followed above steps and i am getting null

    ReplyDelete
  2. Me ayudó bastante el artículo.Mil gracias.Saludos desde Ecuador.

    ReplyDelete
  3. set Reset type: report in main report for fix null value

    ReplyDelete
  4. thanks i return value from subreport to main report, can you please share the detail flow as same for same variable pass from main report to subreport

    ReplyDelete
  5. thanks i return value from subreport to main report, can you please share the detail flow as same for same variable pass from main report to subreportSubzeros repair in Orange County

    ReplyDelete