The report driver

The report driver retrieves data, starts the report engine and sends the data (as input records) to be formatted by the REPORT routine.

Usage

A report driver can be part of the MAIN program block, or it can be in one or more functions.

The report driver typically consists of a loop (such as WHILE , FOR, or FOREACH) with the following statements to process the report:

Table 1. Report driver statements
Instruction Description
START REPORT This statement is required to instantiate the report driver.
OUTPUT TO REPORT Provide data for one row to the report driver.
FINISH REPORT Normal termination of the report.
TERMINATE REPORT Cancels the processing of the report.

A report driver is started by the START REPORT instruction. Once started, data can be provided to the report driver through the OUTPUT TO REPORT statement. To instruct the report engine to terminate output processing, use the FINISH REPORT instruction. To cancel a report from outside the report routine, use TERMINATE REPORT (from inside the report routine, you cancel the report with EXIT REPORT).

In order to handler report interruption, the report driver can check if the INT_FLAG variable is TRUE to stop the loop when the user asked to interrupt the report execution.

It is possible to execute several report drivers at the same time. It is even possible to invoke a report driver inside a REPORT routine, which is different from the current driver.

The programmer must make sure that the runtime system will always execute these instructions in the following order:

  1. START REPORT
  2. OUTPUT TO REPORT
  3. FINISH REPORT

Example

SCHEMA stores7
MAIN
  DEFINE rcust RECORD LIKE customer.*
  DATABASE stores7
  DECLARE cu1 CURSOR FOR SELECT * FROM customer 
  LET int_flag = FALSE
  START REPORT myrep 
  FOREACH cu1 INTO rcust.*
     IF int_flag THEN EXIT FOREACH END IF
     OUTPUT TO REPORT myrep(rcust.*)
  END FOREACH
  IF int_flag THEN
    TERMINATE REPORT myrep 
  ELSE
    FINISH REPORT myrep 
  END IF
END MAIN