Working with Datasets Activity

 

 

 

Step

Action

1. 

Activity End Result

In this activity, you define a query and create the report template, as displayed above. This template serves as the foundation for many of the activities that follow. Adding a query to a report allows you to register database fields and add data to the report.

 

Notes: 

- $F{ } represents database fields, which map to columns in a report.

- $P{ } represents parameters, used to constrain the query.

- $V{ } represents variables, which manage calculations at runtime.

2. 

Begin by clicking the File menu to create a new report.

3. 

Click the New menu item.

4. 

Note: The New file window appears. In this window, select the report template you want to use.

5. 

Click the Blank A4 object.

6. 

Click the Open this Template button.

7. 

Note: The New window appears. In this window, specify the name and save location of the report.

 

Best practice:  For optimal performance, save reports locally.

8. 

Enter "department_report" into the Report name field.

9. 

Click the Next button.

10. 

Click the Finish button to open the empty report template.

11. 

Note: iReport Designer opens the new report template.

12. 

Next, design the query that returns data from the database.

 

Click the Query button to open the Report query window.

13. 

Note: The Report query window appears. Enter queries manually in this window, or use the query design wizard.

14. 

Click the Query designer button to create a query on the department table.

15. 

Note: The Query designer wizard opens. Here you create queries using mouse, cursor, and keyboard.

16. 

Click the Schema drop-down to activate the menu.

17. 

Click the public list item.

18. 

Note: A list of all of the tables in the foodmart public schema appears.

19. 

Double-click the department list item to add that table to the query.

20. 

Note: The department table field names are displayed and automatically selected by default. The query is automatically built and displayed in the pane at the upper left.

21. 

Click the OK button to save the query and return to the Report query window.

22. 

Note: The wizard returns to the Report query window and

displays the completed query. The field name aliases (the names after the word AS in the SELECT statement) display below in the bottom pane.

23. 

Edit the query manually. 

 

Double-click to highlight the department_ text string in the query.

24. 

Press [Delete] to remove part of this field's alias name.

25. 

Note: The alias in both the query and the registered field pane below are updated.

26. 

Click the OK button to save the query and return to the iReport Designer window.

27. 

Note: You return to the iReport Designer window.

28. 

Expand the Fields tree item.

29. 

Note: The query's two field alias names appear in the Fields hierarchy.

30. 

Next, create a new parameter.

 

Right-click the Parameters tree item.

31. 

Click the Add Parameter menu item.

32. 

Note: The new parameter appears at the bottom of the parameters list.

33. 

Next, configure the new parameter in the Properties panel as follows:

 

- Name: title

- Parameter Class: java.lang.String

- Use as a prompt: Check this box

- Default Value Expression: “Default Title” (notice the double quotation marks)

 

Enter "title" into the Name field.

34. 

Enter ""Default Title""into the Default Value Expression field.

35. 

Next, create and configure a variable to count the number of departments in the foodmart sample data.

 

Right-click the Variables tree item.

36. 

Click the Add Variable menu item.

37. 

Note: The new variable appears at the bottom of the variables list.

38. 

Configure the variable as follows:

 

- Name: department_count

- Variable Class: java.lang.Integer

- Calculation: Distinct Count

- Reset type: Report

- Variable Expression: $F{department_department_description}

 

Enter "department_count" into the Name field.

39. 

Click the Variable Class drop-down button to activate the menu.

40. 

Click the java.lang.Integer list item.

41. 

Click the Calculation drop-down button to activate the menu.

42. 

Click the Distinct Count list item.

43. 

Click the Variable Expression edit button.

44. 

Note: The expression editor appears. The expression editor helps you create expressions for variables, fields, parameters, and other configurable items.

45. 

All the registered field names appear in the center pane.

 

Double-click the department_department_description list item to add it to the expression.

46. 

Note: The field name appears in the expression editor window.

47. 

Click the OK button to save the expression and close the editor.

48. 

Note: The Variable Expression property displays the name of the department_description field. The variable is now configured to count the number of departments in the foodmart sample data.

49. 

Next, save your work and move report elements into the report.

 

Click the Save button.

50. 

From the Report Inspector, click and drag the title parameter into the top center of the Title band.

51. 

Note: The title parameter text field appears in the Title band.

52. 

Now, from the Report Inspector, click and drag the department_department_description field into the upper-left corner of the Detail band.

53. 

Note: The department_department_description text field appears in the report, and iReport automatically adds a column header label to the Column Header band above.

54. 

Double-click the Column Header field to edit the text.

55. 

Enter "Dept Name" into the Column Header field.

56. 

Press [Enter] to commit your change.

57. 

Now, from the Report Inspector, click and drag the department_count variable into the Summary band.

58. 

Note: The variable's text field appears in the Summary band.

59. 

Preview the report to see how it looks.

 

Click the Preview button.

60. 

Note: Because you configured a parameter, a Parameter prompt window appears. Enter any title and click OK, or click the Use default button to specify the default title you configured earlier.

61. 

Click the Use default button.

62. 

Note: The report appears in the Preview window. The title displays the text you entered for the parameter's default value, the Dept Name column header appears, and each department name displays because the Details band expands vertically to make room for all records returned by the query.

63. 

Click the Next Page button to see Page 2 of the report.

64. 

Note: Page two appears, displaying more department names.

65. 

Click the Next Page button to see Page 3 of the report.

66. 

Note: The Summary band's contents display at the bottom of the last page, and the department_count variable indicates that there are 12 departments in this report.

67. 

In order to re-use this report template in future activities, remove all items from the report.

 

Click the Designer button to return to Design View.

68. 

In the parameters list, right-click the title tree item.

69. 

Click the Delete menu item.

70. 

Click the Yes button to confirm.

71. 

Note: The title parameter is deleted from the Report Inspector parameter list.

72. 

Compile a report to check that the report template is well formed and contains no errors.

 

Click the Compile Report button.

73. 

Note: Deleting an item that is referenced in the report (in this case a parameter referenced in the Title band) prevents the report from compiling or running. A warning message in the Report Problems Window near the bottom of iReport indicates that the title parameter is not found. This problem is resolved in the next step.

74. 

Next, delete the title field.

 

Click to select the title text field.

75. 

Press [Delete].

76. 

Note: The title text field is deleted from the report.

77. 

Next, delete the variable.

 

Right-click the department_count tree item.

78. 

Click the Delete menu item.

79. 

Click the Yes button to confirm.

80. 

Click the Compile Report button to see if the report compiles properly.

81. 

Note: The report does not compile because the deleted variable is still referenced by the variable text field in the Summary band.

82. 

Click anywhere in the Summary Variable text field to select it.

83. 

Press [Delete].

84. 

Likewise, remove all remaining elements from the report.

 

Click in the Description field.

85. 

Press [Delete].

86. 

Click in the Dept Name field.

87. 

Press [Delete].

88. 

Note: All elements are now removed from the report.

89. 

Best Practice: Save reports frequently.

 

Click the Save button.

90. 

Congratulations!

 

In this activity you opened a new report template, created a query, defined a parameter and variable, added and removed report elements, and previewed the report.

 

View the Online Learning Portal here (http://www.jaspersoft.com/online-learning-portal).

End of Procedure.