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.

Create a report composed of other reports

You have two reports that you want to output as a single report. 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 part across multiple reports

Consider an order confirmation report and an invoice report. The two reports could share a table containing the sales items and their descriptions (the shared part). You can put that table in a sub report. Changing the sub report then changes the two reports using the sub report.

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