Example 4gl code

 

To incorporate the BIRT engine to a 4gl-based application, you need to write your 4gl source code and create and style your report.

 

Here you can find the source code for our basic examples, provided with some general explanations.

To create our own basic example, just copy the code to your .4gl source file.

 

Step 1

Import JAVA classes:

 

import java java.util.logging.Level

import java org.eclipse.birt.core.framework.Platform

import java org.eclipse.birt.report.engine.api.EngineConfig

import java org.eclipse.birt.report.engine.api.HTMLRenderOption

import java org.eclipse.birt.report.engine.api.IReportEngine

import java org.eclipse.birt.report.engine.api.IReportEngineFactory

import java org.eclipse.birt.report.engine.api.IReportRunnable

import java org.eclipse.birt.report.engine.api.IRunAndRenderTask

 

Step 2

Define the necessary variables of the corresponding JAVA classes:

 

define config EngineConfig

define factory IReportEngineFactory

define engine IReportEngine

define design IReportRunnable  

define task IRunAndRenderTask

define html_opts HTMLRenderOption

define birt_home_dir string

 

For greater details about the supported classes, refer here.

 

Step 3

Create a JAVA object which will store the report:

 

let birt_home_dir = fgl_getenv("LYCIA_DIR") || "\ReportEngine"

let config = EngineConfig.create()

call config.setBIRTHome(birt_home_dir)

call Platform.startup(config)

        

let factory = Platform.createFactoryObject("org.eclipse.birt.report.engine.ReportEngineFactory")

let engine = factory.createReportEngine(config)

 

Step 4

Initialize the template for a future report:

 

let design = engine.openReportDesign("Birt_no_param.rptdesign")

 

Refer here and here to find out how to create and edit report templates.

 

Step 5

Run and render the future report:

 

let task = engine.createRunAndRenderTask(design)

 

Step 6

(optional)

Specify the report parameters:

 

call task.setParameterValue("address_menu", "Red%")  -- Red% standing for any city starting with Red like Redmond

call task.validateParameters()

 

Refer here to find out how to set parameters of the report in the Report Design view.

In the simplest possible example - which supposes no reports - this step can be omitted.

 

Step 7

Specify the output file:

 

let html_opts = HTMLRenderOption.create()

 

Specify the folder to save the output file:

 

call html_opts.setOutputFileName("Birt_no_param.html")

 

Step 8

Create the report (possibly provided with some explanations displayed to Lycia Console):

 

call task.setRenderOption(html_opts)

display "HTML render task is running..."

call task.run()

 

Step 9

Shutdown the report engine (possibly provided with some explanations displayed to Lycia Console):

 

call task.close()

call engine.destroy()         

call Platform.shutdown()

display "Report has been saved into file:"

display "C:\ProgramData\Querix\Lycia\progs\Birt_no_param.html"

 

 

 

Example programs:

CVS server: client.querix.com

CVS repository: /lycia_doc_examples

User: client

Project: birt

Program: birt_no_param

                     birt_with_param