Tutorial Chapter 9: Reports |
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.
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.
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.
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.
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: