23
EclipseCon 2006 Copyright © 2004 Business Objects. All rights reserved. Page 1 Crystal Reports for Eclipse – Report Design Contents SETTING THE ENVIRONMENT ........................................................................ 3 Starting the Derby Server ............................................................................ 3 ACTIVITY 1 CREATING A NEW CRYSTAL REPORTS FILE............................... 3 CONNECTING TO THE DATA SOURCE ............................................................ 5 Data Source overview .................................................................................. 5 ACTIVITY 2 CONNECTING TO A DATA SOURCE ........................................... 5 ACTIVITY 3 BUILDING THE SALESHISTORYBYCUSTOMERREPORT.RPT........ 7 Part I: Adding a data source ....................................................................... 7 Part II: Inserting a Group............................................................................ 7 Part III: Inserting the Detail Fields ............................................................. 8 Part IV: Adding/Modifying the Field Headers............................................. 9 Part V: Inserting Summaries and Totals.................................................... 10 Part VI: Inserting Report Title and Special Fields .................................... 11 ACTIVITY 4 BUILDING THE DYNAMICINVENTORYLEVELREPORT.RPT .......... 13 Tables Required: ........................................................................................ 13 Part I: Adding a data source ..................................................................... 13 Part II: Inserting a Cross-Tab ................................................................... 13 Part III: Modifying the Cross-tab fields..................................................... 14 Part IV: Adding Parameters to the Report ................................................ 15 Part V: Record Selection Formulas and Conditional Formulas ................ 16 Part VI: Suppressing Sections ................................................................... 17 Part VII: Insert the Title ............................................................................ 18 ACTIVITY 5 BUILDING THE SALESBYREGIONREPORT.RPT ........................ 20 Tables Required: ........................................................................................ 20 Part I: Adding a data source ..................................................................... 20 Part II: Inserting a Chart ........................................................................... 20 Part III: Inserting a Subreport ................................................................... 21

Crystal Reports for Eclipse – Report Design

  • Upload
    others

  • View
    4

  • Download
    0

Embed Size (px)

Citation preview

Page 1: Crystal Reports for Eclipse – Report Design

EclipseCon 2006

Copyright © 2004 Business Objects. All rights reserved. Page 1

Crystal Reports for Eclipse – Report Design

Contents SETTING THE ENVIRONMENT........................................................................3

Starting the Derby Server ............................................................................3 ACTIVITY 1 – CREATING A NEW CRYSTAL REPORTS FILE...............................3 CONNECTING TO THE DATA SOURCE............................................................5

Data Source overview..................................................................................5 ACTIVITY 2 – CONNECTING TO A DATA SOURCE ...........................................5 ACTIVITY 3 – BUILDING THE SALESHISTORYBYCUSTOMERREPORT.RPT........7

Part I: Adding a data source .......................................................................7 Part II: Inserting a Group............................................................................7 Part III: Inserting the Detail Fields .............................................................8 Part IV: Adding/Modifying the Field Headers.............................................9 Part V: Inserting Summaries and Totals....................................................10 Part VI: Inserting Report Title and Special Fields ....................................11

ACTIVITY 4 – BUILDING THE DYNAMICINVENTORYLEVELREPORT.RPT..........13 Tables Required:........................................................................................13 Part I: Adding a data source .....................................................................13 Part II: Inserting a Cross-Tab ...................................................................13 Part III: Modifying the Cross-tab fields.....................................................14 Part IV: Adding Parameters to the Report ................................................15 Part V: Record Selection Formulas and Conditional Formulas................16 Part VI: Suppressing Sections ...................................................................17 Part VII: Insert the Title ............................................................................18

ACTIVITY 5 – BUILDING THE SALESBYREGIONREPORT.RPT ........................20 Tables Required:........................................................................................20 Part I: Adding a data source .....................................................................20 Part II: Inserting a Chart...........................................................................20 Part III: Inserting a Subreport...................................................................21

Page 2: Crystal Reports for Eclipse – Report Design

Sponsored Tutorial EclipseCon 2006

Copyright © 2004 Business Objects. All rights reserved. Page 2

Overview: This module will take you through the Crystal Reports for Eclipse report design experience. It will introduce the users to new and existing functionality found within the Eclipse-based designer

Learning Objectives: Upon completion of this module users will be able to:

• Create a new Crystal Report

• Use Parameters to filter data

• Insert a Cross-Tab object

• Use the Crystal Formula language to customize look and feel of reports

• Know when and how to include a subreport in the report

Introduction This module is designed to introduce the user to Crystal Reports and specifically the Crystal Reports for Eclipse report design experience. The user will create 3 reports which will be used later in the Development tutorial.

Page 3: Crystal Reports for Eclipse – Report Design

Sponsored Tutorial EclipseCon 2006

Copyright © 2004 Business Objects. All rights reserved. Page 3

Setting the Environment

Starting the Derby Server This tutorial will build reports designed against a Derby database. In order to successfully connect to the database server for design purposes we will need to start the server.

1. In the CR4E Tutorial folder, find the following folder:

Supplemental\Derby

2. Locate the startServer.bat file and double click it. This should result in a Command Prompt dialog box opening up with the message “Server is ready to accept connections on port 1527”. Similar to the following:

Activity 1 – Creating a new Crystal Reports file 1. Under File->New select Project…

2. Expand the Simple folder and select the “Project” option. This action will create the bare minimum project to contain the new reports we will be creating

Page 4: Crystal Reports for Eclipse – Report Design

Sponsored Tutorial EclipseCon 2006

Copyright © 2004 Business Objects. All rights reserved. Page 4

3. Click Next

4. Enter the Name of the Project – “Crystal Reports Demo”

5. Click Finish

6. You should now see a new Project in the Navigator view, right-click on the Project and select New -> Other

7. From this dialog expand the Crystal Reports folder and select the Blank Report option

Page 5: Crystal Reports for Eclipse – Report Design

Sponsored Tutorial EclipseCon 2006

Copyright © 2004 Business Objects. All rights reserved. Page 5

8. Call the report SalesHistoryByCustomerReport.rpt and click Finish

9. This action will launch the Crystal Reports Perspective

Connecting to the Data Source

Data Source overview Crystal Reports for Eclipse makes use of existing built-in Data Source tools within the Eclipse IDE. In this current version we only support JDBC connections created via the Database Explorer view which is included within the Web Tools Platform (WTP) project. When the product is made generally available we will also support database connections made via the Database Explorer shipped with the Data Tools Project, as well as POJO (Plain Old Java Objects) and Custom SQL query statement support

Activity 2 – Connecting to a Data Source The Crystal Reports perspective includes a view to enable users to easily create a connection to their chosen data source. The view required to do this is the Database Explorer view

Page 6: Crystal Reports for Eclipse – Report Design

Sponsored Tutorial EclipseCon 2006

Copyright © 2004 Business Objects. All rights reserved. Page 6

1. In the Database Explorer view right-click on the Connections folder and select the option “New Connection”. This will launch the dialog to customize the data source connection properties

2. Unfortunately the Derby Server does not have a pre-defined configuration option. Therefore we must choose Other and input the following properties:

Database: Underground

JDBC Driver Class: org.apache.derby.jdbc.ClientDriver

Class location: derbyclient.jar (Browse to Derby\lib)

Connection URL: jdbc:derby://localhost:1527/Underground;create=true

3. Use the following credentials and then click the Test Connection button to ensure that everything is working as expected:

User ID: bobj

Password: bobj

Page 7: Crystal Reports for Eclipse – Report Design

Sponsored Tutorial EclipseCon 2006

Copyright © 2004 Business Objects. All rights reserved. Page 7

4. Users can opt to click Finish at this point, or click Next to provide them with the ability to Filter the tables being displayed. If you choose to filter the tables, be sure to enable the BOBJ table

5. Upon completing the wizard successfully users should be able to expand the newly created Underground connection in the Database Explorer view. This view will show all of the tables and will be the main source for adding the required tables to the report.

Activity 3 – Building the SalesHistoryByCustomerReport.rpt This report is a pretty simple report that will introduce users to the report design experience within Eclipse. It will be built off of a single View from the database and will list the Sales History grouped by Customer Name

Part I: Adding a data source 1. Open the report titled “SalesHistoryByCustomerReport.rpt” created in Activity 1

2. Expand the Underground connection in the Database Explorer view. Drill down to the BOBJ schema and expand the Views folder

3. Drag and drop VW_SALES_HISTORY to report. This should result in the table being added to the report

4. Switch to the Layout pane

5. In the Field Explorer, expand the VW_SALES_HISTORY table to see the available

fields

6. Save the Report – it is good practice to save the report after any modification

