Time for action – creating our first Subreport

The steps for creating our first Subreport are as follows:

  1. We will create our first Subreport and place it in the Report Header section. Then we will edit the internally used Parameters and import the value of the field country_id. Finally, we will create a JDBC data set that will be filtered by the value imported from the main Report. We add a Sub-report object (Time for action – creating our first Subreport) to the Group Header section. We drag-and-drop it in the area that we have left empty.
  2. After doing this, PRD will ask us if we want the Subreport to be Banded or Inline. We should click on the Inline button. PRD will ask us about the data set to be used. We click on the option Cancel. We name our Subreport so it is easier for reference. We go to the Structure tab, choose the sub-report node, and configure the following:
    • Attributes.name = SubReportBarChartAs: This Subreport will display information related to the country that the final user chooses. We should make the Subreport receive the country that will be displayed in the main Report. To do so, we will use the Parameters for internal use between Reports and Subreports.
  3. Next, we go to the Data tab, select the Parameters node, right-click on it, and choose the option Edit Sub-report Parameters... as shown in the following screenshot:
    Time for action – creating our first Subreport

    We will see the following window:

    Time for action – creating our first Subreport
  4. To the left-hand side is where we configure the values that will be imported from the main Report, and to the right-hand side is where we configure the values that will be exported to the main Report.
  5. In this case, we configure a value to be imported. It is the country identification (country_id).
  6. In the table on the left-hand side (Import Parameter), we click on the Time for action – creating our first Subreport button to create a new row and then establish the following:
    • Outer Name = country_id. The field of the main Report from which the value should be obtained is placed here.
    • Inner Name = importCountryId. This will be the Subreport's internal use variable that will take on the value that is imported.
    Time for action – creating our first Subreport
  7. Now we create the data set for this Subreport. It will be a JDBC data set, and we will configure it as follows:
    • Connections = sakila db
    • Query Name = RatingAmount
    • Query =
        SELECT film.rating, SUM(payment.amount) sum_amount
        FROM payment
        INNER JOIN rental ON rental.rental_id=payment.rental_id
        INNER JOIN inventory ON inventory.inventory_id=rental.inventory_id
        INNER JOIN film ON film.film_id=inventory.film_id
        INNER JOIN customer ON customer.customer_id = rental.customer_id
        INNER JOIN address ON address.address_id = customer.address_id
        INNER JOIN city ON city.city_id = address.city_id
        WHERE city.country_id = ${importCountryId}
        GROUP BY film.rating

    We can see that the SQL query is filtered by the value of the variable we created earlier.

What just happened?

We added an inline Sub-report object to the Group Header section. We created an internally used Parameter called importCountryId that will take on the value of the country_id field in the main report. Then we created the Subreport's data set and configured it so the SQL query is filtered by importCountryId.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset