Modifying Redundant Data within Reports

 

Modifying Redundant Data within Reports with Freemarker

Let’s say we have a Report coming from two tables — a header table and a detail table. If there are 20 detail records for 1 header record, that header record’s information is going to repeat 20 times, one for each detail record. See below:

It is common for customers to want to see this header information listed only once. Here are two different ways to do that:

Method 1: Showing Header Information in Line Once per Section

After compiling your application, open m-Painter and toggle the Source code.

Search for section.lastDetail as this will take you directly above the Detail Section.

I will use Freemarker Functionality to only show each Header Information (customer number and customer name) once per section. Newly added code is in red Bold Face.

<!-- END_SORT_TABLE_HEADER -->

<!-- END_REPORT_TABLE_HEADER -->

<!--<#assign var = 'x'>-->

<!-- <#list report as section> -->

<!-- <#assign lastRow = section.lastDetail /> -->

<!-- <#assign grandTotal = grandTotal0 /> -->

<!--<#if ( section.subtotalsc.size() > 0)> -->

<!-- <#assign subTotal1 = section.subtotalsc[1] /> -->

<!--</#if> -->

<!-- <#list section.detailRows as row> -->

<tr class="ten" nowrap ="nowrap" align="right">

<!--<#if row.CUSNO != var>-->

${row.CUSNO?html}

<!--</#if>-->

</td>

<td nowrap ="nowrap" align="left">

<!--<#if row.CUSNO != var >-->

${row.CNAME?html}

<!--</#if>-->

</td>

<td nowrap ="nowrap" align="left">${row.PRDNO?html}</td>

<td nowrap ="nowrap" align="left">${row.CLASS?html}</td>

<td nowrap ="nowrap" align="right">${row.MTDUD?html}</td>

</ tr >

<!--<#assign var = row.CUSNO >-->

<!-- </#list> -->

The Freemarker code states above that if the customer number (row.CUSNO) for the current record is not equal to the previous record’s customer number, print the Customer Number (CUSNO) & the Customer Name (CNAME). Otherwise, ignore that section.

In my case, I want to display the customer number and customer name fields only when the customer number (row.CUSNO) changes. In your case you will replace CUSNO in <!–<#if row.CUSNO != var >–> and <!–<#assign var = row.CUSNO >–> with a field from your application. When the value of this field changes from record to record, the fields inside the freemarker #if tags will be output.

Here is my output:

Method 2: Showing Header Information Above Records

Similar to Method 1, the Header information will only appear once, except now, we will add the header information in its own row above the Detail Section.

I will use Freemarker Functionality to only show each Header Information once above each Detail Line. Newly added code is in red Bold Face.

<!-- END_SORT_TABLE_HEADER -->

<!-- END_REPORT_TABLE_HEADER -->

<!--<#assign var = 'x'>-->

<!-- <#list report as section> -->

<!-- <#assign lastRow = section.lastDetail /> -->

<!-- <#assign grandTotal = grandTotal0 /> -->

<!--<#if (section.subtotalsc.size() > 0)> -->

<!-- <#assign subTotal1 = section.subtotalsc[1] /> -->

<!--</#if> -->

<!-- <#list section.detailRows as row> -->

<!-- <#if row.CUSNO != var > -->

<tr>

<td colspan ="3" nowrap ="nowrap" align="left">Customer # ${row.CUSNO?html} | Customer Name ${row.CNAME?html} </td>

</tr>

<!-- </#if> -->

<tr>

<td nowrap ="nowrap" align="left">${row.PRDNO?html}</td>

<td nowrap ="nowrap" align="left">${row.CLASS?html}</td>

<td nowrap ="nowrap" align="right">${row.MTDUD?html}</td>

</tr>

<!--<#assign var = row.CUSNO >-->
<!-- </#list> -->

The Freemarker code above states that if the current record’s customer number (row.CUSNO) is not equal to the previous record’s customer number, create a new row, and a new data cell (notice that the colspan value should equal the number of columns you have). Once the data cell is created, print the Customer Number (CUSNO) & the Customer Name (CNAME). Otherwise, ignore that section.

Note: I also removed the Customer # and Customer Name from the Detail, Subtotal, Grand Total, and Header sections.

Here is my output:

 

Related Posts:

Leave a Reply

Your email address will not be published. Required fields are marked *