Part II: Inserting a Group 7. Right-click on the field CUSTOMER_NAME and select the option “Group on

Field”

Page 8: Crystal Reports for Eclipse – Report Design

Sponsored Tutorial EclipseCon 2006

Copyright © 2004 Business Objects. All rights reserved. Page 8

8. Using either the toolbar or the Properties View change the properties of the GroupName field to the following:

a. Font: Arial b. Font Size: 11 c. Width: 2.125 d. Height: 0.155

9. Save the Report

Part III: Inserting the Detail Fields 10. Select Section A of the Body in the Outline View. Change the following property:

a. Height: 0.156 in

11. Insert the following fields to the Body section of the report. This can be achieved by either dragging and dropping the fields from the Field Explorer or right-clicking on the Field and selecting the “Insert” option:

a. SALES_DATE b. PRODUCT_NAME c. QUANTITY d. SALES_PRICE e. TOTAL_SALE

12. Make the following modifications to the report fields using the Properties View:

a. SALES_DATE i. Font: Arial

ii. Size: 10 iii. Height: 0.146 iv. Left: 1.875 v. Width: 1.083

vi. Horizontal Alignment: Centered b. PRODUCT_NAME

i. Font: Arial ii. Size: 10

iii. Height: 0.146 iv. Left: 3.219 v. Width: 1.479

vi. Horizontal Alignment: Centered c. QUANTITY

i. Font: Arial ii. Size: 10

iii. Height: 0.146 iv. Left: 4.917 v. Width: 0.541

vi. Horizontal Alignment: Default d. SALES_PRICE

i. Font: Arial ii. Size: 10

iii. Height: 0.146 iv. Left: 6.022 v. Width: 0.728

vi. Horizontal Alignment: Default vii. Use System Default: False

viii. Currency Symbol Format: Floating e. TOTAL_SALE

Page 9: Crystal Reports for Eclipse – Report Design

Sponsored Tutorial EclipseCon 2006

Copyright © 2004 Business Objects. All rights reserved. Page 9

i. Font: Arial ii. Size: 10

iii. Height: 0.146 iv. Left: 7.083 v. Width: 0.676

vi. Horizontal Alignment: Default vii. Use System Default: False

viii. Currency Symbol Format: Floating

13. Save the Report

Part IV: Adding/Modifying the Field Headers When the fields were added to the Body section Field Headers were automatically inserted. In this step we will remove these Field Headers and add our own custom headers

14. Delete all of the Field Headers from the Page Header section.

15. Add the following Text Objects to the Group Header section. This can be achieved by dragging the Text icon from the palette and releasing it in the Group Header section:

*Note: You can use the Format Painter to easily format objects with the same settings a. SALES DATE

i. RGB: 60,120,0 ii. Font: Arial

iii. Size: 11 iv. Height: 0.146 v. Left: 1.875

vi. Top: 0.417 vii. Width: 1.094

viii. Horizontal Alignment: Centered b. PRODUCT NAME

i. RGB: 60,120,0 ii. Font: Arial

iii. Size: 11 iv. Height: 0.146 v. Left: 3.219

vi. Top: 0.417 vii. Width: 1.49

viii. Horizontal Alignment: Centered c. QUANTITY

i. RGB: 60,120,0 ii. Font: Arial

iii. Size: 11 iv. Height: 0.146 v. Left: 4.833

vi. Top: 0.417 vii. Width: 0.833

viii. Horizontal Alignment: Centered d. SALES PRICE

i. RGB: 60,120,0 ii. Font: Arial

iii. Size: 11 iv. Height: 0.146 v. Left: 5.802

vi. Top: 0.417 vii. Width: 1.073

viii. Horizontal Alignment: Right

Page 10: Crystal Reports for Eclipse – Report Design

Sponsored Tutorial EclipseCon 2006

Copyright © 2004 Business Objects. All rights reserved. Page 10

e. TOTAL SALE i. RGB: 60,120,0

ii. Font: Arial iii. Size: 11 iv. Height: 0.146 v. Left: 6.917

vi. Top: 0.417 vii. Width: 0.979

viii. Horizontal Alignment: Right

16. Save the Report

Part V: Inserting Summaries and Totals Summaries are a useful mechanism to provide an easy way to analyze the data. We are going to add 2 summaries at the Group level and 2 summaries at the Report level.

17. Right-click on the VW_SALES_HISTORY.QUANTITY field in the Body section

