Lesson 2:  Using Report Wizards

You can build a report in JReport in one of the following two ways:

In this lesson you will learn:

What is a report in JReport?

Before you continue, you may want to review the basic definitions and some of the terminology used to describe JReport and its components.

The simplest type of report is called the "standard report".  Below is an example of a standard report with the title "Customer Sales Report".  Detail customer records are grouped by Country and within each country by Region.  The Sales from last year are totaled for each Region and for each country.


Customer Sales Report

Country:     USA
State:         CA
City Customer Name Phone Number

Annual Sales

Cupertino The Island Coffee (408) 777-0001 $98,239.00
Irvine Cafe International (714) 243-9548 $51,958.00
Los Gatos International Coffee Hut (650) 867-9879 $81,349.00
Palo Alto Automatic Java Machines (650) 239-4690 $74,986.00
San Francisco Cafe San Francisco (415) 288-9090 $67,823.00

Annual Sales Totals:

$374,355.00
State:           New York
City Customer Name Phone Number Annual Sales
Dix Hill The Ultimate Bean (212) 938-4491 $54,738.00
New York City Starmug Coffee (212) 834-9082 $101,001.00
New York City Absolute Java (212) 946-3462 $50,600.00
Scarsdale The Java King (914) 657-9823 $78,321.00

Annual Sales Totals:

$284,660.00


Annual Sales Total in the USA:      $659,015.00


Building a report from a database is time consuming, but with JReport, it only takes a matter of minutes to compile your data into a professional looking report.

How to Create a Simple Report using the Report Wizard

  1. Start JReport according to the instructions in Lesson 1.
     
  2. When the Choose Report dialog appears, you first need to make certain you are using the correct catalog. For this tutorial you should use the Tutorial catalog:

    c:\jreport\Demo\Reports\Tutorial\Tutorial.cat

    where c:\jreport is the path where you installed JReport. You can use the browse button to browse to the catalog file, or just type the path in the Catalog field.
     
  3. With the New tab active, click the Standard icon to select it.
     
  4. Now click the Create button to launch the report wizard.


     
  5. With the first three tabs of the Standard Report Wizard you will specify the source of data and select which ones to be displayed.
    • Data tab - Select data source from all data objects to form a Working Set
    • Query tab - Define a query to retrieve the Working Set data for the report
    • Fields tab - Select a subset of Working to display in the report

    Let's first look at the Data tab.  Here you must choose the objects you are interested in from the All Objects list and place them into the Working Set list.  For this example, open the Connections item.  Next click the Jinfonet data source and select the Customer table.  Click the button to add all of the fields in the table to the Working Set. You can also open the table and add individual fields one by one to the Working Set.
     

  6. By placing the objects in the Working Set, you have implicitly instructed JReport to create a Query, which will retrieve all of the data you will need for the report.

  7. Click the Query tab.  Here the table(s) you selected are shown and you can add search conditions in the grid below.   For this example, we want to compare the sales in California and New York.   Therefore, will type USA in the Country column and NY and CA in the Region column.  The ='xxx' automatically appears so you do not have to type those characters in as seen in the example.
     
    l2f3.gif (9199 bytes)
     
  8. Click the Display tab. 
     
    Usually not all of the fields from a Query need to be visible in a report.  Therefore, you must indicate which fields to display by selecting the objects from the Working Set and adding them to the list on the right. 
     
    For this example, select: City, Customer Name, Phone, Fax and Annual Sales  to display in the report.
     
  9. Click the Group/Sort tab.
  10. Note: Records in a report are usually organized into groups based on certain criteria.   With the Group/Sort tab you can enter the criteria to define multi-level groups.  You can also specify the ordering of groups and ordering of records within each group.

    For this example, we will group the data by selecting Country and then by Region. The arrows beside the field names indicate the sorting sequence of the groups. You can choose from descending order (ex: c,b,a), ascending order (a,b,c) or specify a special ordering criteria (indicated by "S").

  11. Next you can sort records within the groups you create by clicking the Sort tab and selecting the sorting fields. For this example, choose the City field to sort the records, as shown below.
     

  12.  

  13. Click the Summary tab to specify summary functions.
  14. To generate a total sales amount for each Region group, select Last Year's Sales, click the to move it to the Summary Fields.  The Function drop down list allows you to select a summary function like sums, counts, minimums, maximums, etc.  We will select Sum for this example to see a total of Last Year's Sales

    The Function is computed when the Break Field changes value at the end of a group.  Clicking the Region field will cause a sum to be created for each Region group.  Leave the Grand Total column checked so that we get a total sum of last year's sales in the country.

  15. Skip the Graph tab. You will not be adding a graph to this report.
     
  16. Now click the Styles tab and enter a title for the report: "Customer Sales Report". On this panel you can also specify report style, page orientation. We chose to use Left Alignment in the Style menu.

     
  17. Click Finish to generate the report.
     
    When the report design window appears, you can make any adjustments you like to the report layout.  The Report Inspector can be used to examine and change the objects in the report. The Catalog Browser can be used to add additional objects to the report.

  18. l2f9.gif (9061 bytes)
     
  19. Click on the View tab to run your report and view it.  What you are seeing is a very rough copy of your report.

    l2f10.gif (7963 bytes)
  20. Edit and complete your report.

    Now you are ready to finely tune your report and give it a professional look.  Report Wizard provides you with a quick start but JReport provides a wealth of tools for you to adjust the report to your preference.  Use the Report Inspector to change font, size, position, and other variable.  Do not forget that you can also move items anywhere in the Design view.  Try to insert labels and texts and place objects in headers/footers and details. 


How to Place Parameters in Your Report

What is a Parameter?
Frequently you need to specify a parameter when running a report.  For example, you may want to input an order date as an input parameter when running a report so that only orders on that date will be displayed.  Typically, parameters are used as part of the query conditions (search criteria) so that only records satisfying that parameter will be retrieved to become part of the report.

How do we insert a parameter?

  1. From the Edit Toolbar click on the help60.gif (935 bytes) icon or from the main window, click on Insert/DB Fields... and select the Parameter tab.
  2. The following window will appear (Edit Toolbar, but the same window format in Insert/DB Fields...)

    l2f12.gif (6522 bytes)

    Click on the New button for a new parameter.
  3. The next window should appear after clicking on the new button.  The example parameter we created below allows the last person who edited the report to place his name on it. 

    l2f13.gif (4023 bytes)

    In the Parameter Name, type in a name for your parameter.  We chose Editor.  In the Prompting Text area, please enter a message that will appear.  Our message was, "Please type in the name of the last person who edited."  Note, you can only create a one line statement.   
  4. The Value Type should be left as String.  This allows the parameter to remain same as text.  There are also other Value Types.   Please refer to the parameter help file for more information.   

    Lastly, place an example in the Default Prompt Value so that you have a format to follow.  We chose John Smith since our parameter dealt with name.
  5. Click on the Check button to make sure all syntax is correct.   Click on OK to finish.
  6. Once you have clicked OK, select the new parameter and click on the Insert button.  Place this new field into your report.
  7. After you placed the parameter field into the report, click on the View tab to view your report.
  8. The following window will appear when you view the report.

    l2f14.gif (3713 bytes)

    You can type in any text field in the area.  The default button will change the value back to its original value.  In our case, that was John Smith.
  9. This was the final outcome of our report.

    Design:

    l2f15.gif (12472 bytes)

    View:

    l2f16.gif (10399 bytes)