Understanding Master and Detail Reports

Master and detail reports show hierarchical information. The information is normally retrieved from multiple tables that have a one-to-many relationship, such as customers and orders. The customer information is the master, and the orders are the detail.

Often, you can obtain such information with a single SQR select paragraph. In such a program, the data from the master table is joined with data from the detail table. You can implement break logic to group the detail records for each master record. This type of report has one major disadvantage: if a master record has no associated detail records, then the system does not display it. If you need to show all master records, whether they have detail records or not, this type of report will not meet your needs.

See Understanding Break Logic.

To show all master records, whether or not they have detail records, create a master and detail report with one SELECT statement that retrieves records from the master table, followed by separate SELECT statements that retrieve the detail records that are associated with each master record.

The sample program for Master and Detail Reports produces just such a report. In the example, one BEGIN-SELECT command returns the names of customers. For each customer, two additional BEGIN-SELECT commands are run—one to retrieve order information and another to retrieve payment information.

When one query returns master information and another query returns detail information, the detail query is nested within the master query.