INFORMIX-4GL Reports Overview

Many relational database management applications are designed to produce a report that contains information from the database. A 4GL report can arrange and format the data according to your instructions, and display the output on the screen, or send it to a printer, or store it as a file for future use.

To write a report, a 4GL program must include two distinct components:

A report driver specifying what data the report includes

A REPORT routine (also called the report definition) that formats the data

The report driver (also called the calling routine) retrieves the specified rows from a database, stores their values in program variables, and sends these, one input record at a time, to the REPORT routine. After the last input record has been received and formatted, 4GL calculates any aggregate values (such as frequency counts, sums, or averages) that are based on all the data, and then sends the entire report to some output device.

The Report Driver

The report driver invokes the report, retrieves data, and sends the data (as input records) to be formatted by the REPORT routine. The report driver can be part of the MAIN program block or can be a 4GL function.

It requires three special-purpose statements to interface with the REPORT routine:

START REPORT

OUTPUT TO REPORT

FINISH REPORT.

These elements of the report driver can appear in different program blocks, but they are typically embedded within a FOR, FOREACH, or WHILE loop:

4GLREF00000000.gif

The typical report driver performs the following actions:

Declares a cursor (associated with a SELECT statement of SQL) to retrieve the necessary rows from a database, and to sort them in a useful order.

Uses START REPORT to initialize the report.

Begins a FOR, FOREACH, or WHILE loop to control the repeated fetching of rows, and the creation of input records for storing the retrieved data.

Uses OUTPUT TO REPORT to pass input records to the REPORT routine.

Terminates the loop (with the END FOR, END FOREACH, or END WHILE keywords) after all the desired values have been passed to the report.

Uses FINISH REPORT to execute any statements in ON LAST ROW control block and calculate any aggregate values for the entire report.

Structure of the REPORT Definition

The REPORT routine specifies how to format input records. Like the MAIN or a FUNCTION routine, it is a program block. It can contain control blocks with statements for producing headers, footers, and calculating aggregate values.

From the report driver, the REPORT routine receives data in sets called input records. These can include program records, but other data types are also supported. Each input record is formatted and printed, as specified by control blocks and statements within the REPORT routine. Most 4GL statements and functions can be included within a REPORT routine, and certain specialized statements and operators for formatting output can appear only in a REPORT routine.

4GLREF00000001.gif

argument is the name of a formal argument that the driver passes to the report. The list of identifiers is called the argument list. (You can include arguments of the RECORD data type in this list, but you cannot append the .* symbols here to the name of the record.)

report is the 4GL identifier that you declare here for the report.

The report name and the argument list (enclosed in parentheses) are called the report prototype. In its syntax, this resembles the prototype of a function.

To format input records, the typical REPORT routine performs these actions:

Specifies a REPORT prototype to declare the report name and the names of the formal arguments of the input records that the report will format.

Uses a DEFINE section to declare formal arguments and local variables.

Uses control blocks within the FORMAT section to produce headers,

footers, and formatted output of the data in the input records.

Terminates processing the data with the END REPORT keywords.