Run multiple reports from one data stream

To use the same data in more than one report, create a snapshot of the data and produce the reports from this snapshot.

Data is continually changing in today's fast-paced environment. Each time you run a query against a database, you expect to have a different result set. Even if two queries are run within a second of each other, the data might change in that time.

In most cases, real-time data gathering is an advantage. However, you might want to create a series of reports to represent the same data set. Consider the scenario where you create an overview report for marketing and a deep-dive report for data analytics. If you simply run the report twice, and the data changes between the two runs, the information will be inconsistent.

To solve this problem, create two applications:

  • The first application captures the data in an XML file.
  • The second application uses that XML data file to create your reports.

Capture the data

In the first application, create a report application that includes the fgl_report_createProcessLevelDataFile() function. This function instructs the Genero Report Engine to output the data to an XML file.

Tip: Use the Report from Database wizard to generate the code, and add the fgl_report_createProcessLevelDataFile() function.

For example, the following code creates an XML file called accountfile.xml:

FUNCTION run_myReport_to_handler(handler)
    DEFINE
        data myReport_data,
        handler om.SaxDocumentHandler
    DECLARE cur CURSOR FOR
        SELECT 
            account.*
        FROM 
            account

    LET handler = fgl_report_createProcessLevelDataFile("accountfile.xml")
            
    START REPORT myReport_report TO XML HANDLER handler
    FOREACH cur INTO data.*
        OUTPUT TO REPORT myReport_report(data.*)
    END FOREACH
    FINISH REPORT myReport_report
    CLOSE cur
END FUNCTION

Ensure that the Compiler Options property of the .4gl file containing the REPORT block is set to --build-rdd, so that a data schema (.rdd) file will be built. For more information about .rdd files, see Generate a data schema from a Genero BDL report program.

Note: Alternatively, you can use the fgl_report_setProcessLevelDataFile() function to create the XML file at the same time as another report.

Create the reports

In the second application, include the fgl_report_runReportFromProcessLevelDataFile() function. This function runs a report using the XML data file you created in the first application.

The section application also specifies the report design documents (.4rp) for the required reports. All report design documents must use the data schema created by the first application.

For example, the following code creates two reports using the same XML data file. The quickreport.4rp report design document displays the data in a simple list, and the chartreport.4rp document displays the same data using business graphs.

MAIN

DEFINE xmlfile STRING
DEFINE listreportname STRING
DEFINE chartreportname STRING
DEFINE result INTEGER
DEFINE grw_handler om.SaxDocumentHandler

LET xmlfile = "accountfile.xml"
LET listreportname = "quickreport.4rp"
LET chartreportname = "chartreport.4rp"

IF fgl_report_loadCurrentSettings(listreportname) THEN
    LET grw_handler = fgl_report_commitCurrentSettings()
    LET result = fgl_report_runReportFromProcessLevelDataFile(grw_handler,xmlfile)
ELSE 
    EXIT PROGRAM 
END IF

IF fgl_report_loadCurrentSettings(chartreportname) THEN
    LET grw_handler = fgl_report_commitCurrentSettings()
    LET result = fgl_report_runReportFromProcessLevelDataFile(grw_handler,xmlfile)
ELSE 
    EXIT PROGRAM 
END IF 

END MAIN