Showing posts with label XML. Show all posts
Showing posts with label XML. Show all posts

Sunday, 11 January 2015

Displaying subtotal and grand total based on the group column in BI Publisher Template

For Example

Display the sub total values based on Account code and show grand total end of the report.

The report has only one group (G_ACCT) and  group columns like 
     Account Code, Ro Number, ROLine# ,Ro Type, Ro Date, Supplier#, Supplier Name, 
     Supplier Site, W/H, Buyer, Items, Qty, Price, Trxn Amount


Show the subtotal and grand total amount for Trxn amount column based on account code combination.

Steps:
  • Divide the for –each loop with Account code column
  • Do the current group logic.
  • Display the sub total column before closing current group loop.
  • Display the grand total value at end of the report.

 Adding above steps logic in xml tags:

  1.      <?for-each-group:G_ACCT;./ACCOUNT_CODE?> (first F Xml tag)
  2.      <?for-each:current-group()?>(second F xml tag)
  3.       After displaying G_AMT Closing current-group for-each.
  4.       Displaying the  T_AMT (grand total amount)

Output:




Friday, 31 October 2014

Excel Template for BI Publisher Report

This blog explains the process and steps to develop BI data templates with excel.
 
Steps in Brief:
  1. Create xml data template.
  2. Create concurrent program with executable XDODTEXE.
  3. Create Data definition and load the data template.
  4. Obtain XML data from your data model.
  5. Design layout in excel by using XML data.
  6. Create the data template and load the designed excel template.
  7. Submit your concurrent program and check the excel output.
About Data Template
A data template is a simple xml file with a defined number of elements.  (Refer the below Image 0.1 for sample data template structure.)
A basic data template contains the data Template element where you define the name of your template and a description.
The next element set is the parameters section. In this section you define the names, data types and possible default values for parameters used in your query. You define these parameters later also in the concurrent program definition.
The data Query block contains the sql Statement block where you define the SQL query (in conjunction with any parameters). Optionally you are able to run some trigger at a stage of the data generation (quite handy sometimes :-)).
The data Structure block defines the output columns of the data. When defining the xml file always make sure you close every element block.
 
Data Template Structure
     Image 0.1
Once the data template is prepared save it with .xml format (ex:  BI_excel_demo2.xml).
Concurrent Program
Create the concurrent program with executable XDODTEXE.
What is XDODTEXE?
XDODTEXE is java concurrent program used as a BI Publisher Data template Executable.
The main purpose of this executable is to identify data template file (.xml) and execute the data template to generate the raw (output) xml data, which is later used by BI Publisher formatting engine to format as per the layout (RTF, PDF, etc).
 This executable will be used by all the BI Publisher reports (Concurrent Program) which are using Data Template to generate the xml data.
  
Data Definition
Data definition code should be same as your concurrent program short name. Load the data template xml file by clicking on the upload option next to the Data template.
 
About Excel Templates
An Excel template is a report layout designed in Microsoft Excel for formatting your enterprise reporting data in Excel spreadsheets. Excel templates provide a set of special features for mapping data to worksheets and for performing additional processing to control how the data is output to excel workbooks.
The BI Publisher Tab in Excel
Features of Excel Templates
With Excel templates you can:
  • Define the structure for the data in Excel output
  • Split hierarchical data across multiple sheets and dynamically name the sheets
  • Create sheets of data that have master-detail relationships
  • Use native XSL functions in the data to manipulate it prior to rendering
  • Use native Excel functionality
Steps to Develop Excel templates
  1.     Obtain sample XML data from your data model.
  2.     Open the BlankExcelTemplate.xls file and save as your template name.
  3.     Design the layout in Excel.
  4.     Assign the BI Publisher defined names.
  5.     Prepare the XDO_METADATA sheet.
  6.     Test the template using the desktop Excel Template Builder.
Creating the XDO_METADATA Sheet
Each Excel template requires a sheet within the template workbook called "XDO_METADATA". Use this sheet to identify your template to BI Publisher as an Excel template.
This sheet is also used to specify calculations and processing instructions to perform on fields or groups in the template. BI Publisher provides a set of functions to provide specific report features. Other formatting and calculations can be expressed in XSLT.
Create a new sheet in your Excel Workbook and name it "XDO_METADATA".
Create the header section by entering the following variable names in column A, one per row, starting with row 1:
  1. Version
  2. ARU-dbdrv
  3. Extractor Version
  4. Template Code
  5. Template Type
  6. Preprocess XSLT File
  7. Last Modified Date
  8. Last Modified By
  • Skip a row and enter "Data Constraints" in column A of row 10.
  • In the header region, for the variable "Template Type" enter the value: TYPE_EXCEL_TEMPLATE

Design the excel layout using xml generated tags. See below for example.

Data Template
Create the data template and load the excel layout.
 
Finally submit your concurrent program and you should able to see the excel output file as below.
 

Wednesday, 15 October 2014

Load XML data into Oracle table

Steps to Load XML File to Oracle Tables

Solution : Sample XML file has been used for illustration

Step 1 : Create a directory using the below command. The below directory will be created in /tmp folder. We need to mention the appropriate path as where the directory to be created.

     CREATE DIRECTORY  < DIRECTORY_NAME> AS '/tmp';

Step 2 : Create a table with XMLType as Datatype - This table will be used to store the XML Data from the directory created above.
       CREATE TABLE table_with_xml_column  (    file_id  NUMBER,   
       filename VARCHAR2(64),    xml_document XMLType  );

Step 3: Create another table to store the values of xml
      create table temp_xml(file_content XMLType)

Step 4:  Insert data to the XMLType table table_with_xml_column

        INSERT INTO  table_with_xml_column (xml_document)  VALUES
        (XMLType(bfilename('XMLDIR', 'mlc_gl_daily_rates.xml'),     
        nls_charset_id('AL32UTF8')));
        Note : XMLDIR is the directory we created.

Step 5 : The below Query will insert data to the Temporary table by reading the values  

       from TEMP_XML table.

set serveroutput on;
DECLARE
v_xml xmltype :=xmltype('<WebServiceResponse xmlns="http://ws.abc.com">
    <SubscriptionInfo xmlns="http://ws.oracle.com">
      <LicenseStatusCode>0</LicenseStatusCode>
      <LicenseStatus>123</LicenseStatus>
      <LicenseActionCode>1</LicenseActionCode>
      <LicenseAction>Decremented hit count</LicenseAction>
      <RemainingHits>5993</RemainingHits>
      <Amount>0</Amount>
    </SubscriptionInfo>
    <GetResponse xmlns="http://www.abc.com">
      <GetData>
        <ServiceStatus>
          <StatusNbr>212</StatusNbr>
          <StatusDescription>Employee information Found</StatusDescription>
        </ServiceStatus>
        <Result>
          <Empno>6263</Empno>
          <Ename>ABC</Ename>
          <Job>Manager</Job>
          <DOJ>10/10/2014 6:35:12 PM</DOJ>
        </Result>
      </GetData>
    </GetResponse>
  </WebServiceResponse>');
  v_result clob;
 v.Date               date;
CURSOR C1 IS
SELECT
  Q.LICENSESTATUSCODE   LICENSESTATUSCODE,
  Q.LICENSESTATUS       LICENSESTATUS,
  Q.LICENSEACTIONCODE   LICENSEACTIONCODE,
  Q.LICENSEACTION       LICENSEACTION,
  Q.REMAININGHITS       REMAININGHITS,
  Q.AMOUNT              AMOUNT,
  S.STATUSNBR           STATUSNBR,
  S.STATUSDESCRIPTION   STATUSDESCRIPTION,
  V.Empno             Empno,
  V.Ename             Ename,
  V.Job                 Job,
  v.DOJ                 DOJ
     From temp_xml T
    LEFT JOIN XMLTABLE('/WebServiceResponse'
                      PASSING T.FILE_CONTENT 
                      COLUMNS   LICENSESTATUSCODE     VARCHAR2(500)   PATH 

'SubscriptionInfo/LicenseStatusCode',
                                LICENSESTATUS         VARCHAR2(500)   PATH 

'SubscriptionInfo/LicenseStatus',
                                LicenseActionCode     VARCHAR2(500)   PATH 

'SubscriptionInfo/LicenseActionCode',
                                LicenseAction         VARCHAR2(500)   PATH 

'SubscriptionInfo/LicenseAction',
                                REMAININGHITS         VARCHAR2(500)   PATH 

'SubscriptionInfo/RemainingHits',
                                AMOUNT                VARCHAR2(500)   PATH 

'SubscriptionInfo/Amount',
                                SERVICESTATUS         XMLTYPE         PATH 

'GetResponse/GetData/ServiceStatus',
                                Result                Xmltype         Path 

'GetResponse/GetData/Result'
                                ) Q
    On (1=1) 
  Left Join Xmltable('/ServiceStatus'
                      Passing Q.ServiceStatus
                      COLUMNS
                      STATUSNBR           VARCHAR2(500) PATH 'StatusNbr'
                      ,StatusDescription  Varchar2(500) Path 'StatusDescription'
                      ) S
    On (1=1)
   Left Join Xmltable('/ServiceResult'
                      PASSING Q.SERVICERESULT
                      COLUMNS
                       Empno        VARCHAR2(500) PATH 'Empno'
                      ,Ename        VARCHAR2(500) PATH 'Ename'
                      ,Job          VARCHAR2(500) PATH 'Job'
                      ,DOJ          Varchar2(500) Path 'DOJ'                      
                      ) V
    ON (1=1)     
Where Nvl(Q.LicenseStatusCode,'~')<> '~';
  
BEGIN
BEGIN
DELETE FROM TEMP_XML;
commit;
SELECT REPLACE((REPLACE(((REPLACE

(V_XML,'xmlns="http://ws.abc.com"','+'))),'xmlns="http://www.abc.com"','+')),' +') INTO V_RESULT 

FROM DUAL;
INSERT INTO TEMP_XML
(FILE_CONTENT)
VALUES(XMLTYPE(V_RESULT));
COMMIT;
END;
BEGIN
FOR I IN C1
loop
v_Date:=to_date(i.date1, 'dd/mm/yyyy hh:mi:ss am');
INSERT INTO TEMP_SUBSCRIPTION
 ( 

LICENSESTATUSCODE,LICENSESTATUS,LICENSEACTIONCODE,LICENSEACTION,REMAININGHITS,AMOUNT,STATUSNBR,STA

TUSDESCRIPTION,Empno,Ename,Job,DOJ) 
VALUES ( 

I.LICENSESTATUSCODE,I.LICENSESTATUS,I.LICENSEACTIONCODE,I.LICENSEACTION,I.REMAININGHITS,I.AMOUNT,I

.STATUSNBR,I.STATUSDESCRIPTION,I.Empno,I.Ename,I.Job,v_date); 
end loop;
EXCEPTION WHEN OTHERS THEN
raise_application_error(-20002,'Err');
END;
commit;
END;