Add range, Sort field, datasource in axapta using code in report

This is sample code to Add range, Sort field, datasource in axapta using code in report. This code you can apply in fetch method in Report. This code is related to Axapta report.

 QueryBuildRange fromdt,todt;  
 str value;  
 Query q = new Query();  
 Query q1 = new Query();  
 QueryBuildDataSource qbds,qbds1;  
 QueryBuildRange startTransDate;  
 QueryBuildRange endTransDate;  
 QueryRun qr1;  
 Add range, Sort field, datasource in axapta using code in report  
 q = this.query();  
 q1=this.query();  
 qbds = q.dataSourceTable(tablenum(EmplTable));  
 // dateMin = str2date(mindate1,123);  
 qbds1=q1.dataSourceTable(tablenum(_PMaster));  
 qbds1.addSortField(fieldnum(_PMaster,PCategory));  
 fromdt =qbds1.findRange(fieldnum(_PMaster,Date_From));  
 todt=qbds1.findRange(fieldnum(_PMaster,Date_To));  
 mindate1=fromdt.value();  
 maxdate1=todt.value();  
 fromDate=str2date(mindate1,123);  
 toDate=str2date(maxdate1,123);