Based on Oracle Application Express (formerly called HTML DB) version 1.6
After completing this How To, you should be able to:
- Launch Oracle Reports paper reports from Oracle HTML DB
- Build interactive parameter screens for Oracle Reports using Oracle HTML DB
Introduction
Oracle Reports is a professional reporting tool capable of creating rich formatted output, ideal for paper-based layouts.
This document describes how to use HTML DB to create interactive web-based parameter entry screens that can be used to dynamically invoke Oracle Reports. This example will show how to create dynamic list of values, branching, validations, and more.
Software Requirements
- Oracle HTML DB 1.6
- Oracle Reports Services (available as a component of Oracle Application Server Enterprise Edition or Oracle Business Intelligence)
- Oracle Reports Developer (available as a component of Oracle Developer Suite)
Create and Deploy the Oracle Reports Report
You must first create a report using the Oracle Reports Developer tool and then deploy it to the Application Server Reports Services. Useful sources of information are the Getting Starting Guide and the
Publishing Reports manual.
For this example, we will use an example report from the Building Reports manual. The example well use is the Invoice Example, but you can work with any other report. This example report as supplied does not use any parameters. Well add 2 new parameters to this report in order to illustrate how to make parameter screens.
To create and deploy the Oracle Reports report:
- Download the invoice example .rdf from the samples .zip. The invoice example is located in the
invoice\invoice.rdf file.
- This report uses the
OE sample schema. This schema is locked by default. You may need to ask your DBA to unlock this schema and reset the password. You will also need to use Oracle HTML DB against the OE schema, so you might want to ask for those privileges as well.
- Open the
invoice.rdf report in Oracle Reports Developer, connect as OE, and test the paper design using the live previewer.
If you get an error about uncompiled code, you can compile the report by selecting
Compile >
All ... from the
Program menu. The report will look like this:
- Using the Object Navigator, open the
Property Inspector for the
Q_ORDER Query:
- Click on the
... button beside the SQL Query Statement to edit the SQL Statement, and add a new where clause referencing two new parameters to the query:
and c1.cust_address.state_province = :p_state
and (c1.customer_id = :p_customerid or :p_customerid is null)
The newly typed text is shown in lowercase letters:
- Click on OK - you should receive a prompt about how the report now has 2 bind variable parameters.
- Run the report in the paper design previewer again. This time you will be asked to enter a value for the
P_STATE parameter. Enter "
MI" without the quotes for Michigan, or "
IN" for Indiana. Leave the
P_CUSTOMERID field empty.
- Save the report as
invoice2.rdf.
- Deploy the report to the Oracle Application Server Reports Services. Your local administrators may have specific steps to deploying a report, but here are some steps that work with a default setup.
- Copy the
invoice2.rdf file to
$ORACLE_HOME/reports/samples/demo, where $ORACLE_HOME is the oracle home of Reports Services. If using FTP to copy, be sure to transfer the .rdf in binary mode.
- Test the report. Here is a sample URL to use in your web browser:
http://hostname:port/reports/rwservlet?module=invoice2.rdf&userid=oe/oe@tnsalias&destype=cache&desformat=pdf&p_state=IN
Where hostname, port are where Reports Services is running and tnsalias is the TNS alias of the database where the OE schema resides.
Note: that this example passes the userid parameter on the URL. One can take advantage of the Reports Services $ORACLE_HOME/reports/conf/cgicmd.dat file to hide sensitive parameters like userid. The Publishing Reports to the Web manual discusses this feature.
Create the Oracle HTML DB Application
We are now ready to create parameter entry screens in HTML DB. You must first create an HTML DB application that will own the parameter screens of our reporting system.
To create an Application:
- Login to HTML DB as a user who privileges to use the OE schema.
- Click on
Create Application.
- In the Create Application Wizard:
- For the
Creation Method, select
From Scratch and click
Next.
- Enter a
Name for your Application and click
Next.
- Make sure that the
Default Parsing Schema is set to
OE. If OE is not available in the drop-down list, ask your Oracle HTML DB Administrator to associate the OE schema with your Workspace.
- Select
2 for
Number of Pages, and click
Next.
- Select
One Level of Tabs and click
Next.
- For
Page Names, enter
Home and
Invoice and click
Next.
- For
Tab Names, simply click
Next.
- Select any
Theme and click
Next.
- Click
Create Application.
Create the Home Page
Now that you have created the application, you will create a home starter page for our reporting system.
To create a home page:
- Under
Pages, click on
Home.
- Click on the "
+" icon under
Regions.
- Select
HTML and click
Next.
- Select
HTML again and click
Next.
- For the
Title, enter
Welcome and click
Next.
- For the
HTML Text Region Source, enter "
Welcome to the Oracle HTML DB & Oracle Reports How-To" and click
Create Region.
Create the Utility Objects
Next, create some utility objects like static substitution strings and list of values.
- Click on the
Application Builder tab.
- Click on
Edit Attributes.
- Scroll down to the
Static Substitution Strings section and enter the following:
Substitution String: REPORTS_URL
Substitution Value: http://hostname:port/reports/rwservlet?userid=oe/oe@tnsalias&
Be sure to replace
hostname,
port, and
tnsalias to the same values which you used when testing the invoice2.rdf report against Reports Services when deploying. As discussed earlier, you can use the Oracle Reports cgicmd.dat file to avoid passing sensitive parameters like userid via a URL.
- Scroll to the top and click
Apply Changes.
- Click on
Shared Components.
- Click on
List of Values.
- Click on
Create.
- Select
From Scratch and click on
Next.
- Enter
DESFORMAT_LOV as the
Name, select
Static as the
Type, and click
Next.
- Enter the following data:
| Facet Name |
Display Value |
Return Value |
| 1 |
PDF |
PDF |
| 2 |
HTML |
HTMLCSS |
- Click
Create Static LOV.
Create the Parameter Entry Page
Next, we need to create a page to accept parameters for our Oracle Report.
To create a Parameter Page:
- Click on the
Application Builder tab.
- Click on the
Invoices page.
- Click on the "
+" icon under
Regions.
- Select
HTML and click
Next.
- Select
HTML again and click
Next.
- For the
Title, enter
Invoice Report and click
Next.
- Click
Create Region.
Create the Parameter Items
Now you will items to allow users to select parameters. You will create drop-down lists for the STATE and CUSTOMER parameters of the report.
- Click on the "
+" icon under
Items.
- Select
Select List and click
Next.
- Select
Select List with Submit and click
Next.
- Enter
P2_STATE as the
Name and click
Next.
- For
Display Null Option, select
Yes.
- Enter this SQL statement for the
List of Values Query and click
Next:
select distinct c.cust_address.state_province display1, c.cust_address.state_province return1
from customers c
where exists (select 'x' from orders o where o.customer_id = c.customer_id and sales_rep_id is not null)
order by 1
- Take the defaults for Item Attributes and click Next.
- Click on Create Item.
- Click on the "
+" icon under
Items.
- Select
Select List and click
Next.
- Select
Select List and click
Next.
- Enter
P2_CUSTOMER as the
Name and click
Next.
- For
Display Null Option, select
Yes.
- Enter this SQL statement for the
List of Values Query and click
Next:
select c.cust_last_name||','||c.cust_first_name display1, c.customer_id return1
from customers c
where exists (select 'x' from orders o where o.customer_id = c.customer_id and sales_rep_id is not null)
and c.cust_address.state_province = :p2_state
order by 1
- Under the Items region, click on
P2_CUSTOMER.
- Scroll down to
Conditional Display.
- For
Condition Type, select
Value of Item in Expression 1 is NOT NULL.
- For
Expression 1, enter
P2_STATE.
- Scroll to the top and click
Apply Changes.
- Click on the "
+" icon under
Items.
- Select
Select List and click
Next.
- Select
Select List and click
Next.
- Enter
P2_DESFORMAT as the
Name and click
Next.
- Select
DESFORMAT_LOV for the
Named LOV.
- For
Display Null Option, select
No and click
Next.
- For
Label, enter
Report Format and click
Next.
- Click
Create Item.
Create Validation and Branches
Now you will items to allow users to select parameters. You will create drop-down lists for the STATE and CUSTOMER parameters of the report.
- Click on the "
+" icon under
Branches.
- Take the defaults and click
Next.
- For
Page, enter
2 and click
Next.
- Click on
Create Branch.
- Click on the "
+" icon under
Validations.
- Select
Item Level Validation and click
Next.
- Select
P2_STATE and click
Next.
- Select Item Not Null and click Next.
- Take the defaults for Validation Attributes and click Next.
- Enter "Please select a State" and click Next.
- Click Create.
Create the Run Report Button
Next, create a button to run the report and a new branch to launch Orale Reports when the button is clicked.
- Click on the "
+" icon under
Buttons.
- Take the defaults and click
Next.
- Select
Invoice Report as the
Region and click
Next.
- Select
Create a button displayed among this regions items and click
Next.
- Enter
P2_GO as the
Button Name, and click
Create Button.
- Click on the "
+" icon under
Branches.
- Take the defaults and click
Next.
- Select
URL for
Target is a, and for the
URL Targer, enter:
&REPORTS_URL.&module=invoice2.rdf&destype=cache&desformat=&P2_DESFORMAT.&p_state=&P2_STATE.&p_customerid=&P2_CUSTOMER.
- Click
Next.
- For the
Sequence, enter
5.
- For
When Button Pressed, select
P2_GO and click
Create Branch.
Advanced Techniques
1) Creating Additional Parameter Pages for Additional Reports
A typical reporting system will have multiple reports. One approach would be to create each report's parameter page from scratch as described above. Another approach is to use HTML DB's ability to copy a page. This approach copies over the regions, items, branches, and validations intelligently.
2) Creating a Data Preview Reporting Region with Oracle HTML DB
HTML DB makes it very easy to add a live "preview" region to your parameter page. To do this, add a new region and select the Report (SQL Report) region type. In this region you can use SQL that gives the user a preview of the reports data. In many cases, this will be as easy as copying the SQL from the .rdf file using Oracle Reports Developer. Once pasted into HTML DB, you can refer to the HTML DB parameters by their HTML DB item names.
3) Passing Parameters via Tables
The example above passes parameters like P_STATE and P_CUSTOMERID to the report via a URL. In some scenarios, you might not want to pass parameters this way (for instance, you might be worried about mischievous users who try to edit the parameter values in the URL address field of their browser).
An alternative approach is to use a database table to store the report parameters and simply pass an identifier of the table row which holds the parameters to the report submission. Some of HTML DB's wizards can be helpful in this situation. Here's one approach:
- To build the parameter table for a report, use HTML DB's Data Workshop's ability to Import Spreadsheet Data. Use Excel and build a simple spreadsheet. Put the names of the report parameters in the first row as the column headings. Put some sample values in the second row. In the example below, I have added some additional tracking columns like REPORT_STATUS, REPORT_SUBMIT, etc. Other typical columns/parameters to consider would be ones like DESFORMAT, DESTYPE, and DESNAME.
You can let the HTML DB wizard create the primary key column (ID) and new sequence/trigger to maintain it.
- To have your parameter screen store the parameters in your new table, you will want to:
- Create a hidden item called P2_ID
- Create a Process (conditional on the Submit button) with the following PL/SQL:
insert into params_invoice (REPORT_STATUS,REPORT_SUBMIT,
P_STATE,P_CUSTOMERID) values
('NEW',sysdate,:p2_state,:p2_customer) returning id into :p2_id;
commit;
- Modify the Oracle Reports URL in the Branching item to pass the primary key of the row where the parameters are stored. For instance, it could look like:
&REPORTS_URL.&module=invoice2.rdf&destype=cache&desformat=&P2_DESFORMAT.&p_param_id=&P2_ID.
- Modify the Oracle Reports .rdf file by:
- Creating a P_PARAM_ID parameter.
- Adding an After Parameter Form Trigger:
- Adding a After Report Trigger (this trigger is not required, but as shown below is used to record when a report finishes in the parameter table):