In a scripted data set in BIRT you don’t need to define parameters that are bound to report parameters. That is because you can refer to report parameters directly in the open or fetch script, like in this example of an open script:

cities = [];
if (params["pCOUNTRY"]=="France") {
   cities[0] = "Paris";
   cities[1] = "Marseille";
   cities[2] = "Lille";
} else if (params["pCOUNTRY"]=="USA") {
   cities[0] = "New York";
   cities[1] = "Chicago";
}

When you are dealing with a scripted data set that is bound to a nested table, and you need the parameter value to be a value from the outer table, you’ll need a different approach.

In that case, select the data set, choose Edit data set and add a parameter to the scripted data set.
ssspDsParam

Next, bind a value from the outer table to the parameter. Select the inner table, go to the bindings tab and select the Data Set Parameter Binding button:
ssspDsParamBinding

And finally, write the open script like this:

cities = [];
if (inputParams["pCOUNTRY"]=="France") {
   cities[0] = "Paris";
   cities[1] = "Marseille";
   cities[2] = "Lille";
} else if (inputParams["pCOUNTRY"]=="USA") {
   cities[0] = "New York";
   cities[1] = "Chicago";
}

For some reason it took me some time to find out about the use of inputParams[“datasetParam”]. So I hope that if you are dealing with the same issue, this post has eased your search.

Just a couple of days after I posted my Columns to Rows in BIRT Data Set I ran into this birt-exchange forum post where Robilco provides a solution for the exact same problem. I like his approach and he was kind enough to let me write about it on this blog.

This approach has no need for computed columns and a joint data set, just a scripted data set and some more scripting.

Problem Description
The starting point is a .csv file with this content:
Department;Infrastructure;Training;Comms;Consumables
X;100;150;200;125
Y;150;200;150;175

The different types of budgets need to be in rows instead of in columns.

CSV data set
Like in my previous post, a data set is created for the purpose of the .csv file. But this time some scripting is added.

In the BeforeOpen method of the data set, two variables are initialized:

idx = 0;
budgetRecs = [];

In the onFetch method of the data set, an array is created with the budget data. The budget types are already separated in this step:

budgetRec = {department: row["Department"], budgetType: "Infrastructue", budget: row["Infrastructure"]};
budgetRecs[idx++] = budgetRec;
budgetRec = {department: row["Department"], budgetType: "Training", budget: row["Training"]};
budgetRecs[idx++] = budgetRec;
budgetRec = {department: row["Department"], budgetType: "Communications", budget: row["Comms"]};
budgetRecs[idx++] = budgetRec;
budgetRec = {department: row["Department"], budgetType: "Consumables", budget: row["Consumables"]};
budgetRecs[idx++] = budgetRec;

Scripted data set
The scripted data set won’t do anything else but fetching the data that is entered in the array in the onFetch method of the CSV data set.

The open method initalizes the array index:

idx = 0;

The fetch method (not the onFetch method!) reads the array and moves the data into the data set columns.

if (idx < budgetRecs.length) {
	row["Department"] = budgetRecs[idx].department;
	row["BudgetType"] = budgetRecs[idx].budgetType;
	row["Budget"] = budgetRecs[idx].budget;
	idx++;
	return true;
}else{
	return false;
}

Dummy grid
To make sure the CSV data set is executed, drag a grid element to the report layout and bind it to the CSV data set. As long as no report items are put in the grid, it will not be visible when the report is executed.
rtc2GridBinding

Results
To check if things work as expected, drag the scripted data set to the report layout and run the report. As you can see: every budget type is on a separate row:
rtc2Results

Many thanks to Robilco for providing the inspiration to this post!

This article describes a way to transform column data into row data with the help of a scripted data set, computed columns and a joint data set.

Most of the time I use SQL to perform the task of transforming columns to rows, but some time ago, when helping out someone on the birt-exchange forums, I needed to come up with a different approach. The poster got his data from a .csv file, so the use of SQL was no option. (See bottom of this post for a SQL based solution).

Problem Description
A pie chart needs to be created based on the data in a .csv file:
Department;Infrastructure;Training;Comms;Consumables
X;100;150;200;125
Y;150;200;150;175

