Writing code to drive a report

Use the New EGL Part wizard to create a new EGL basic program that uses the report library to run reports.

To create this report driver, follow these steps:
  1. Choose File > New > Program and then select the folder that will contain the EGL source file.
  2. Select a package.
  3. Specify a file name for the source file, select the BasicProgram type and click Finish.
  4. Open the new file in the EGL editor.
  5. In the main() function, just after the program line, type jas followed by Ctrl+space to insert code for the report driver.
  6. In the pop-up window offering data-source connection types and code, select one of the data-source connection types.
  7. You can modify existing code or add your own code. If you modify the code, insert specific values for the placeholders the editor provided. These placeholders might include reportDesignFileName, reportDestinationFileName, exportReportFile, alias, databaseName, userid, password, and connectionName.

Code showing report-invocation information

The following code shows report-invocation information for a report where you specify the SQL statement in the EGL source file, using the default connection in your build descriptor and exporting the file in PDF:
  myReport     Report;
  myReportData ReportData;

	//Initialize Report file locations
  myReport.reportDesignFile = 
		"c:\\workspace\\report_project\\bin\\report_package\\myReport.jasper";
  myReport.reportDestinationFile = "c:\\temp\\myReport.jrprint";

	//Get the report data via a SQL statement
	myReportData.sqlStatement = "Select * From myTable";
  myReport.reportData = myReportData;

	//Fill the report with data
	ReportLib.fillReport(myReport, DataSource.sqlStatement);

  //Export the report in pdf
	myReport.reportExportFile = "c:\\temp\\myReport.pdf";
	ReportLib.exportReport(myReport, ExportFormat.pdf);
Because the backslash character ("\") is used in escape sequences, you must use a double backslash in path names.
Code Explanation
myReport Report; A report library record declaration
myReportData ReportData; A report library data record declaration
myReport.reportDesignFile = "c:\\workspace\\..." Full path to the .jasper design file
myReport.reportDestinationFile ="c:\\temp\\myReport.jrprint"; Full path to the intermediate (destination) work file
myReport.sqlStatement = "Select * From myTable"; The SQL statement used to provide data to the report
myReport.reportData = myReportData; Assigns the data the variable of type Report
ReportLib.fillReport(myReport, DataSource.sqlStatement ); Defines the data source for the report to be an SQL statement
myReport.reportExportFile = "c:\\temp\\myReport.pdf Full path to the file to be created/used for PDF output
ReportLib.exportReport(myReport, ExportFormat.pdf); Specifies the report export format

Related concepts
EGL reports overview
EGL report creation process overview

Related tasks
Creating an EGL report handler
Creating the report design file
Using report templates

Related reference
EGL report handler
EGL library ReportLib
Sample code for EGL report-driver functions

Feedback
(C) Copyright IBM Corporation 2000, 2005. All Rights Reserved.