and select the option to “Summarize”.

18. This action should insert a new field in the Group Footer 1 Area. Drag this new field to the Report Footer Area.

19. Repeat Step #15 to insert a new Summary field. Now you should have a summary field in both the Group Footer 1 Area and the Report Footer Area.

20. Repeat Steps 15-17 for the field VW_SALES_HISTORY.TOTAL_SALE

21. Make the following modifications to the new Summary Fields:

Group Footer 1 a. Sum({VW_SALES_HISTORY.QUANTITY},{VW_SALES_HISTORY.CU

STOMER_NAME}) i. Bottom Line Style: Single

ii. RGB: 60,120,0 iii. Font: Arial iv. Size: 11 v. Height: 0.185

vi. Left: 5.083 vii. Top: 0.167

viii. Width: 0.608 ix. Horizontal Alignment: Centered x. Use System Default: False

xi. Decimals: 0 b. Sum({VW_SALES_HISTORY.TOTAL_SALE},{VW_SALES_HISTORY.

CUSTOMER_NAME}) i. Bottom Line Style: Single

ii. RGB: 60,120,0 iii. Font: Arial iv. Size: 11 v. Height: 0.185

vi. Left: 7.083 vii. Top: 0.167

viii. Width: 0.681 ix. Horizontal Alignment: Right x. Use System Default: False

xi. Currency Symbol Format: Floating

Report Footer c. Sum({VW_SALES_HISTORY.QUANTITY})

Page 11: Crystal Reports for Eclipse – Report Design

Sponsored Tutorial EclipseCon 2006

Copyright © 2004 Business Objects. All rights reserved. Page 11

i. Bottom Line Style: Double ii. Top Line Style: Single

iii. RGB: 60,120,0 iv. Font: Arial v. Size: 11

vi. Height: 0.227 vii. Left: 5.083

viii. Top: 0.153 ix. Width: 0.728 x. Horizontal Alignment: Centered

xi. Use System Default: False xii. Decimals: 0

d. Sum({VW_SALES_HISTORY.TOTAL_SALE})

i. Bottom Line Style: Double ii. Top Line Style: Single

iii. RGB: 60,120,0 iv. Font: Arial v. Size: 11

vi. Height: 0.227 vii. Left: 7.083

viii. Top: 0.153 ix. Width: 0.681 x. Horizontal Alignment: Right

xi. Use System Default: False xii. Currency Symbol Format: Floating

22. Save the Report

Part VI: Inserting Report Title and Special Fields Now that we have most of the report content all that is left is to clean it up a little. We will now add some special fields to the report, as well as a report title. The special fields are useful for adding commonly used report fields (e.g. Page Number, Print Date, etc.)

23. First we will add a Report Title. To do this add a Text object from the palette to the

Report Header area. The text object will contain the following text “Sales History By Customer”. Once the Text object has been added make the following changes to it:

i. Font: Arial ii. Size: 16

iii. Height: 0.25 iv. Left: 3.78 v. Top: 0.083

vi. Width: 3.417 vii. Horizontal Alignment: Left

24. After the title has been added we can now add a special field. To do this expand the

Special Fields icon in the palette. Scroll down until you see the “Page Number” field. Drag this field on to the Page Footer area. Make the following modifications to the Page Number field:

i. Font: Arial ii. Size: 10

iii. Height: 0.155 iv. Left: 7.213 v. Top: 0.31

Page 12: Crystal Reports for Eclipse – Report Design

Sponsored Tutorial EclipseCon 2006

Copyright © 2004 Business Objects. All rights reserved. Page 12

vi. Width: 0.66 25. Save the Report

Design Time

Page 13: Crystal Reports for Eclipse – Report Design

Sponsored Tutorial EclipseCon 2006

Copyright © 2004 Business Objects. All rights reserved. Page 13

Activity 4 – Building the DynamicInventoryLevelReport.rpt

Tables Required: CR_PRODUCT CR_PRODUCT_SUB_CATEGORY CR_WAREHOUSE CR_WAREHOUSE_PRODUCT

Part I: Adding a data source Create a new report titled “DynamicInventoryLevelReport.rpt”

Drag and drop the 4 tables onto the report. This should result in the tables being added to the report and the focus switching to the Data pane.

Create the following links (this can be achieved by dragging the field from 1 table onto the linking field of another table):