The different types of budgets – Infrastructure, Training, Comms and Consumables – are all in separate columns and have to become the slices of the pie chart. If we take the csv based data set as it is, there is no unique column that can be selected as a values series field.

CSV Data Set
First of all: create a data source and data set on the .csv file. This is pretty straightforward.
Also, add a computed column that will always contain the value 1 and name it join_col. We will need this column when creating the Joint Data Set in one of the next steps.
rtcComputedCol

Scripted Data Set
Next, create a scripted data set that has two columns:

  • join_col
  • col_number

The join_col field will always contain the value 1 and will be used to join this data set to the .csv data set created in the previous step.
The col_number will add up for each row in this data set and the number of rows needs to correspond to the number of columns in the .csv that you want to transform to rows. In this case we need 4 rows as there are 4 types of budget in the .csv file.

To create a scripted data set take these steps:

  • create a new data source → make sure you choose Scripted Data Source and enter an appropriate name, e.g. dsScripted
  • create a new data set → Select dsScripted as the datasource and enter an appropriate name, e.g. dsScriptedData
  • add both join_col and col_number as Integer type columns
  • in the open script of the data set, add this code:
    joinCols = [];
    colNums = [];
    for (i=0;i<=4;i++) {
       joinCols[i] = 1;
       colNums[i] = i+1;
    }
    idx = 0;
    
  • in the fetch script of the data set, add this code:
    if (idx < numCols.length) {
    	row["join_col"] = joinCols[idx];
    	row["column_num"] = colNums[idx];
    	idx++;
    	return true;
    }else{
    	return false;
    }
    
  • If you now Edit the data set and select Preview Results, you should see this:
    rtcDsScriptedResults

Joint Data Set
In the joint data set, we will now join the csv data set and the scripted data set together based on the join_col field that exists in both data sets. Every row in the csv data set is joined to every row in the scripted data set. So for every department there will be 4 rows in this data set:
rtcJointDataset

Next step is to create two computed columns. One will hold the budget type and the other will hold the actual budget on each row. The first column, budgetType, has an expression like this:

switch(row["dsScriptedData::column_num"])
{
case 1:
  "Infrastructure";
  break;
case 2:
  "Training";
  break;
case 3:
   "Commissions";
   break;
case 4:
   "Consumables";
   break;
}

The second column, budget, has an expression like this:

switch(row["dsScriptedData::column_num"])
{
case 1:
  row["dsBudget::Infrastructure"];
  break;
case 2:
  row["dsBudget::Training"];
  break;
case 3:
   row["dsBudget::Comms"];
   break;
case 4:
   row["dsBudget::Consumables"];
   break;
}

This is what you should see when you Edit the data set, select Preview Results and scroll to the right:
rtcJointDatasetPreview

Result
With the joint data that we have created, it’s a piece of cake to create the pie chart. Put the budget column in the Series Definition, the budgetType column in the Category Definition and the dsBudget::Department column in the Optional Grouping:
rtcCreateChart

The result now looks like this:
rtcResult

*SQL Solution
If the data does not come from a csv file, but you are selecting it from a data base, you don’t have to worry about scripted data sets, computed columns and all the other fancy features I mentioned in above article. You can write a query like this and you are ready to move on:

SELECT Department,
       'Infrastructure' as budget_type
       Infrastructure_budget as budget
FROM   your_table
UNION  ALL
SELECT Department,
       'Training' as budget_type
       Training_budget as budget
FROM   your_table
UNION  ALL
SELECT Department,
       'Commissions' as budget_type
       Comms_budget as budget
FROM   your_table
UNION  ALL
SELECT Department,
       'Consumables' as budget_type
       Consumable_budget as budget
FROM   your_table

If you want to put a filter on the values series of a BIRT chart, you’ll need some kind of workaround. The values series can’t be used after selecting the filter button on the Select Data tab of the chart dialog. The easiest way to accomplish this, is to do add the grouping and aggregation in the query and then put a filter on the aggregated data column. However, if you want to use the ungrouped data in other parts of your report, you might prefer another workaround.

Let’s say you want to know from the classicmodels database the top 5 of employees that have taken the most orders.

The Data Set
This query selects the employee’s lastname and the ordernumbers of his customers:

select e.lastname,
       o.ordernumber
