This document is for Net Beans based IReports (> Version 3.00). For the Classic version look at re2jClassic.htm.
This package makes it easy to design and run reports from Fixed Width Data files including both Cobol and Mainframe Cobol files.
This package provides
This document describes using the package with iReports. Following is an example of a Report (for a mainframe Cobol file) in iReports:
Jasper | Jasper-Reports or iReports (which includes JasperReports) must be installed. This document assumes iReports is installed. |
RecordEditor | RecordEditor must be installed. |
Following are the steps to install the package with iReports. Installing with Jasper-Reports is the same (just different install directory):
Environment | Download Version to Use |
---|---|
Windows & Ms-Access | RecordEdit_Installer_for_MSAccess_065.exe |
Windows | RecordEdit_Installer_for_HSQL_v065.exe |
Linux | RecordEdit_Installer_for_HSQL_065.jar |
Note: Do not copy the LayoutEdit.jar from <RecordEdit install directory>;/lib
JRDataSource | Abstract representation of a Jasper-Reports data source (i.e. source of the data to be written to the report). This package contains a class RecordDataSource which implements JRDataSource |
JRDataSourceProvider | Abstracts the means of creating and disposing a data source. This interface is meant to be the standard way to plug custom data sources into GUI designers. Typically the report developer will implement this interface to create and return a configured data source of the desired type and then configure the designer to use this implementation. This package contains a class RecordDataSourceProvider which implements JRDataSourceProvider |
Class | Purpose |
---|---|
BaseDataSourceProvider | Abstract JRDataSourceProvider |
CopybookToLayout | Class to read a Cobol Copybook into the internal Record-Layout definition. |
JasperConst | Various directories used. You should Check this class before running any of java examples. |
LayoutOptions | Options class. |
RecordDataSource | Most important class in the package. It reads a File and supplies the data in it to Jasper-Reports. It is a Jasper-Reports JRDataSource. |
RecordDataSourceProvider | Interface to Jasper Reports designers like iReports. It is a Jasper-Reports JRDataSourceProvider. |
Zcompile | Sample program to compile a jasper report. |
ZRunCobolRpt | Example of running jasper reports with Report Layouts read from Cobol Copybooks. |
ZRunRpt | Example of running jasper reports with Report Layouts read from |
Sample data files for these reports are in the <RecordEditor install directory>/SampleFiles
Report | Layout | Description |
---|---|---|
amsPO_Chart1.jrxml | ams PO Download | Chart Report built from a unix Text file |
amsPO_Chart2.jrxml | ams PO Download | Chart Report built from a unix Text file
|
amsPo_rpt2.jrxml | ams PO Download | Chart Report built from a unix Text file
|
amsPO_Chart1.jrxml | ams PO Download | Chart Report built from a unix Text file
|
DTAR020_chart1.jrxml | DTAR020 | Chart Report built from a Mainframe (Z-OS) Binary file
|
DTAR020_rpt_1.jrxml | DTAR020 | Report built from a Mainframe (Z-OS) Binary file
|
DTAR020_rpt_2.jrxml | DTAR020_rpt_2 | Report built from a Mainframe (Z-OS) Binary file |
Sample files:
Layout | Sample Files |
---|---|
ams PO Download | Ams_PODownload_20041231.txt
Ams_PODownload_20050101.txt |
DTAR020 | DTAR010_Chart.bin
DTAR020.bin |
This package can be used with iReports report designer, following is a description of how to do so.
The class RecordDataSourceProvider implements JRDataSourceProvider ands acts as the interface between iReports and the RecordDataSource (file based data source for a report).
Steps:
Note: The class name is net.sf.RecordEditor.Jasper.RecordDataSourceProvider
First you need to create a report (File >>> New), then
Follow is the description of the fields on the screen:
Field | Description |
System | The Record Layouts can be grouped into different systems. This Combo Box is used to select a specific System. |
Record Layout | The Record Layout used to format the file. Only layouts belonging to the selected System (above) are displayed. Note: A Record Layout describes the format of a file, each layout consists of either
|
Define fields as numeric | If this check box is ticked, fields defined as numeric in the RecordEditor DB will be defined as numeric in the Report (otherwise they are defined as String which is faster). If performance is an issue, unselect this option and define only those fields that need to be numeric as numeric. |
Report Record | When a file consists of more than one record, you would use this combo box to select which record should be used in the report. i.e. If file consists of
You could choose Store if this is a store level report.
Note: The last record of every record type is available via [record name].[Field Name]
|
Record | In this List box you select the records that contain fields you want to use in the report. Only fields from the selected Records will be returned to iReports. |
Designing a file based in iReports:
To run the report:
When defining a field in Jasper, normally you would supply the RecordEditor field name in the fieldDescription tag as below.
In the following code, the Jasper field PackQty is associated with the RecordEditor field Pack Qty.
When the Jasper field name is the same as the RecordEditor field you do not need to use the fieldDescription tag as below.
For files with more than one type of Record the RecordDataSource stores the last Line of each Record Type for your use. You can access a field in a specific record by using a field name of Record Name.Field Name. i.e. The following example accesses the field beg01 code in the last ams PO Download: Header Line:
To run a report using re2jasper you must have the following jars in the classpath (or for eclipse as external jars).
To run directly from a Cobol Copybook you will also need
The following code from ZRunRpt illustrates running a report using the RecordDataSource and the standard (Database Based) RecordEditor Layout definitions.
Note: Lines 4 and 5 read in the specified RecordEditor layout.
1: JasperReport jasp; 2: String fileName; 3: String inputFileName = SAMPLE_DIRECTORY + dataFile; 4: CopyBookDbReader copybookReader = new CopyBookDbReader(); 5: LayoutDetail copyBook = copybookReader.getLayout(layout); 6: 7: System.out.println(">>> " + rpt + " ~ " + layout + " - " + dataFile); 8: 9: try { 10: jasp = JasperCompileManager.compileReport(REPORT_DIRECTORY + rpt + ".jrxml"); 11: fileName = REPORT_DIRECTORY + rpt + ".pdf"; 12: Map parameters = new HashMap(); 13: RecordDataSource source = new RecordDataSource(copyBook, inputFileName); 14: 15: if (!"".equals(record)) { 16: source.setRequiredRecord(copyBook.getRecordIndex(record)); 17: } 18: 19: parameters.put("ReportTitle", rptTitle); 20: 21: byte[] b = JasperRunManager.runReportToPdf(jasp, parameters, source); 22: FileOutputStream s = new FileOutputStream(fileName); 23: s.write(b); 24: s.close(); 25: } catch (JRException e) {
Following is an example (from ZRunCobolRpt) of running a report from a Cobol Copybook. When running from Cobol you are limited to files with only one record type.
Note: Lines 6 to 13 read in the specified RecordEditor layout.
1: JasperReport jasp = null; 2: String fileName = null; 3: String inputFileName = SAMPLE_DIRECTORY + dataFile; 4: 5: try { 6: CopybookToLayout cobolConv = new CopybookToLayout(); 7: cobolConv.setBinaryFormat(machine); 8: LayoutDetail copyBook = cobolConv.readCobolCopyBook( 9: JasperConst.COBOL_DIRECTORY + layout + COBOL_SUFIX, 10: CopybookToLayout.SPLIT_NONE, 11: Common.LINE_SEPERATOR, 12: null, 13: Common.FIXED_LENGTH_IO, 14: new TextLog() 15: ); 16: jasp = JasperCompileManager.compileReport(REPORT_DIRECTORY + rpt + ".jrxml"); 17: fileName = REPORT_DIRECTORY + rpt + ".pdf"; 18: Map parameters = new HashMap(); 19: RecordDataSource source = new RecordDataSource(copyBook, inputFileName); 20: 21: byte[] b = JasperRunManager.runReportToPdf(jasp, parameters, source); 22: FileOutputStream s = new FileOutputStream(fileName); 23: s.write(b); 24: s.close(); 25: } catch (JRException e) {
To run with windows / unix text files (on a windows / unix box) the machine on line 6 above becomes CopybookToLayout.FMT_INTEL For IBM Mainframe files use CopybookToLayout.FMT_MAINFRAME.
Field_Position | Field_Length | Field_Name | Type |
---|---|---|---|
1 | 2 | Record Type | Char |
3 | 5 | Sequence Number | Num Assumed Decimal (Zero padded) |
8 | 10 | Vendor | Num (Right Justified zero padded) |
18 | 12 | PO | Num Assumed Decimal (Zero padded) |
30 | 6 | Entry Date | Char |
36 | 8 | Filler | Char |
44 | 2 | beg01 code | Char |
46 | 2 | beg02 code | Char |
48 | 4 | Department | Char |
52 | 6 | Expected Reciept Date | Char |
58 | 6 | Cancel by date | Char |
68 | 1 | EDI Type | Char |
69 | 6 | Add Date | Char |
75 | 1 | Filler | Char |
76 | 10 | Department Name | Char |
86 | 1 | Prcoess Type | Char |
87 | 2 | Order Type | Char |
Field_Position | Field_Length | Field_Name | Type |
---|---|---|---|
1 | 2 | Record Type | Char |
3 | 9 | Pack Qty | Num Assumed Decimal (Zero padded) |
12 | 13 | Pack Cost | Num Assumed Decimal (Zero padded) |
25 | 13 | APN | Num (Right Justified zero padded) |
38 | 1 | Filler | Char |
39 | 8 | Product | Num (Right Justified zero padded) |
72 | 15 | pmg dtl tech key | Char |
87 | 15 | Case Pack id | Char |
101 | 50 | Product Name | Char |