You are on page 1of 3

Advance BI Publisher Concepts - Sorting in RTF Template

by AshishRaj on Wed May 18, 2011 5:59 pm

The objective of this post is to explain the “sorting” capabilities available in the RTF.
Many might already be aware of the standard BI Publisher syntax for sorting in the RTF
template:

<?sort:VENDOR_NAME?>

The above construct sorts the data by the VENDOR_NAME in ascending order – an
alphabetic sort is performed. However, what if the requirement was to sort on a number
field. For example, if you want to sort by the VENDOR_NUMBER, then the above will
produce incorrect results as an aphabetic sort would be applied to a numeric field. The
following BIP construct can be used to specifc the order and the sort type:

<?sort:VENDOR_NUMBER;'ascending';data-type='number'?>

The above BIP construct performs a numeric sort on the vendor_number. That's rather
simple to do. Let's say we would like to sort on a field but the field name is not known at
design time. The field name exists in the xml data. Let's say the element P_SORT_BY
specifies the field on which sorting must be done. So, if the value of P_SORT_BY is
VENDOR_NAME, sorting must be performed on the field VENDOR_NAME. This can
be acheived by using the following XSL:

<xsl:sort select=".//node()[local-name()=P_SORT_BY]" order="ascending" data-


type="number"/>

Debug XML Publisher report:

We can also check the OPP log file for debug logging.

• Login the application with System Administration Responsibility


• Navigate to Concurrent Manager: Administrator
• Select the Output Posy Processors and click on View Details.
• Click on View Processes
• Click the current process, which is active at the time request submitted. Check the other process, if you are not sure and search
for Request ID.
• Click the Outpost process log file.
PL/SQL logic should be implemented as single PL/SQL Package with following
conditions.

1. All the parameters define in Parameter section of Data Template should be define
as parameters in plsql package.
2. PL/SQL logic should be implemented as function and must return a Boolean
value.
3. The package should be define as defaultPackage attribute in Data Template
Header.

In the above example, we see following three instance of PL/SQL call. Two dataTriggers
and one Group Filter

-<dataTrigger name="afterReport"
source="emp_test1.AfterReportTrigger(:ORG_TOTAL_SALARY)" />
-<dataTrigger name="beforeReport" source="emp_test1.BeforeReportTrigger" />

1) Before Report Trigger

The position of first dataTrigger is before the dataStructure section in Data Template. It
gets fire before the very first SQL query executes. In this example, PL/SQL function
BeforeReportTrigger drive the DYNAMIC_WHERE_CLAUSE variable based on
P_DEPTNO value. P_DEPTNO value will be available within plsql package as the
process set the value from data template parameters to pl/sql parameters. That is the
reason; we need to define the same set of parameters in PL/SQL as defined in data
template. BeforeReportTrigger function set the DYNAMIC_WHERE_CLAUSE
parameter calue as “D.DEPTNO =10”. Before executing the SQL query Q1, process
replace the substitute variable DYNAMIC_WHERE_CLAUSE with the actual values
and following query get fired.

SELECT d.DEPTNO,d.DNAME,d.LOC,
EMPNO,ENAME,JOB,MGR,HIREDATE,SAL,COMM from DEPT D, EMP E
where D.DEPTNO=E.DEPTNO
and D.DEPTNO =10

PL/SQL parameter/s can be reference as substitute variables within SQL query and this
feature allow us to design the dynamic SQL query based on the input parameters.

The before report triggers can be used to designing dynamic SQL queries or filter
conditions using substitute variables,populating the temporary or global temporary tables
for Oracle apps for complex data extraction process and then write the SQL query against
these temp tables.

2) After Report Trigger


The position of “afterReport” data trigger is after the dataStructure section and termed as
after Report Trigger. These triggers get fire after the XML generation complete. In our
example function “AfterReportTrigger” accept the ORG_TOTAL_SALARY as input
parameter and insert a record to ORG_SAL table.

The purpose of after report triggers is to implement any post process logic as cleaning or
deleting the temp tables or records, auditing activities.

3) Group Filter

The use of Group filter is to filter out the groups from the XML ouput, if the specified
condition implemented in calling function does not match. If the PL/SQL function returns
the false, the particular instance of group will not be the part of XML output.

In the example, DeptGroupFilter accept the dept_number element value as input. If the
value is 30, it returns false and Group belongs to deptn0=30 will not be there in final xml.

I tried multiple before and aft er data triggers within the same data template and they
executed sequentially, So I think we can use multiple before and after dataTriggers. All
these three call are simple PL/SQL functions and designed for some specific operations
but there is no restrictions on nature of PL/SQL logic inside the function, just make sure
it return the appropriate Boolean value.

Please feel free to ask any question on this topic and I will be happy to help you out.

http://apps2fusion.com/at/ps/51-ps/260-integrating-xml-publisher-and-oa-
framework

You might also like