Working with sub reports
Genero Report Writer video scripts
Related video: Working with Sub-Reports
Description: Create a report that calls other reports, to be displayed in a single master report.
Tags: Genero Report Writer, sub report, master report
Presentation |
Script |
Intro splash |
|
Slide 1 |
In this presentation, you will learn about sub reports: what they are and how to make use of them in Genero Report Writer. |
Slide 2 |
Consider this scenario: You have created one report that graphs your data using a pie chart. You have also created a report that summarizes your data in a list format. The list report provides the detail that backs up the pie chart.
You can distribute the two reports at the same time – one report containing the pie chart, the other containing the list report. You would run your report application twice and output two separate reports. It would be up to you to somehow distribute these reports as a package.
With the introduction of sub reports in version 2.32 of the Genero Report Writer, you now create a master report that calls sub reports. Create a master report that includes the graph report and the list report. Executing the master report outputs the sub reports to a single report deliverable, whether a single file, a single PDF, or a single tab in the Genero Report Viewer.
The goal for this demo is a simple one – to have these two reports output as a single report deliverable. Sub reports have many more uses – re-using part of a report across multiple reports, for example – but this simple demo provides a good introduction on how to implement sub reports.
What do you need to do to create a master report that uses sub reports? This is the process at a high level. You will see each step in detail during the demonstration.
Start by creating the reports that you will include in the master report. You will want these available when it comes time to specify the sub reports.
Add a master report to your report application. Within the master report, call your sub reports.
Compile your report application and generate a new RDD file.
Create a new report design document, specifying the master report for the data schema. If multiple REPORT blocks are in your report application, you select the master report block when you add the data schema.
Once the Report Structure displays, assign the appropriate sub report to each of the sub report triggers.
The report is ready to execute. |
Demo – show two reports we are using |
Start with the first step. Create the reports that will become your sub reports. It is best to have the reports created and tested prior to including them as sub reports.
For the demonstration, the reports will be two reports included with the Reports sample project: the MapChart Revenue by Customers report and List Demo report.
The MapChart Revenue by Customers presents a pie chart showing the revenue by customer.
The ListDemo report provides the detail for each customer, including the dollar total for each customer – which maps to the revenue total for each customer shown in the pie chart. |
Slide 3 |
The next step in the process is to update the report application to include a master report calling one or more sub reports.
In the master report block, you call the sub-reports with their own START REPORT, OUTPUT TO REPORT, and FINISH REPORT statements. The START REPORT statement cannot be in a function called by the master report block, it must be in the master report block. It does not take any arguments.
Look at the sample code shown here. See the two sub reports, detailreport1 and detailreport2, each with their own START REPORT, OUTPUT TO REPORT, and FINISH REPORT statements.
If you look at the function that will call the master report, notice that its START REPORT statement does take the argument TO XML HANDLER. The master report is responsible for the data streaming to the Genero Report Engine. The sub reports are children, if you will, of this master report.
There are some additional restrictions when it comes to specifying sub reports, you can read more in the Genero Report Writer documentation.
When you have finished updating your report application, compile your file and generate a new RDD file. |
Demo – code tour of OrderReport.4gl |
For this demo, examine the Reports sample application.
Access the function runTwice. This is the function called when the user selects to run one of the master reports. You see that it includes START REPORT report_all_orders_twice TO XML HANDLER handler.
Look at the REPORT block report_all_orders_twice.
Under the FORMAT ON EVERY ROW, there are two sub reports set up. Each sub report involves a START REPORT, an OUTPUT TO REPORT without arguments in a WHILE loop, and a FINISH REPORT.
In this sample application, both are calling the same sub report block, report_all_orders. Understand they could have been calling different report blocks.
They are also both under ON EVERY ROW. Understand that a sub report can be called from anywhere where printing in loops is allowed – a sub report can be located under ON EVERY ROW, BEFORE GROUP, AFTER GROUP, or ON LAST ROW.
For this demo, however, we have both sub reports under ON EVERY ROW, and they both call the same REPORT block.
After making any changes to the report application, you compile your application and create a new RDD. |
Slide-4 |
The next step involves creating the report design for the master report. Start with an empty report. When you specify the data schema – the part of that RDD that maps to the master report – sub reports appear as nodes in the data view and sub reports appear as triggers in the Report Structure. Place your OnEveryRow trigger under the Page Root. The sub report triggers remain under the OnEveryRow trigger. Specify a report for each of the Sub Report triggers. |
Demo |
Continuing with the simple demo:
Create a new, empty report.
From the Data View tab, select the OrderReport.rdd. There are two REPORT blocks to choose from. Select report_all_orders_twice.
Take a look at the Data View. See the two sub report nodes.
Take a look at the Report Structure. See the two sub report triggers.
Move the OnEveryRow trigger under the Page Root.
And specify the reports.
Select the first Sub Report trigger. Under its Properties, specify the URL by selecting the name of the first report to include. Pick the chart report, MapChart-byCat.4rp.
Select the second Sub Report, and for its URL select ListDemo.4rp.
Save your report with a new name.
While this has been done already for this demo, you would modify your form to include the new report name as an option from the ComboBox. You would also modify your report application so that the report_all_orders_twice report block is called when your new report is selected.
Compile the application if needed, run the application and select your master report.
The result: both the chart and the list report are included in the master report output. |
Demo |
Look at the sample MasterReport provided with the sample Reports project.
In this report, the Report Structure shows that under the OnEveryRow trigger, two MiniPages are defined, to hold the two sub report triggers.
You can use the MiniPage to limit the space that a sub report will occupy. In this sample, the first report is a graph that is designed to take up the max space of its parent minipage. By placing it on a MiniPage with a height set at 10 cm, you guarantee that the graph will only take up half of the first page of the report. |
Slide 5 |
This concludes the demonstration and the introduction to sub reports. For more on sub reports, refer to the documentation. For other topics, be sure to check out the other Genero Report Writer videos. |