Sample code for EGL report-driver functions

Here are code snippets that show how to fill a report using three different data sources:
  • A database connection
  • A data record
  • A result set from an SQL statement
The following code snippet shows how you might fill a report using a database connection as the data source (the SQL statement is in the .jasper design file):
//Variable declaration
myReport     Report;
myReportData ReportData;

//Function containing report invocation code
function makeReport()
	//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 connection
	sysLib.defineDatabaseAlias("alias", "connectionName");
	sysLib.connect("alias", "userid", "password");
	myReportData.connectionName = "alias";
	myReport.reportData = myReportData;


	//Fill the report with data
	reportLib.fillReport(myReport, DataSource.databaseConnection);

	//Export the report in PDF format
	myReport.reportExportFile = "c:\\temp\\reportDesignFileName.pdf";
	reportLib.exportReport(myReport, ExportFormat.pdf);
end
The following code snippet shows how you might fill a report using your own internal record as the data source. First, you'll need to define a record like the following somewhere outside the program:
Record myRecord type BasicRecord
	author String;
	description String;
	title String;
end
Next you'll write the function to fill and drive the report:
//Variable declarations
myReport     Report;
myReportData ReportData;

recArray        myRecord[];
recArrayElement myRecord;

//Function containing the report driving code
function makeReport()
	//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 
	populateReportData();
	myReport.reportData = myReportData;

	//Fill the report with data
	reportLib.fillReport(myReport, DataSource.reportData);

	//Export the report in HTML format
	myReport.reportExportFile = "c:\\temp\\myReport.html";
	reportLib.exportReport(myReport, ExportFormat.html);
end

function populateReportData()
	recArrayElement.author="Jane Austen";
	recArrayElement.title="Northanger Abbey";
	recArrayElement.description = "British Novel";
	recArray.appendElement(recArrayElement);

	recArrayElement.author = "Jane Austen";
	recArrayElement.title="Emma";
	recArrayElement.description = "British Novel";
	recArray.appendElement(recArrayElement);

	recArrayElement.author = "Charles Dickens";
	recArrayElement.title="Our Mutual Friend";
	recArrayElement.description = "British Novel";
	recArray.appendElement(recArrayElement);

	recArrayElement.author = "Gustave Flaubert";
	recArrayElement.title="Madame Bovary";
	recArrayElement.description = "French Novel";
	recArray.appendElement(recArrayElement);

	recArrayElement.author = "M. Lermontov";
	recArrayElement.title="Hero of Our Time";
	recArrayElement.description = "Russian Novel";
	recArray.appendElement(recArrayElement);
end
The following code snippet shows how you might fill a report using an SQL statement as the data source. This example assumes a default database connection in your program properties file:
//Variable declaration	
myReport     Report;
myReportData ReportData;

//Function containing report driving code
function makeReport()
//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 SQL statement
	myReportData.sqlStatement = "SELECT * FROM dataBaseTable";
	myReport.reportData = myReportData;

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

	//Export the report in text format
	myReport.reportExportFile = "c:\\temp\\myReport.txt";
	reportLib.exportReport(myReport, ExportFormat.text);
end
Feedback
(C) Copyright IBM Corporation 2000, 2005. All Rights Reserved.