Fetch Method to make Trial balance quickly

This is simple Fetch Method to make Trial balance quickly. Some times standard trial balance does not match due to wrong customization of application so there may be data problem in ledger balance table then you can make trial balance by using LedgerTrans table.

Performance of report will be slow but it can give accurate result.

 public boolean fetch()  
 {  
 Query q = new Query();  
 QueryBuildDataSource qbds;  
 ;  
 q= this.query();  
 qbds = q.dataSourceTable(tablenum(LedgerTrans));  
 qbds.addSortField(fieldnum(LedgerTrans,AccountNum));  
 rangeTransDate =qbds.findRange(fieldnum(LedgerTrans,TransDate));  
 purpose1 = qbds.findRange(FieldId2Ext(FieldNum(LedgerTrans, Dimension),3));  
 if(!rangeTransDate.value())  
 {  
 rangeTransDate.value(queryRange(dateMin,dateMax));  
 fromdate= dateMin;  
 todate =dateMax;  
 }  
 else  
 {  
 value=rangeTransDate.value();  
 if(strfind(value,".",1,11) != 0)  
 {  
 mindate1 =strdel(value,strfind(value,".",1,11),strlen(value));  
 maxdate1 =strDel(value,strfind(value,".",1,11)+1,-(strfind(value,".",1,11)+1));  
 dateMin = str2date(mindate1,123);  
 dateMax= str2date(maxdate1,123);  
 fromdate= dateMin;  
 todate =dateMax;  
 }  
 else  
 {  
 fromdate =str2date(value,123);  
 todate = str2date(value,123);  
 }  
 }  
 queryRun = new QueryRun(q);  
 tmpAC = "";  
 while(queryRun.next())  
 {  
 LedgerTrans1 = queryRun.get(tablenum(LedgerTrans));  
 // LedgerTable1 = queryRun.get(tablenum(LedgerTable));  
 if(tmpAC != LedgerTrans1.AccountNum)  
 {  
 if(tmpAC != "")  
 {  
 element.FinalTOTAL();  
 ProgrammableSection.executeSection();  
 element.defaultSetting();  
 }  
 }  
 LedgerAC = LedgerTrans1.AccountNum;  
 Accountnum = LedgerTable::find(LedgerTrans1.AccountNum).AccountName;  
 if(LedgerTrans1.AmountMST < 0)  
  { Credit += LedgerTrans1.AmountMST * -1; }  
 else { Debit += LedgerTrans1.AmountMST; }  
  tmpAC = LedgerTrans1.AccountNum; }  
  if(tmpAC != "")  
 { element.FinalTOTAL();  
  ProgrammableSection.executeSection();  
 element.defaultSetting(); }  
  ProgrammableSection_1.executeSection();  
  return true; }