Showing posts with label Eclipse. Show all posts
Showing posts with label Eclipse. Show all posts

Thursday, July 21, 2011

Crystal Reports for Eclipse: How to set the Record Sorting at runtime?

A. Introduction

In this article, I would like to explain how to sort the data in a report based on the value of a parameter.
The example used in this article is based on a simple database table containing three columns, namely Product ID, Product Name and Product Description. A Command Table representing the data of this DB table will be added to a new report. And finally, it is required to define a parameter for choosing the sorting column at runtime.

If you are new to Crystal Reports for Eclipse, I recommend that you watch the following QuickStart demos:
Crystal Reports for Eclipse 2.0 - Command Table Part 1: Adding SQL to a Report
http://www.sdn.sap.com/irj/scn/elearn?rid=/library/uuid/00b07182-3ed3-2b10-6695-fb255b4eae01

Crystal Reports for Eclipse 2.0 - Command Table Part 2: Updating Command Table SQL
http://www.sdn.sap.com/irj/scn/elearn?rid=/library/uuid/d027948f-3fd3-2b10-e582-f19c3946490f

Crystal Reports for Eclipse 2.0 - Designing a Report
http://www.sdn.sap.com/irj/scn/elearn?rid=/library/uuid/d0ee1df6-41d3-2b10-de8d-a4fdc5077c68


B. Database preparations

Create the example database table and fill it with data using the following script:

CREATE TABLE REPORT_PARAM_FOR_SORTING(
Product_ID varchar(6) not null,
Product_Name varchar(20) not null,
Product_Description varchar(100) not null,
constraint pk_report primary key (Product_ID)
);

insert into REPORT_PARAM_FOR_SORTING values
('F50Z13', 'Optical mouse', 'This is an optical mouse.'),
('A04K02', 'Keyboard', 'This is a wireless keyboard.'),
('A00B18', 'Speakers', 'Perfect speakers.');



C. Report Creation
  1. Open Eclipse.
  2. Browse your Crystal Reports project.
  3. Create a new SQL file called "sqlReportParamForSorting".
  4. Open the SQL file and write the following SELECT query:
    select Product_ID, Product_Name, Product_Description
    from REPORT_PARAM_FOR_SORTING
  5. Right-click inside the SQL file and click Crystal Reports > Add to a New Report.
  6. Set the location and name for the new report and click OK.
  7. Open the newly created report.
  8. In the Crystal Reports perspective, open the Field Explorer view.
  9. Expand the command table, in order to see the selected DB fields.
  10. While the Layout page is open, drag and drop the three fields in the Body section of the report.
  11. Switch to the Preview page and check that you can see all three rows from the example DB table properly.


D. Sorting based on a parameter
  1. In the Field Explorer view, add a new parameter called "param_SortingColumn".
  2. In the Properties view for the new parameter, set the List of Values as shown in the following figure:


  3. In the Field Explorer view, add a new formula called "sort_Column".
  4. On the Formula page, write the following formula for "sort_Column":
    if ({?param_SortingColumn} = 'Name') then
    {sqlReportParamForSorting.PRODUCT_NAME}
    else
    {sqlReportParamForSorting.PRODUCT_ID}
  5. From the Crystal Reports menu, click Record Sorting.


  6. Select the formula "sort_Column" and click OK.


  7. Save the report.


E. Testing
  1. Switch to the Preview page.
  2. You would be prompted to select a sorting column.
  3. Select "Product Name" and the result should be as shown in the following figure:


  4. Refresh the report and select "Prompt for parameters before refresh".
  5. Select "Product ID" and the result should be as shown in the following figure:


Tuesday, June 28, 2011

Crystal Reports for Eclipse: Where to start?

What is Crystal Reports for Eclipse?

Crystal Reports for Eclipse is an Eclipse plug-in that integrates Crystal reports into Eclipse IDE. It makes it easy to develop and access Crystal Reports in your Eclipse projects.

According to the Crystal Reports for Eclipse Developer Guide, the plugin adds the following features to Eclipse:

  • An embedded report designer for creating Crystal reports.
  • Crystal reports viewers for viewing reports in Java applications and over the web.
  • SDKs to programmatically modify reports.
  • Java runtime libraries that implement reporting functionality.
  • Eclipse integration features, including project wizards, views, and perspectives for reporting.
  • A set of sample reports, sample database connections, and helper code.



Know How material

This section acts as an indexer for referencing pages which describe how to install and work with "Crystal Reports for Eclipse". It also contains links to very good demos, webinars and articles that can be of great help for beginners to find their first steps while using this tool.

SAP Crystal Reports, version for Eclipse
This is the official Home Page for "Crystal Reports for Eclipse" on the SAP Community Network.
http://www.sdn.sap.com/irj/sdn/crystalreports-java

Crystal Reports for Eclipse e-Book
The Crystal Reports for Eclipse e-Book contains articles, videos, and information on how to create reports and embed them in custom java applications.
http://wiki.sdn.sap.com/wiki/display/BOBJ/Crystal+Reports+for+Eclipse

Crystal Reports for Eclipse 2.0 demos
This page contains QuickStart demos that cover the topics of creating Crystal Reports projects, designing reports and adding them to the projects, configuring different types of datasources inside the reports, and finally viewing the report inside a sample Java application or a sample JSP page hosted in a web application.
http://www.sdn.sap.com/irj/sdn/crystalreports-java?rid=/webcontent/uuid/30e3a9b4-a7d3-2b10-678a-9ed48f648365

Crystal Reports Java SDK Samples
This page contains a set of code samples that cover a variety of topics, e.g. General, Viewing, Database, Exporting/Printing, Parameters and Report Modification
https://wiki.sdn.sap.com/wiki/display/BOBJ/Crystal+Reports+Java++SDK+Samples

Crystal Reports for Eclipse 2.0 - Sample Codes Package
This page contains a bundle of 12 sample codes for Crystal Reports for Eclipse 2.0. The package covers the topics "Web Application Viewing and Exporting", "Report Creation/Modification" and "Designer Extension Points".
http://www.sdn.sap.com/irj/scn/weblogs?blog=/pub/wlg/13120

Crystal Reports for Java/Eclipse Articles
This page contains some good articles about Crystal Reports for Eclipse.
http://www.sdn.sap.com/irj/boc/index?rid=/webcontent/uuid/e038f87e-f576-2b10-1e92-baf4baf5f6f5