Getting Started

This document is for Net Beans based IReports (> Version 3.00). For the Classic version look at re2jClassic.htm.


Introduction

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

  1. A Jasper-Reports JRDataSource for reading Fixed Field Width Data files (both Text and binary) for

  2. A Jasper-Reports JRDataSourceProvider to make it easy to define reports in Jasper-Reports report designers like iReports.

This document describes using the package with iReports. Following is an example of a Report (for a mainframe Cobol file) in iReports:


Requirements

Jasper

Jasper-Reports or iReports (which includes JasperReports) must be installed. This document assumes iReports is installed.

RecordEditor

RecordEditor must be installed.


Installation

Following are the steps to install the package with iReports. Installing with Jasper-Reports is the same (just different install directory):

  1. Install iReports (if not already installed).

  2. Install RecordEditor If not already installed I would suggest using the following


    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

  3. Unzip the re2Jasper zip file into a re2jasper directory.

  4. Copy the following jars from the <RecordEditor install directory>/lib Directories to the re2jasper directory.

    Note: Do not copy the LayoutEdit.jar from <RecordEdit install directory>;/lib

  5. Next you need to Add the Jars / Zip files to the ClassPath. To do this

    1. Start IReport,

    2. Select Tools >>> Options

    3. Select the IReport Icon and the ClassPath tab.  

    4. Enter the RecordEditor / re2jasper jars/zip files in to the panel as above.


Jasper Interfaces

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


Supplied Java Source

 


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


Supplied Example Reports

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


Using with iReport designer

This package can be used with iReports report designer, following is a description of how to do so.


Defining RecordDataSourceProvider

The class RecordDataSourceProvider implements JRDataSourceProvider ands acts as the interface between iReports and the RecordDataSource (file based data source for a report).

Steps:


Using RecordDataSource in a Report

First you need to create a report (File >>> New), then

  1. In the Report Inspector Right Click on the report Name and select Edit Query

  2. Select the DataSource Provider Tag.  

  3. Press the Get fields from datasource to get the RecordEditor layout selection screen

    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

    • A series of fields.
    • A serious of record (which intern consist of a series of fields).

    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

    • PO record
      • Product record 1
        • Store Record 1
        • Store Record 2
        • ...
        • Store Record n
      • Product record 2
        • Store Record 1
        • ...
        • Store Record n
      • etc
    • PO record 2
      • Product record's

    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.

  4. Press the go button to get the field selection screen

  5. Select the fields you want and press ok.

  6. Next if you click on the Objects library and then double click on Fields you should see the fields you selected.

  7. Finally you can click on a field and drag it to the report

Designing a file based in iReports:


Running a Report in iReports

To run the report:

  1. To run a report click on the preview tag

  2. Enter File name and the select the appropriate Layout and record and press go


Jasper interface

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:


Running Reports from Java

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


Using RecordEdit Layouts

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) {


Using Cobol Layouts

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.


Example Report


PO Header Record

Field_PositionField_LengthField_NameType
12Record TypeChar
35Sequence NumberNum Assumed Decimal (Zero padded)
810VendorNum (Right Justified zero padded)
1812PONum Assumed Decimal (Zero padded)
306Entry DateChar
368FillerChar
442beg01 codeChar
462beg02 codeChar
484DepartmentChar
526Expected Reciept DateChar
586Cancel by dateChar
681EDI TypeChar
696Add DateChar
751FillerChar
7610Department NameChar
861Prcoess TypeChar
872Order TypeChar


PO Detail Record

Field_PositionField_LengthField_NameType
12Record TypeChar
39Pack QtyNum Assumed Decimal (Zero padded)
1213Pack CostNum Assumed Decimal (Zero padded)
2513APNNum (Right Justified zero padded)
381FillerChar
398ProductNum (Right Justified zero padded)
7215pmg dtl tech keyChar
8715Case Pack idChar
10150Product NameChar