a. CR_PRODUCT.PRODUCT_SUB_CATEGORY_ID = CR_PRODUCT_SUB_CATEGORY.PRODUCT_SUB_CATEGORY_ID

b. CR_PRODUCT.PRODUCT_ID = CR_WAREHOUSE_PRODUCT.PRODUCT_ID

c. CR_WAREHOUSE_PRODUCT.WAREHOUSE_ID = CR_WAREHOUSE.WAREHOUSE_ID

Switch to the Layout pane

Save the Report

Part II: Inserting a Cross-Tab Cross-Tab reports are useful for easily creating tabular reports with breakdowns of totals. In this example we will demonstrate how to easily identify the current inventory level of a product category in any given warehouse.

Drag the “Cross-Tab” icon from the palette on to the Report Footer area. This will

result in a 1x1 crosstab being added to the report.

Drag the CR_PRODUCT_SUB_CATEGORY.PRODUCT_SUB_CATEGORY_NAME field to just above the Total field of the Row (as indicated by the highlighted square in the picture below)

Next drag the CR_PRODUCT.PRODUCT _NAME field just to the right of the PRODUCT_SUB_CATEGORY_NAME field (as indicated by the highlighted square in the picture below)

Page 14: Crystal Reports for Eclipse – Report Design

Sponsored Tutorial EclipseCon 2006

Copyright © 2004 Business Objects. All rights reserved. Page 14

Finally, drag and drop the CR_WAREHOUSE_PRODUCT.QUANTITY_ON_HAND field beneath the Total column (as indicated by the highlighted square in the picture below)

The user should see the following if all has steps have been followed correctly thus far

Part III: Modifying the Cross-tab fields Now that we have the appropriate field selection in the cross-tab we will want to

modify the properties to get the look and feel just right. Using the Outline View make the following changes to the following components of the Cross-Tab

a. Row1: PRODUCT_SUB_CATEGORY_NAME i. GroupLabel

1. Font Color: RGB{0,128,0} 2. Font Name: Arial 3. Font Size: 10 4. Font Style: Bold 5. Height: 0.447 6. Width:1.008

ii. Sub-Total: Total 1. Font Color: RGB{0,128,0} 2. Font Name: Arial 3. Font Size: 10 4. Font Style: Regular 5. Height: 0.154 6. Width:1.95

b. Row2: PRODUCT_NAME i. GroupLabel

1. Font Color: RGB{0,128,0} 2. Font Name: Arial 3. Font Size: 10 4. Font Style: Regular 5. Height: 0.153 6. Width:1.95

c. Total Row i. GrandTotalRow

1. Font Color: RGB{0,128,0} 2. Font Name: Arial 3. Font Size: 10 4. Font Style: Bold 5. Height: 0.155 6. Width:3.097

d. Total Column i. GrandTotalColumn

Page 15: Crystal Reports for Eclipse – Report Design

Sponsored Tutorial EclipseCon 2006

Copyright © 2004 Business Objects. All rights reserved. Page 15

1. Font Color: RGB{0,128,0} 2. Font Name: Arial 3. Font Size: 10 4. Font Style: Regular 5. Height: 0.155 6. Width:1.361

e. QUANTITY_ON_HAND (Summaries) i. PRODUCT_SUB_CATEGORY_NAME

1. Font Name: Arial 2. Font Size: 10 3. Height: 0.154 4. Width:1.361 5. Use System Default: False 6. Decimals: 0

ii. PRODUCT _NAME 1. Font Name: Arial 2. Font Size: 10 3. Height: 0.153 4. Width:1.361 5. Use System Default: False 6. Decimals: 0

iii. Total Row by Total Column 1. Bottom Line Style: Double 2. Font Color: RGB{0,128,0} 3. Font Name: Arial 4. Font Size: 10 5. Font Style: Bold 6. Height: 0.197 7. Width:1.361 8. Use System Default: False 9. Decimals: 0

Save the Report

At this point your report should look similar to the image below:

Part IV: Adding Parameters to the Report Parameters are a useful tool to customize the report to suit the end-users requirements. By using parameters a developer can create a single report which can serve up many users in a customized fashion. We will add 3 parameters to this report and use them to customize the output.

In the Field Explorer view right-click on the Parameters heading and choose

“New”. This will add a new parameter item underneath this heading.

Using the Properties view change the following properties of the new Parameter:

a. Name: Highlighting b. Prompt Text: Please enter a value c. Type: Number d. List of Values: 200

