Oracle Bi Publisher Data Template Example
Create Report BI Publisher Using Data Template. RTF Report Templates – Using the Design Helper Plug-in – Creating Data Definition for the.
Introduction
The BI Publisher data engine enables you to rapidly generate any kind of XML data structure against any database in a scalable, efficient manner. The data template is the method by which you communicate your request for data to the data engine. It is an XML document whose elements collectively define how the data engine will process the template to generate the XML.
The data engine supports the following functionality:
Single and multiple data queries
Query links
Parameters
Aggregate functions (SUM, AVG, MIN, MAX, COUNT)
Event triggers
Multiple data groups
The XML output generated by the data engine supports the following:
Unicode for XML Output
Unicode is a global character set that allows multilingual text to be displayed in a single application. This enables you to develop a single multilingual application and deploy it worldwide.
Canonical format
The data engine generates date elements using the canonical ISO date format: YYYY-MM-DDTHH24:MI:SS.FF3TZH:TZM for a mapped date element, and ######.## for number elements in the data template XML output.
The Data Template Definition
The data template is an XML document that consists of four basic sections: define parameters, define triggers, define data query, define data structure. This structure is shown in the following graphic:
As shown in the sample figure, the data template consists of a <parameters> section in which parameters are declared in child <parameter> elements; a <dataQuery> section in which the SQL queries are defined in child <sqlStatement> elements; and a <dataStructure> section in which the output XML structure is defined.
The table below lists the elements that make up the XML data template. Each element is described in detail in the following sections. Required elements are noted.
Element | Attributes/Description |
---|---|
dataTemplate (Required) | Attributes:
|
properties | Consists of one or more <property> elements to support the XML output and Data Engine specific properties. |
property | Attributes:
|
parameters | Consists of one or more <parameter> elements. |
parameter | Attributes:
|
lexicals | (Supported for queries against the Oracle E-Business Suite only). Consists of one or more lexical elements to support flexfields. |
lexical | There are four types of key flexfield-related lexicals as follows:
|
dataQuery (Required) | Consists of one or more <sqlstatement> or <xml> elements. |
sqlstatement (Required) | Attributes:
|
xml | Attributes:
|
url | Attributes:
|
link | Attributes:
|
dataTrigger | Attributes:
|
dataStructure | (Required for multiple queries) Defines the structure of the output XML. Consists of <group> and <element> elements to specify the structure. This section is optional for single queries; if not specified, the data engine will generate flat XML. |
group | Consists of one or more <element> elements and sub <group> elements. Attributes:
|
element (Required) | Attributes:
|
Constructing the Data Template
You can use any text or XML editor to write a data template.
Data Template Declaration
The <dataTemplate> element is the root element. It has a set of related attributes expressed within the <dataTemplate> tag.
Attribute Name | Description |
---|---|
name | (Required) Enter the data template name. |
description | (Optional) Enter a description of this data template. |
version | (Required) Enter a version number for this data template. |
defaultPackage | This attribute is required if your data template contains lexical references or any other calls to PL/SQL. |
dataSourceRef | (Required) The default data source reference for the entire data template. |
Properties Section
Use the <properties> section to set properties to affect the XML output and data engine execution.
Example:
The following table shows the supported properties:
Property Name | Description |
---|---|
include_parameters | Indicates whether to include parameters in the output. Valid values are:
|
include_null_Element | Indicates whether to remove or keep the null elements in the output. Valid values are:
|
xml_tag_case | Allows you to set the case for the output XML element names. Valid values are:
|
db_fetch_size | Sets the number of rows fetched at a time through the jdbc connection. The default value is 500. |
scalable_mode | Sets the data engine to execute in scalable mode. This is required when processing a large volume of data. Valid values:
|
include_rowsettag | Allows you to include or exclude the Rowset Tag from the output. Valid values:
|
debug_mode | Turns debug mode on or off. Valid values:
|
Parameters Section
A parameter is a variable whose value can be set at runtime. Parameters are especially useful for modifying SELECT statements and setting PL/SQL variables at runtime. The Parameters section of the data template is optional.
How to Define Parameters
The <parameter> element is placed between the open and close <parameters> tags. The <parameter> element has a set of related attributes. These are expressed within the <parameter> tag. For example, the name, dataType, and defaultValue attributes are expressed as follows:
Attribute Name | Description |
---|---|
name | Required. A keyword, unique within a given Data Template, that identifies the parameter. |
dataType | Optional. Specify the parameter data type as 'character', 'date', or 'number'. Default value is 'character'. For the 'date' dataType, the following three formats (based on the canonical ISO date format) are supported:
|
defaultValue | Optional. This value will be used for the parameter if no other value is supplied from the data at runtime. |
include_in_output | Optional. Whether this parameter should appear in XML output or not. The valid values are “true” and “false”. |
How to Pass Parameters
To pass parameters, (for example, to restrict the query), use bind variables in your query. For example:
Query:
At runtime, the value of department is passed to the query:
Data Query Section
The <dataQuery> section of the data template is required.
Supported Column Types
The following column types are selectable:
VARCHAR2, CHAR
NUMBER
DATE, TIMESTAMP
BLOB/BFILE (conditionally supported)
BLOB image retrieval is supported in the following two cases:
Using the SetSQL API (see SQL to XML Processor)
In the data template when no Structure section is defined. The returned data must be flat XML.
The BLOB/BFILE must be an image. Images are retrieved into your results XML as base64 encoding. You can retrieve any image type that is supported in the RTF template (jpg, gif, or png). You must use specific syntax to render the retrieved image in your template. See Rendering an Image Retrieved from BLOB Data.
CLOB (conditionally supported)
The CLOB must contain text or XML. Data cannot be escaped inside the CLOB column.
XMLType (conditionally supported)
XMLType can be supported if it is converted to a CLOB using the getClobVal() method.
REF CURSOR (conditionally supported)
A REF CURSOR is supported inside the SQL statement when only one results set is returned.
How to Define SQL Queries
The <sqlStatement> element is placed between the open and close dataQuery tags. The <sqlStatement> element has a related attribute, name. It is expressed within the <sqlStatment> tag. The query is entered in the CDATA section. For example:
Attribute Name | Description |
---|---|
name | A unique identifying name for the query. Note that this name will be referred to throughout the data template. |
If your column names are not unique, you must use aliases in your SELECT statements to ensure the uniqueness of your column names. If you do not use an alias, then the default column name is used. This becomes important when you specify the XML output in the dataStructure section. To specify an output XML element from your query you declare a value attribute for the element tag that corresponds to the source column.
Tip: Performing operations in SQL is faster than performing them in the data template or PL/SQL. It is recommended that you use SQL for the following operations:
Use a WHERE clause instead of a group filter to exclude records.
Perform calculations directly in your query rather than in the template.
Lexical References
You can use lexical references to replace the clauses appearing after SELECT, FROM, WHERE, GROUP BY, ORDER BY, or HAVING. Use a lexical reference when you want the parameter to replace multiple values at runtime.
Create a lexical reference using the following syntax:
Define the lexical parameters as follows:
Before creating your query, define a parameter in the PL/SQL default package for each lexical reference in the query. The data engine uses these values to replace the lexical parameters.
Create your query containing lexical references.
For example:
Data template definition:
How to Define a Data Link Between Queries
If you have multiple queries, you must link them to create the appropriate data output. In the data template, there are two methods for linking queries: using bind variables or using the <link> element to define the link between queries.
Tip: To maximize performance when building data queries in the data template:
BI Publisher tests have shown that using bind variables is more efficient than using the link tag.
The following example shows a query link using a bind variable:
The <link> element has a set of attributes. Use these attributes to specify the required link information. You can specify any number of links. For example:
Attribute Name | Description |
---|---|
name | Required. Enter a unique name for the link. |
parentQuery | Specify the parent query name. This must be the name that you assigned to the corresponding <sqlstatement> element. See How to Define Queries. |
parentColumn | Specify the parent column name. |
childQuery | Specify the child query name. This must be the name that you assigned to the corresponding <sqlstatement> element. See How to Define Queries. |
childColumn | Specify the child column name. |
Using Data Triggers
Data triggers execute PL/SQL functions at specific times during the execution and generation of XML output. Using the conditional processing capabilities of PL/SQL for these triggers, you can do things such as perform initialization tasks and access the database.
Data triggers are optional, and you can have as many <dataTrigger> elements as necessary.
The <dataTrigger> element has a set of related attributes. These are expressed within the <dataTrigger> tag. For example, the name and source attributes are expressed as follows:
Attribute Name | Description |
---|---|
name | The event name to fire this trigger. |
source | The PL/SQL <package name>.<function name> where the executable code resides. |
The location of the trigger indicate at what point the trigger fires:
Place a beforeReport trigger anywhere in your data template before the <dataStructure> section. A beforeRepot trigger fires before the dataQuery is executed.
Place an afterReport trigger after the <dataStructure> section. An afterReport trigger fires after you exit and after XML output has been generated.
Data Structure Section
In the data structure section you define what the XML output will be and how it will be structured. The complete group hierarchy is available for output. You can specify all the columns within each group and break the order of those columns; you can use summaries, and placeholders to further customize within the groups. The dataStructure section is required for multiple queries and optional for single queries. If omitted for a single query, the data engine will generate flat XML.
Defining a Group Hierarchy
In the data template, the <group> element is placed between open and close <dataStructure> tags. Each <group> has a set of related elements. You can define a group hierarchy and name the element tags for the XML output.
Creating Break Groups
Use a break group to produce subtotals or add placeholder columns. A break group suppresses duplicate values in sequential records. You should set an Order By clause in the SQL query to suppress duplicate values.
Assign a name to the group, and declare the source query, then specify the elements you want included in that group. When you specify the element, you assign it a name that will be used as the XML output tag name, and you declare the source column as the value. If you do not assign a name, the value (or source column name) will be used as the tag name.
For example:
The following table lists the attributes for the <group> element tag:
Attribute Name | Description |
---|---|
name | Specify any unique name for the group. This name will be used as the output XML tag name for the group. |
source | The name of the query that provides the source data for the group. The source must come from the name attribute of the <sqlStatement> element. |
The following table lists the attributes for the <element> element tag:
Attribute Name | Description |
---|---|
name | Specify any name for the element. This name will be used as the output XML tag name for the element. The name is optional. If you do not specify a name, the source column name will be used as the XML tag name. |
value | The name of the column that provides the source data for the element (from your query). |
Applying Group Filters
It is strongly recommended that you use a WHERE clause instead of a group filter to exclude records from your extract. Filters enable you to conditionally remove records selected by your queries, however, this approach impacts performance. Groups can have user-created filters, using PL/SQL.
The PL/SQL function must return a boolean value (TRUE or FALSE). Depending on whether the function returns TRUE or FALSE, the current record is included or excluded from the XML data output.
For example, a sample PL/SQL function might be:
An example of the group filter in your data template definition would be:
Creating a Summary Column
A summary column performs a computation on another column's data. Using the function attribute of the <element> tag, you can create the following summaries: sum, average, count, minimum, and maximum.
To create a summary column, you must define the following three attributes in the element tag:
Attribute | Description |
---|---|
name | The XML tag name to be used in the XML data output. |
source | The name of the column that contains the data on which the summary calculation is to be performed. The source column remains unchanged. |
function | The aggregation function to be performed. The type tells the XDO data engine how to compute the summary column values. Valid values are: SUM(), AVG(), COUNT(), MAX(), and MIN(). |
The break group determines when to reset the value of the summary column. For example:
Flexfield Support
Note: This section applies to data templates written to query the Oracle Applications database.
Flexfields are defined in the data template using lexical parameters.
How to define a flexfield
Define the SELECT statement to use for the report data.
Within the SELECT statement, define each flexfield as a lexical. Use the &LEXICAL_TAG to embed flexfield related lexicals into the SELECT statement.
Define the flexfield-related lexicals using XML tags in the data template.
Flexfield Lexicals
There are four types of KFF-related lexicals. These are:
oracle.apps.fnd.flex.kff.segments_metadata
oracle.apps.fnd.flex.select
oracle.apps.fnd.flex.kff.where
oracle.apps.fnd.flex.kff.order_by
Following are descriptions of each type of KFF lexical:
oracle.apps.fnd.flex.kff.segments_metadata
Use this type of lexical to retrieve flexfield-related metadata. Using this lexical, you are not required to write PL/SQL code to retrieve this metadata. Instead, define a dummy SELECT statement, then use this lexical to get the metadata.
The XML syntax for this lexical is as follows:
The following table lists the attributes for the segements_metadata lexical:
Attribute | Description |
---|---|
application_short_name | (Required) The application short name of the key flexfield. For example: SQLGL. |
id_flex_code | (Required) the internal code of the key flexfield. For example: GL# |
id_flex_num | (Required) Internal number of the key flexfield structure. For example: 101 |
segments | (Optional) Identifies for which segments this data is requested. Default value is 'ALL'. See the Oracle Applications Developer's Guide for syntax. |
show_parent_segments | (Optional) Valid values are 'Y' and 'N'. Default value is 'Y'. If a dependent segment is displayed, the parent segment is automatically displayed, even if it is not specified as displayed in the segments attribute. |
metadata_type | (Required) Identifies what type of metadata is requested. Valid values are: above_prompt - above prompt of segment(s). left_prompt - left prompt of segment(s) |
This example shows how to request the above_prompt of the GL Balancing Segment, and the left_prompt of the GL Account Segment.
oracle.apps.fnd.flex.kff.select
This type of lexical is used in the SELECT section of the statement. It is used to retrieve and process key flexfield (kff) code combination related data based on the lexical definition. Edition introduction sixth sociology quizlet.
The syntax is as follows:
The following table lists the attributes for this lexical:
Attribute | Description |
---|---|
application_short_name | (Required) The application short name of the key flexfield. For example: SQLGL. |
id_flex_code | (Required) the internal code of the key flexfield. For example: GL# |
id_flex_num | (Conditionally required) Internal number of the key flexfield structure. For example: 101. Required if MULTIPLE_ID_FLEX_NUM is 'N'. |
multiple_id_flex_num | (Optional) Indicates whether this lexical supports multiple structures or not. Valid values are 'Y' and 'N'. Default is 'N'. If set to 'Y', then flex will assume all structures are potentially used for data reporting and it will use <code_combination_table_alias>.<set_defining_column_name> to retrieve the structure number. |
code_combination_table_alias | (Optional) Segment column names will be prepended with this alias. |
segments | (Optional) Identifies for which segments this data is requested. Default value is 'ALL'. See the Oracle Applications Developer's Guide for syntax. |
show_parent_segments | (Optional) Valid values are 'Y' and 'N'. Default value is 'Y'. If a dependent segment is displayed, the parent segment is automatically displayed, even if it is not specified as displayed in the segments attribute. |
output_type | (Required) Indicates what kind of output should be used as the reported value. Valid values are: value - segment value as it is displayed to user. padded_value - padded segment value as it is displayed to user. Number type values are padded from the left. String type values are padded on the right. |
description | Segment value's description up to the description size defined in the segment definition. |
full_description | Segment value's description (full size). |
security | Returns Y if the current combination is secured against the current user, N otherwise. |
This example shows how to report concatenated values, concatenated descriptions, the value of the GL Balancing Segment, and the full description of the GL Balancing Segment for a single structure:
oracle.apps.fnd.flex.kff.where
This type of lexical is used in the WHERE section of the statement. It is used to modify the WHERE clause such that the SELECT statement can filter based on key flexfield segment data.
The syntax for this lexical is as follows:
The attributes for this lexical are listed in the following table:
Attribute | Description |
---|---|
application_short_name | (Required) The application short name of the key flexfield. For example: SQLGL. |
id_flex_code | (Required) the internal code of the key flexfield. For example: GL# |
id_flex_num | (Conditionally required) Internal number of the key flexfield structure. For example: 101. Required if MULTIPLE_ID_FLEX_NUM is 'N'. |
code_combination_table_alias | (Optional) Segment column names will be prepended with this alias. |
segments | (Optional) Identifies for which segments this data is requested. Default value is 'ALL'. See the Oracle Applications Developer's Guide for syntax. |
operator | (Required) Valid values are: =, <, >, <=, >=, !=, <>, , BETWEEN, LIKE |
operand1 | (Required) Values to be used on the right side of the conditional operator. |
operand2 | (Optional) High value for the BETWEEN operator. |
full_description | Segment value's description (full size). |
security | Returns Y if the current combination is secured against the current user, N otherwise. |
This example shows a filter based on the GL Account segment and the GL Balancing Segment:
oracle.apps.fnd.flex.kff.order_by
This type of lexical is used in the ORDER BY section of the statement. It returns a list of column expressions so that the resulting output can be sorted by the flex segment values.
The syntax for this lexical is as follows:
The attributes for this lexical are listed in the following table:
Attribute | Description |
---|---|
application_short_name | (Required) The application short name of the key flexfield. For example: SQLGL. |
id_flex_code | (Required) the internal code of the key flexfield. For example: GL# |
id_flex_num | (Conditionally required) Internal number of the key flexfield structure. For example: 101. Required if MULTIPLE_ID_FLEX_NUM is 'N'. |
multiple_id_flex_num | (Optional) Indicates whether this lexical supports multiple structures or not. Valid values are 'Y' and 'N'. Default is 'N'. If set to 'Y', then flex will assume all structures are potentially used for data reporting and it will use <code_combination_table_alias>.<set_defining_column_name> to retrieve the structure number. |
code_combination_table_alias | (Optional) Segment column names will be prepended with this alias. |
segments | (Optional) Identifies for which segments this data is requested. Default value is 'ALL'. See the Oracle Applications Developer's Guide for syntax. |
show_parent_segments | (Optional) Valid values are 'Y' and 'N'. Default value is 'Y'. If a dependent segment is displayed, the parent segment is automatically displayed, even if it is not specified as displayed in the segments attribute. |
The following example shows results sorted based on GL Account segment and GL Balancing segment for a single structure KFF.
Using the Data Engine Java API
This section describes how to utilize BI Publisher's data engine outside of the BI Publisher Enterprise user interface through the Java APIs. Use the descriptions in this section in conjunction with the Javadocs included with your installation files.
Calling a Data Template from the Java API
The following classes comprise the data engine utility Java API:
oracle.apps.xdo.oa.util.DataTemplate (OA wrapper API)
oracle.apps.xdo.dataengine.DataProcessor (Core wrapper API)
The DataProcessor class is the main class to use to execute a data template with the BI Publisher Data Engine. To use this API, you will need to instantiate this class and set parameter values for the data template, connection and output destination. Once the parameters are set, you can start processing by calling processData() method.
This example provides a sample data template file, then shows an annotated Java code sample of how to call it.
The sample data template is called EmpDataTemplate.xml and is stored as /home/EmpDataTemplate.xml:
The following code sample is an annotated snippet of the Java code used to process the data template by the data engine:
SQL to XML Processor
The data engine not only supports data generation from data templates, but it can also return data by simply passing it a SQL statement. This functionality is similar to the native database support for generating XML with the added advantage that you can retrieve huge amounts of data in a hierarchical format without sacrificing performance and memory consumption. You SQL statement can also contain parameters that can be given values prior to final processing.
The processor will generate XML in a ROWSET/ROW format. The tag names can be overridden using the setRowsetTag and setRowsTag methods.
The following annotated code sample shows how to use the setSQL method to pass a SQL statement to the data engine and set the element names for the generated data:
Other Useful Methods
The data engine has several very useful functions that can be used to generate objects or files that can be used with the other BI Publisher APIs:
writeDefaultLayout – once the DataTemplate has been instantiated you can call this method to generate a default RTF template that can be used with the RTFProcessor to create an XSL template to be used with the FOProcessor. Alternatively, the default RTF can be loaded into Microsoft Word for further formatting. This method can generate either a String or Stream output.
writeXMLSchema - once the DataTemplate has been instantiated you can call this method to generate an XML schema representation of your data template. This is very useful if you are working with PDF templates and need to create mapping from the PDF document to your XML data.
setScalableModeOn – if you know you are going to return a large dataset or have a long running query you can specify that the data engine enter scalable mode. This will cause it to use the disk rather than use memory to generate the output.
setMaxRows – this allows you to specify a fixed number of rows to be returned by the engine. This is especially useful when you want to generate some sample data to build a layout template against.
Sample Data Templates
This section contains two sample data templates:
Employee Listing
General Ledger Journals Listing
The sample files are annotated to provide a better description of the components of the data template. To see more data template samples, see the BI Publisher page on Oracle Technology Network (OTN). From here you can copy and paste the samples to get you started on your own data templates.
Employee Listing Data Template
This template extracts employee data and department details. It has a single parameter, Department Number, that has to be populated at runtime. The data is extracted using two joined queries that use the bind variable method to join the parent (Q1) query with the child (Q2) query. It also uses the event trigger functionality using a PL/SQL package 'employee' to set the where clause on the Q1 query and to provide a group filter on the G_DEPT group.
The sample data template will generate the following XML:
Following is the data template used to extract this data.
The PL/SQL Package:
General Ledger Journals Data Template Example
This data template extracts GL journals data from the E-Business Suite General Ledger schema. It is based on an existing Oracle Report that has been converted to a data template format. It follows the same format as the Employee data template but has some added functionality.
Employee XML Datasource Data Template
This data template combines data that exists in a table called 'dept' with data from an xml file called 'employee.xml'. It follows the same format as the Employee data template but the employee data comes from an xml file instead of from the emp table.
Copyright © 2003, 2008, Oracle and/or its affiliates. All rights reserved.