When to use sub reports
Sub reports offer a solution for specific reporting scenarios.
Before implementing a sub report solution, ensure it is the best fit for your reporting needs. Genero Studio contains other options for combining and duplicating data, for example, you could create a custom data source or use a report schema transformation. For a comparison of these options, see Options for data operations in reports.
A master report can include linked sub reports (where each sub report is maintained in its own design file) or inline sub reports (where the master and sub reports share one design file).
Linked reports
- Create a report composed of other reports. For example, you have a report that is a graph showing revenue by region, and you have a list report providing the details on the revenue by region. You can create a master report that outputs both of these reports (the graph report and the line detail report) as one report.
- Reuse a report fragment across multiple reports. In this case, you create a sub report containing only the re-usable fragment, and the sub report cannot be used standalone. For example, you have an order confirmation report and an invoice report and you want them to share a table containing the sales items and their descriptions. You put that table in a sub report and link that sub report to two master reports. Changing the sub report then changes the two master reports.
Inline reports
- Keep all your report design in one document
- Group, order, and aggregate data more than once per report (for example, a grouped list of customers grouped by areas followed by a list of products grouped by types).
- Create a report where a sublist has more than one sort key item
Imagine you have a report with two loops, where each loop defines a sublist:
REPORT report(r) ... FORMAT ON EVERY ROW PRINT r.* #loop1 DECLARE c1 CURSOR FOR SELECT * FROM t1 WHERE t1.key=r.t1key ORDER BY a,b,c FOREACH c1 INTO t1.* PRINT t1.* END FOREACH #loop2 DECLARE c12 CURSOR FOR SELECT * FROM t2 WHERE t2.key=r.t2key ORDER BY id FOREACH c2 INTO t2.* PRINT t2.* END FOREACH END REPORT
Should the loops loop1 and loop2 be replaced by sub reports?
Loop1 specifies three sort key items in the
ORDER BY
clause. Replacing loop1 with a sub report usingORDER EXTERNAL a, b, c
gives you the flexibility to "trigger" on a, b, and c in the design.Replacing loop2 by a sub report would not provide any gain (assuming there is no interest to group on
id
). For this loop, you might prefer to see the whole design.
Do NOT use sub reports to process nested sub lists
Genero reports support arbitrarily complex models using PRINT
statements inside
iterator statements (WHILE
, FOR
, FOR EACH
) and
conditional statements (IF
, CASE
). It is not necessary to use sub
reports for this purpose. When sub reports are used for this purpose to produce complex reports
(such as an invoice report), the report becomes scattered across numerous BDL REPORTs and report
design (4rp) files, obscuring the overall structure. The impossibility to see the design as a whole
must be taken into consideration when using this strategy.