Repeat step 13 and make the following changes to the new parameter:

Page 16: Crystal Reports for Eclipse – Report Design

Sponsored Tutorial EclipseCon 2006

Copyright © 2004 Business Objects. All rights reserved. Page 16

a. Name: Product Line b. Prompt Text: Please enter product line c. Type: String d. List of Values: Ballpoint Pens

Complete Step 13 one more time to add the 3rd parameter. Make the following changes to the parameter:

a. Name: Warehouse b. Prompt Text: Please enter warehouse c. Type: String d. List of Values: Central Warehouse

Once this step is complete save the report. Your list of parameters should now look like the following:

Part V: Record Selection Formulas and Conditional Formulas Formulas allow for the developer to integrate their own logic into the report. Two specific types of formulas take the complexity out of some common report requirements that may be difficult to implement with custom logic. The Record Selection Formula enables the developer to modify the SQL query based on the outcome of the formula, whereas a conditional formula will impose a condition on the report or field based on the outcome of the formula. Both of these formula types will be used in this report

To add a Record Selection Formula users can do 1 of 2 things. First they can

manually enter the formula on the Formulas pane under the “Record Filter” formula or they can use the Record Filter wizard to assist in creating the formula. We will manually enter the formula in this scenario.

Switch focus to the Formulas pane.

Enter the following formula under the Record Filter formula:

{CR_PRODUCT_SUB_CATEGORY.PRODUCT_SUB_CATEGORY_NAME} ={?Product Line} and {CR_WAREHOUSE.WAREHOUSE_NAME} = {?Warehouse}

Next we will create a conditional formula to highlight the inventory amounts that are less than the number entered for the Highlighting parameter. To do this access the Outline view and highlight the PRODUCT_NAME by Total Column object in the Report Footer. It will be found under the Summaries section as in the picture below:

Page 17: Crystal Reports for Eclipse – Report Design

Sponsored Tutorial EclipseCon 2006

Copyright © 2004 Business Objects. All rights reserved. Page 17

Right-click on this object and select “New Condition Formula”. From the resulting wizard, select the Font Color option from the list

This will create a new formula in the Formulas pane of the report editor displaying a list of commented out Color constants. Insert the following formula in this section:

if CurrentFieldValue <= {?Highlighting} then crRed else Color(60, 120, 0)

Save the Report

Part VI: Suppressing Sections By default, when a report is created it has 5 separate report areas. In many cases not all of the Report Areas are required. When this is the case, it is necessary to suppress or delete unwanted sections to get the desired report layout. In today’s tutorial we will be suppressing all of the sections except for the Report Header and the Report Footer.

Suppressing sections is very easy. The easiest method is to select the Areas/Sections

that you would like to suppress in the Outline View and the changing the value of the Suppress property in the Properties View.

Using the CTRL key to enable multiple selections, highlight the Page Header, Body and Page Footer areas in the Outline View

Page 18: Crystal Reports for Eclipse – Report Design

Sponsored Tutorial EclipseCon 2006

Copyright © 2004 Business Objects. All rights reserved. Page 18

Switch to the Properties View and change the Suppress property to a value of True.

The selected areas should now have stripes sloping through the section, indicating that it has been suppressed

Save the Report

Part VII: Insert the Title As with the previous report we will want to insert a title into the report.

Drag a Text object from the Palette onto the Page Header. Enter the following text

into the object:

Warehouse Inventory Level Report By Product Line (in Units)

Make the following modifications to the new Text object:

a. Font Color: RGB{60,120,0} b. Font Name: Arial c. Font Size: 12 d. Font Style: Bold e. Height: 0.74 f. Left: 0.083 g. Top: 0.083 h. Width:7.833 i. Horizontal Alignment: Centered

Save the Report

The end result should be similar to the following:

Page 19: Crystal Reports for Eclipse – Report Design

Sponsored Tutorial EclipseCon 2006

Copyright © 2004 Business Objects. All rights reserved. Page 19

Page 20: Crystal Reports for Eclipse – Report Design

Sponsored Tutorial EclipseCon 2006

Copyright © 2004 Business Objects. All rights reserved. Page 20

Activity 5 – Building the SalesByRegionReport.rpt

Tables Required: Main Report CR_ORDER CR_PRODUCT_ORDER CR_REGION Subreport CR_EMPLOYEE CR_ORDER CR_PRODUCT_ORDER

