Tuesday, August 16, 2011

Best Practices in XMLP Reports

As a first step of developing RTF template, setup the page properties.
It includes Margins and Orientation. These setting depend on the Report layout.

Navigation in MS Word:  File -> Page setup

Printing the labels depending on the Language this can be done with “Choose” statement in RTF template. It is a conditional formatting statement; if certain conditions are met in the XML data then specific sections of the template will be rendered.

Below example validates the customer language and prints the appropriate label.


<Choose
<When CUST_LANG='ESA'
Su Numero de Factura
End When>
<When CUST_LANG='PTB'
Número de sua Nota
End When>
<When CUST_LANG='F'
French Label
End When>
<When CUST_LANG='US'
Your Invoice Number
End When>
<Otherwise
Your Invoice Number
End Otherwise>
End Choose>

There are some situations like we need to fit the data into specified field width and truncate remaining information. To accomplish this,

1.    Create a form-field quite left to the data form-field which we need to truncate.
2.    Click on Add help text.
3.    Write the below logic in form-field help text.

<xsl:attribute xdofo:ctx="block" name="wrap-option">no-wrap</xsl:attribute><xsl:attribute xdofo:ctx="block" name="overflow">hidden</xsl:attribute>

4. Press Ok.



































We can divide the whole template logic into sub-templates and can be called where ever required.

To create sub-template:

  1. Create a form-field and write the text <?template:template_name?> in the form-field help text. This is where the sub-template section starts.
  2. Create another form-field and write <?end template?> in its help text. This is where the sub-template ends.
  3. To call the sub-template use the syntax <?call:template_name?>.

Where “template_name” is the name of the sub-template.

For Ex:

<?if:COUNTRY=’INDIA’?>
<?call:India_Body?>
<?end if?>

<?if:COUNTRY!=’INDIA’?>
<?call:Global_Body?>
<?end if?>

<?template:India_Body?>
   INDIA
<?end template?>

<?template:Global_Body?>
   GLOBAL
<?end template?>



Defining a group will notify XML Publisher that for each occurrence of an element, you want the included fields displayed. At runtime, XML Publisher will loop through the occurrences of the element and display the fields each time.

To define a group, follow the steps below.

  1. Create a form-field
  2. Write the text “<?for-each:GROUP_NAME?>” in the help text“of the form-field. This indicates the starting of the GROUP. Where GROUP_NAME is the “Group Element Tag Name” in the XML output.
  3. Create another form-field and write the text “<?end for-each?>” in the “help text” of the form-field. This indicates the end of the GROUP.
  4. Create as many form-fields, to display the records of the group, in between the above 2 form-fields.


Tables can be used for better alignment of data. This way look and feel of the output will improve.

Navigation in MS Word:

Table -> Insert -> Enter Number of columns and number of rows.

Set different Properties like Alignment, Text wrapping, Cell margins (top, bottom, left and right), Row Height, Column Width, Borders and shading.


Note: If required we can draw the nested tables and set the properties.




Setting the Row height and width will affect the data display in the output.

Draw the table and set the row and column Properties.

Row Height: Specify the height in inches and row height is “at least” or “exactly”.
















Column Width: Specify the column width and Measure in either “Percentage” or “Inches”


















Let us assume that an RTF is printing the Item Information (like Item Number, Item Description, Qty, UOM etc.). In some cases, if the Description of the item is big, then it may happen that part of the description may print in the first page along with the other information and part may go to next page.

In this case if we want to prevent this ROW BREAKING

  1. Highlight the table row, which is printing the Item information.
  2. Go to the Table Properties - Row tab (as shown in the below screenshot).
  3. Un-check the “Allow row to break across pages” option.













In order to repeat the header rows across the top of each page follow the below steps:

  1. Highlight the table row, which is printing the column labels information.
  2. Go to the Table Properties - Row tab (as shown in the below screenshot).
  3. check the “Repeat as header row at the top of each page” option.


To print the page numbers, place the cursor exactly where the page number needs to be print.

Navigate to InsertàAuto textàAuto text tab

Select the required page number format (Pn, page x of y).





































While printing the amount we should take care about formatting.

There are different techniques.

a) Formatting Number in Template.
b) Get the formatted Number from Oracle Report.

b)   Formatting in Template:

1.    Place form field
2.    Set the Type as Number,
3.    Give the Appropriate Default Number For Ex: 0.00
4.    Select the Appropriate Number Format
5.    Click on Add help text
6.    Select Status bar tab and place data tag.




























We can restrict the no. of records per page and remaining gap filling with spaces. Follow the below steps to implement this.

  1. Set the No. of lines per page.
    1. Create a form-field “lines per page’’ write ‘<xsl:variable name="lpp1" select="number(no of lines)"/>’ in the form field help text. This declares the no of lines per page.



  1. Create the Section. For this, create a form-filed “Section;Pagenation” write ‘<?for-each@section:HEADER_GROUP_NAME?><xsl:variable xdofo:ctx="incontext" name="group" select=".//LINES_GROUP_NAME"/>’ in the status bar.
Ex: <?for-each@section:G_CHECKS?><xsl:variable xdofo:ctx="incontext" name="group" select=".//G_INVOICES"/>

     <xsl:variable xdofo:ctx="incontext" name="check"    select="../HEADER_GROUP_NAME"/><xsl:variable name="cno" xdofo:ctx="incontext" select="position()"/> in the help key of the form filed.

Ex: <xsl:variable xdofo:ctx="incontext" name="check" select="../G_CHECKS"/><xsl:variable name="cno" xdofo:ctx="incontext" select="position()"/>




  1. Create form-field “for-each” write ‘<?for-each:$group?><?if:(position()-1) mod $lpp1=0?><xsl:variable name="start" xdofo:ctx="incontext" select="position()"/>’ in the help text.

  1. Create form field ‘F’ in the lines section write the
‘<?for-each:$group?><?if:position()>=$start and position()<$start+$lpp1?>’ in the status bar section.

  1. Create form field ‘E’ and write ‘<?end if?><?end for-each?>’ in the status bar section.

  1. Create form field ‘filler spaces’ write ‘<?if:not(count($group) mod $lpp1=0) and     ($start+$lpp1>count($group))?>’ in status bar and write ‘<xsl:variable name="blanks" xdofo:ctx="incontext" select="number($lpp1)-(count($group)-number($start)+1)"/>’ in help key.

  1. Create required rows for filling the gap with space and write the below in first and last column of the each row.

First Column: <?if:$blanks>=26?>
Last Column: <?end if?>

          Ex: Let’s assume we are printing 26 lines per page.

<?if:$blanks>=26?>



<?end if?>
<?if:$blanks>=25?>



<?end if?>


          Continue till the $blanks equal to 1
<?if:$blanks>=1?>



<?end if?>


  1. Create form field ‘End of Filler Spaces’ and write ‘<?end if?>’ in status bar.

  1. Create form filed ‘Page break’ write ‘<?if:$cno<count($check)?><xsl:attribute xdofo:ctx="inblock" name="break-before">page</xsl:attribute><?end if?>’ in status bar.
                            
  1. Create form field ‘End For Each G_CHECKS’ write ‘<?end if?><?end for-each?><?end for-each?>’ in status bar.


Please find the Attached RTF file with the above example.
There are some situations like we need to fit the data into specified field width and truncate remaining information. To accomplish this,

1.    Create a form-field quite left to the data form-field which we need to truncate.
2.    Click on Add help text.
3.    Write the below logic in form-field help text.

<xsl:attribute xdofo:ctx="block" name="wrap-option">no-wrap</xsl:attribute><xsl:attribute xdofo:ctx="block" name="overflow">hidden</xsl:attribute>

4. Press Ok.



































We can divide the whole template logic into sub-templates and can be called where ever required.

To create sub-template:

  1. Create a form-field and write the text <?template:template_name?> in the form-field help text. This is where the sub-template section starts.
  2. Create another form-field and write <?end template?> in its help text. This is where the sub-template ends.
  3. To call the sub-template use the syntax <?call:template_name?>.

Where “template_name” is the name of the sub-template.

For Ex:

<?if:COUNTRY=’INDIA’?>
<?call:India_Body?>
<?end if?>

<?if:COUNTRY!=’INDIA’?>
<?call:Global_Body?>
<?end if?>

<?template:India_Body?>
   INDIA
<?end template?>

<?template:Global_Body?>
   GLOBAL
<?end template?>



Defining a group will notify XML Publisher that for each occurrence of an element, you want the included fields displayed. At runtime, XML Publisher will loop through the occurrences of the element and display the fields each time.

To define a group, follow the steps below.

  1. Create a form-field
  2. Write the text “<?for-each:GROUP_NAME?>” in the help text“of the form-field. This indicates the starting of the GROUP. Where GROUP_NAME is the “Group Element Tag Name” in the XML output.
  3. Create another form-field and write the text “<?end for-each?>” in the “help text” of the form-field. This indicates the end of the GROUP.
  4. Create as many form-fields, to display the records of the group, in between the above 2 form-fields.


Tables can be used for better alignment of data. This way look and feel of the output will improve.

Navigation in MS Word:

Table -> Insert -> Enter Number of columns and number of rows.

Set different Properties like Alignment, Text wrapping, Cell margins (top, bottom, left and right), Row Height, Column Width, Borders and shading.


Note: If required we can draw the nested tables and set the properties.




Setting the Row height and width will affect the data display in the output.

Draw the table and set the row and column Properties.

Row Height: Specify the height in inches and row height is “at least” or “exactly”.
















Column Width: Specify the column width and Measure in either “Percentage” or “Inches”


















Let us assume that an RTF is printing the Item Information (like Item Number, Item Description, Qty, UOM etc.). In some cases, if the Description of the item is big, then it may happen that part of the description may print in the first page along with the other information and part may go to next page.

In this case if we want to prevent this ROW BREAKING

  1. Highlight the table row, which is printing the Item information.
  2. Go to the Table Properties - Row tab (as shown in the below screenshot).
  3. Un-check the “Allow row to break across pages” option.













In order to repeat the header rows across the top of each page follow the below steps:

  1. Highlight the table row, which is printing the column labels information.
  2. Go to the Table Properties - Row tab (as shown in the below screenshot).
  3. check the “Repeat as header row at the top of each page” option.


To print the page numbers, place the cursor exactly where the page number needs to be print.

Navigate to InsertàAuto textàAuto text tab

Select the required page number format (Pn, page x of y).





































While printing the amount we should take care about formatting.

There are different techniques.

a) Formatting Number in Template.
b) Get the formatted Number from Oracle Report.

b)   Formatting in Template:

1.    Place form field
2.    Set the Type as Number,
3.    Give the Appropriate Default Number For Ex: 0.00
4.    Select the Appropriate Number Format
5.    Click on Add help text
6.    Select Status bar tab and place data tag.




























We can restrict the no. of records per page and remaining gap filling with spaces. Follow the below steps to implement this.

  1. Set the No. of lines per page.
    1. Create a form-field “lines per page’’ write ‘<xsl:variable name="lpp1" select="number(no of lines)"/>’ in the form field help text. This declares the no of lines per page.



  1. Create the Section. For this, create a form-filed “Section;Pagenation” write ‘<?for-each@section:HEADER_GROUP_NAME?><xsl:variable xdofo:ctx="incontext" name="group" select=".//LINES_GROUP_NAME"/>’ in the status bar.
Ex: <?for-each@section:G_CHECKS?><xsl:variable xdofo:ctx="incontext" name="group" select=".//G_INVOICES"/>

     <xsl:variable xdofo:ctx="incontext" name="check"    select="../HEADER_GROUP_NAME"/><xsl:variable name="cno" xdofo:ctx="incontext" select="position()"/> in the help key of the form filed.

Ex: <xsl:variable xdofo:ctx="incontext" name="check" select="../G_CHECKS"/><xsl:variable name="cno" xdofo:ctx="incontext" select="position()"/>




  1. Create form-field “for-each” write ‘<?for-each:$group?><?if:(position()-1) mod $lpp1=0?><xsl:variable name="start" xdofo:ctx="incontext" select="position()"/>’ in the help text.

  1. Create form field ‘F’ in the lines section write the
‘<?for-each:$group?><?if:position()>=$start and position()<$start+$lpp1?>’ in the status bar section.

  1. Create form field ‘E’ and write ‘<?end if?><?end for-each?>’ in the status bar section.

  1. Create form field ‘filler spaces’ write ‘<?if:not(count($group) mod $lpp1=0) and     ($start+$lpp1>count($group))?>’ in status bar and write ‘<xsl:variable name="blanks" xdofo:ctx="incontext" select="number($lpp1)-(count($group)-number($start)+1)"/>’ in help key.

  1. Create required rows for filling the gap with space and write the below in first and last column of the each row.

First Column: <?if:$blanks>=26?>
Last Column: <?end if?>

          Ex: Let’s assume we are printing 26 lines per page.

<?if:$blanks>=26?>



<?end if?>
<?if:$blanks>=25?>



<?end if?>


          Continue till the $blanks equal to 1
<?if:$blanks>=1?>



<?end if?>


  1. Create form field ‘End of Filler Spaces’ and write ‘<?end if?>’ in status bar.

  1. Create form filed ‘Page break’ write ‘<?if:$cno<count($check)?><xsl:attribute xdofo:ctx="inblock" name="break-before">page</xsl:attribute><?end if?>’ in status bar.
                            
  1. Create form field ‘End For Each G_CHECKS’ write ‘<?end if?><?end for-each?><?end for-each?>’ in status bar.


Please find the Attached RTF file with the above example.

Let us assume that we need the report output in 4 copies.

Steps to implement the above are as follows.

1. Create a new Lookup type.

Navigation: Application Developer Responsibility -> Application -> Lookups -> Application Object library.


2. Use fnd_lookup_values_vl  table in the data model query group. 
     Add the following two conditions at the Where clause section.
     AND flvv.lookup_type ='TPCO NOTA FISCAL COPY'
     AND flvv.ENABLED_FLAG = 'Y'
3. Order by flvv.MEANING