SSRS Tip: Take care to clear the temp table record in RDP reports

All RDP reports adopt the approach of filling in all the required data into a temp table. In this article let us how a simple “clear” statement could be helpful as well as give way to a hidden problem in disguise.

Consciously make use of “table.clear()”
Let us look at the example here where the method highlighted here “insertCustListTmp” is called in a loop from the procesreport method.The method “isReversed” whose implementation is not shown here finds if there is reverse happened for the trans and also returns the reverse journal id. (Don’t funtionally interpret the implementation)

private void insertCustTransListTmp(ExchAdjustment _exchangeAdjustmentType, 
CustTransListTmp _custTransListTmp, 
RecordInsertList _tmpTableRecordList, 
TransactionReversalTrans _transactionReversalTransLocal)
{   

   //_custTransListTmp.clear();

    this.initBalance(_exchangeAdjustmentType, _custTransListTmp);
    _custTransListTmp.TraceNum = _transactionReversalTransLocal.TraceNum;

    if (this.isReversed())
    {
        _custTransListTmp.Reversed       = true;
        _custTransListTmp.ReverseVoucher = this.getReversedVoucer();
    }

    _custTransListTmp.Reversed = this.reversed(_transactionReversalTransLocal);
    _custTransListTmp.AccountNum = custTable.AccountNum;
    _custTransListTmp.Name = custTable.name();
    _custTransListTmp.Voucher = custTrans.Voucher;
    _custTransListTmp.insert();
 }

Following is the data present at the table level.

Table_data

 

 

 

So when the clear is commented the data filled in the temptable would look like this

Table_Without_Clear

 

 

 

When the clear is applied the temptable would reflect the reality

Table_With_Clear

 

 

 

 

when you run your report it could appear that something is going terribly wrong in your logic but it could be the simple clear statement missing at the back.

Practically though the common problem area could be in reports this can happen anywhere both in temp and regular tables. However you can also use this to your advantage when say every field is initialized unlike the conditional flows specified here. So you can have the methods like “initFromCustTable” called only once and doesn’t required to be call again since the clear is not invoked. Whatever is the case make sure the decision is taken consciously.

Optionally run this code to quickly understand what is discussed here…

static void JobTestClear(Args _args)
{
    CustTransListTmp transTmp; 
    CustTable        custTable;
    boolean insert;
    
    select * from custTable;
    
    while (custTable)
    {
        if (insert)
        {
            transTmp.AccountNum = custTable.AccountNum;
        }
        
        transTmp.insert();
        
        insert = !insert;
        
        print transTmp.AccountNum;
        pause;
        
        next custTable;
    } 
}

 

Info: Thank to Pradeep Itnal who reminded me of this problem and to make a note here. 

7720EN_cov

Sharpen your SSRS skills. Buy the Dynamics AX reporting cookbook

Keep yourself updated with Dynamics Ax – Check the weekly Must read section here