The Report Definition
The report definition uses a REPORT
program block to format the
input records.
REPORT
is global in scope. It is not, however, a function; it is not
reentrant, and CALL
cannot invoke it.
The code within a REPORT
program block consists of several sections, which must
appear in the order shown.
The DEFINE section
Here you define the variables passed as parameter to the report, and the local variables. A report can have its own local variables for subtotals, calculated results, and other uses.
The OUTPUT section (optional)
Although you can define page setup and destination information in this section, the
format of the report will be static. Providing this same information in the START
REPORT
statement provides more flexibility.
The ORDER BY section (optional)
Here you specify the required order for the data rows, when using grouping.
Include this ORDER BY
section if values that the report definition receives from
the report driver are significant in determining how BEFORE GROUP OF
or
AFTER GROUP OF
control blocks will process the data in the
formatted report output. To avoid the creation of additional resources to sort the data,
use the ORDER EXTERNAL
statement in this section if the data to be used
in the report has already been sorted by an ORDER BY
clause in the SQL
statement.
The FORMAT section
Here you describe what is to be done at a particular stage of report generation. The
code blocks you write in the FORMAT
section are the heart of the report
program block and contain all its intelligence. You can use most BDL statements in the
FORMAT
section of a report; you cannot, however, include any SQL
statements.
BDL invokes the sections and blocks within a report program block nonprocedurally, at the proper time, as determined by the report data. You do not have to write code to calculate when a new page should start, nor do you have to write comparisons to detect when a group of rows has started or ended. All you have to write are the statements that are appropriate to the situation, and BDL supplies the "glue" to make them work.
You can write control blocks in the FORMAT
section to be executed for the
following events:
- Top (header) of the first page of the report (
FIRST PAGE HEADER
) - Top (header) of every page after the first (
PAGE HEADER
) - Bottom (footer) of every page (
PAGE TRAILER
) - Each new row as it arrives (
ON EVERY ROW
) - The start end of a group of rows (
BEFORE GROUP OF
) - a group is one or more rows having equal values in a particular column. - The end of a group of rows (
AFTER GROUP OF
) - in this block, you typically print subtotals and other aggregate data for the group that is ending. You can use aggregate functions to calculate and display frequencies, percentages, sums, averages, minimum, and maximum for this information. - After the last row has been processed (
ON LAST ROW
) - aggregate functions calculated over all the rows of the report are typically printed here.