from   orders o,
       customers c,
       employees e
where  o.customernumber = c.customernumber
and    c.salesrepemployeenumber = e.employeenumber

The Report Table
As it is not possible to use a filter directly on the values series of the chart, we need to find some other item to put the filter on: a report table. The chart will be created in the header row of the table.

Take these steps to create a table:

  • drag a table element from the palette to the report, choose 1 row and 1 column and bind it to the data set you created
  • right-click on the table and select ‘Insert Group’ to add a group ‘grpEmployee’ to the dataset and choose lastname in the Group On field
  • select the table, go to the Binding tab and add an aggregation like this:
    aggbuilder
  • select the table, go to the Groups tab and Edit the group ‘grpEmployee’ to add a filter like this:
    editgroup
  • in the same edit group dialog, select Sorting and add a sort on row[“aggcount”] descending

The Chart
Now we are ready to create the chart:

  • drag a Chart item from the palette into the header row of the table
  • select the chart type you like (I chose the a simple Bar Chart)
  • move on to the Select Data tab, make sure the Select Data From Container checkbox is checked and then select row[“aggcount”] at the Value Series and row[“grpEmployee”] at the Category Series:
    chartdialog

The Result
To clean up things a bit, you can remove all the rows from the table, except for the header row and run the report. The result should look like this:results

Grouping within a BIRT data set
In the context of the Plug In 2 BIRT Contest for Autumn 2012, I created the Group Functions plugin. You can find the plugin, documentation and a sample report on birt-exchange Devshare. The group function aggregations in the plugin make it possible to generate the SUM, COUNT or ROWNUMBER by a group of data within a BIRT data set. With the right combination of these functions and the use of filters you can create many-to-many relations in a joint data set by first applying grouping in your data sets. You can read more on this in the pdf that you can download from the link mentioned earlier.

Screenshots
Here’s a screenshot of how a computed column is created with the GROUPSUM function:
grpfUse

And this is the result in the preview results area of the data set:
grpfResult

You can vote
The contest closed on november 30 and now registered birt-exchange users can vote for the plugin they like most on birt-exchange (the poll is in the sidebar on the right). So if you like this feature, give it a vote. Thanks!

Nowadays with Oracle Open World, twitter is buzzing with words like “Forms Modernization”, “Forms isn’t dead” and so on. In these tweets and posts people are encouraging Forms builders to modernize their Forms applications by introducing some features that enhance the looknfeel and usage of Forms. Another way of modernizing Forms, they say, is to migrate to the Oracle ADF framework, which is Oracle’s development framework flagship. If it were up to Oracle they would like to see all Forms applications migrated to ADF.

Luckily, there is another way, and a very smart one indeed! Why not migrate your Forms application to the industry-proven Eclipse RCP platform. As you may or may not know, with the Eclipse RCP framework it is possible to create full blown desktop applications. I know many Forms developers would welcome back the possibility of a client/server application, because, let’s face it, it’s much much faster than a web application (even with ajax).

To demonstrate the migration of Oracle Forms to Eclipse RCP, I have created a little demo. This demo follows a scenario that a company could follow if they decide to migrate Oracle Forms.

In the scenario, our company owns an Oracle Forms application to manage HR data. Lately, they have deployed an application to manage the company’s car fleet, which was built with Eclipse RCP. Of course, there must be some integration because our car fleet application needs data from the HR database. Instead of writing a bunch of routines to deal with the HR database and data, the company decided to simply embed the Oracle Forms HR application inside the car fleet application and to have them “talk” to each other. This way, our company is able to quickly and cheaply integrate both applications and to postpone the migration of the Oracle Forms HR application to the new platform or to gradually migrate piece by piece.

This is a followup on a comment I received on an earlier post about generating a chart in a grouping header: Generate a separate chart for each group value.

If you take a look at the screenshot of the resulting report in that post, you see that for the year 2005 there’s only a bar for the months that have records in the data set. The commenter asked for what needs to be done to show all months of the year, also the ones that don’t have data in the dataset.

In the chart edit screen, on the Format Chart tab, select the X-axis on the left side and uncheck the “Is Category Axis”:

Then click the Scale button and modify it like this:

This is what the report looks like now: