Friday, October 09, 2015

Print No Data Found in Oracle Report/ XML Report

I Have one Requirement to print No Data Found in Oracle Reports or XML Report Template,if my SQL Statement doesn't Return any Row.


We can do it in few ways.

A)-In rdf, we can define a summary column (say CF_COUNT) which counts the number of rows of a group, and in the rtf layout create a text form field and put the helptext as 

<?if:CF_COUNT=0?>No Data Found<?end if?>


B)-Other way to text in RTF Temaplate

In the RTF layout
create a text form field and put the help text as 


<?if: count(./LIST_G_SO_NUMBER/G_SO_NUMBER/LIST_G_SO_NUMBER1/G_SO_NUMBER1)=0?>No Data Found<?end if?>
where
./LIST_G_SO_NUMBER/G_SO_NUMBER/LIST_G_SO_NUMBER1/G_SO_NUMBER1
is the expected path to the group, from the root of the xml, that we define. This expression will count the number of occurances of the group "G_SO_NUMBER1" 



C)- Using Choose and When Option

Assume we have the following XML


<G_CUSTOMER>
 <CUSTOMER_NAME>A. C. Networks</CUSTOMER_NAME>
 <ZIP>84606</ZIP>
 <STATE>UT</STATE>
 <ADDRESS_LINE2/>
 <ADDRESS_LINE1>3405 East Bay Blvd.</ADDRESS_LINE1>
 <COUNTRY>US</COUNTRY>
 <CITY>Provo</CITY>
 <CUSTOMER_NUMBER>1143</CUSTOMER_NUMBER>
 <G_INVOICES>
  ...
 </G_INVOICES>
 <G_INVOICES>
  ...
 </G_INVOICES>
 <G_INVOICES>
  ...
 </G_INVOICES>
 <G_INVOICES>
  ...
 </G_INVOICES>
 </G_CUSTOMER>
<G_CUSTOMER>
 <CUSTOMER_NAME>Networks Inc</CUSTOMER_NAME>
 <ZIP>93934</ZIP>
 <STATE>CO</STATE>
 <ADDRESS_LINE2/>
 <ADDRESS_LINE1>8762 Rawlins Road</ADDRESS_LINE1>
 <COUNTRY>US</COUNTRY>
 <CITY>Castle Rock</CITY>
 <CUSTOMER_NUMBER>1143</CUSTOMER_NUMBER>
 <G_INVOICES/>
</G_CUSTOMER>

Notice the second CUSTOMER has a no INVOICES present. We can test for that and replace an invoice section with a 'No Data Found' string.

The 'if' statement in XSL does not have a 'then else' format i.e. all we have is 'if expr end if'. There is an alternative, the 'choose' statement, its a little verbose but we can use it.

<?choose:?>
 <?when:count(TRX_NUMBER) > 0?>
     Invoice Table
 <?end when?>
 <?otherwise:?>
     No Data Found
 <?end otherwise?>
<?end choose?>

Notice all we are doing is counting how many instances of TRX_NUMBER are present. If there are one or more present then the Invoice Table is rendered otherwise we get the 'No Data Found' string.

No comments:

Post a Comment

Clear BNE Cache for WebADI Changes

It Sometime happens that WebAdi Changes doesn't reflect once migrated in controlled instances. Here are the quick steps(Generally perfor...