Part I: Adding a data source 1. Create a new report titled “SalesByRegionReport.rpt”

Drag and drop the 3 tables for the Main Report onto the report. This should result in the tables being added to the report and the focus switching to the Data pane.

Create the following links (this can be achieved by dragging the field from 1 table onto the linking field of another table):

a. CR_REGION.REGION_ID = CR_ORDER.REGION_ID b. CR_ORDER.ORDER_ID = CR_PRODUCT_ORDER.ORDER_ID

Switch to the Layout pane

Save the Report

Part II: Inserting a Chart Charts are a useful tool to visualize the dataset. In this example we will be inserting 2 charts to allow the end-user to easily visualize which regions and sales personnel are performing the best.

Before we add the chart, we will create a Formula for us to summarize. Right-click

on the Formulas menu in the Field Explorer view and create a New formula.

Rename the formula to Sales in the Properties view and enter the following text in the Formulas pane:

{CR_PRODUCT_ORDER.QUANTITY} * {CR_PRODUCT_ORDER.SALES_PRICE}

Drag a Chart icon from the palette onto the Report Header. By default the initial

chart type will be a Bar chart. We will make the following modifications to the chart:

a. Chart Type: Pie b. Subtype: Pie c. Group Title Text: Region Name d. Title Text: Sales By Region e. Height: 4.844 f. Width: 8.135

Once the chart has been configured drag the Sales formula from the Field Explorer view and drop it into the Data Fields box

Next drag the REGION_NAME field from the CR_REGION table and drop it on the Series box

Page 21: Crystal Reports for Eclipse – Report Design

Sponsored Tutorial EclipseCon 2006

Copyright © 2004 Business Objects. All rights reserved. Page 21

Save the report

Part III: Inserting a Subreport A subreport allows the report designer to include data from a separate dataset into the same report. In some cases these datasets may be linked by a common variable, and in some cases there is no relationship at all…as in this case.

Before we add the subreport we want to add another section to the Report Header

area. This will allow the data in the first section to grow as much as necessary without overlapping the following sections. To do this drag the Section icon from the palette and drop it in the Report Header area. This action will insert a line cutting the section in half. Ideally, the chart created above should be on the top half of the area

On the lower half, drag a Subreport icon from the palette and drop it in the new section

Modify the Subreport object with the following properties:

a. Height: 0.292 b. Left: 0 c. Top: 0.104 d. Width: 8.135 e. Subreport Name: Sales By Employee

Right-click on the newly created Subreport and choose the option to “Switch to

Subreport”. This action will bring the subreport to the forefront of the designer. Now we can add the tables that we want to report off of. In this case we want to add the following tables: CR_EMPLOYEE, CR_ORDER, CR_PRODUCT_ORDER

Once the tables have been added create the following links:

a. CR_EMPLOYEE.EMPLOYEE_ID = CR_ORDER.EMPLOYEE_ID b. CR_ORDER.ORDER_ID = CR_PRODUCT_ORDER.ORDER_ID

Page 22: Crystal Reports for Eclipse – Report Design

Sponsored Tutorial EclipseCon 2006

Copyright © 2004 Business Objects. All rights reserved. Page 22

Next we will do a little cleanup on the subreport. Suppress every section except for the topmost Report Header area. This should result in only 1 section left for us to work in

Now, we will create 2 formulas:

a. Formula #1: i. Formula Name: Sales

ii. Formula Text: {CR_PRODUCT_ORDER.QUANTITY} * {CR_PRODUCT_ORDER.SALES_PRICE}

a. Formula #2:

i. Formula Name: Name ii. Formula Text: {CR_EMPLOYEE.LAST_NAME} & ", " &

{CR_EMPLOYEE.FIRST_NAME}

Finally, we will create a new chart in the subreport. As with the main report, drag a Chart icon from the palette and drop it on the Report Header. Make the following modifications to the Chart’s properties:

a. Chart Type: Pie b. Subtype: Pie c. Group Title Text: Region Name d. Title Text: Sales By Employee e. Height: 5.292 f. Width: 8.104

Once the chart has been configured drag the Sales formula from the Field Explorer view and drop it into the Data Fields box

Next drag the Name formula from the Field Explorer view and drop it on the Series box

Save the report

Page 23: Crystal Reports for Eclipse – Report Design

Sponsored Tutorial EclipseCon 2006

Copyright © 2004 Business Objects. All rights reserved. Page 23