Flags control example in report of MSD Axapta

Flags control example in report of Axapta I think its going to difficult to understand.


 public boolean fetch()  
 {  
 // boolean ret;  
 // ret = super();  
 boolean HeaderFlag;  
 boolean ProgFlag;  
 boolean FirstRun;  
 Boolean HeaderOnFirstRun;  
 QueryBuildDataSource qbds__RegBatchProcess;  
 QueryBuildRange QrRegNo,qrcrop,rangeTransDate,QBR_TechYear;  
 Query q = new Query();  
 ;  
 q = this.query();  
 qbds__RegBatchProcess = q.dataSourceTable(tablenum(_RegBatchProcess));  
 //Add Sort Field  
 qbds__RegBatchProcess.addSortField(fieldnum(_RegBatchProcess, InventLocationId));//1 Center  
 qbds__RegBatchProcess.addSortField(fieldnum(_RegBatchProcess, _seasonid));//2 Season  
 qbds__RegBatchProcess.addSortField(fieldnum(_RegBatchProcess,Stg));//3 Stage  
 qbds__RegBatchProcess.addSortField(fieldnum(_RegBatchProcess, ItemId));//4 Crop  
 qbds__RegBatchProcess.addSortField(fieldnum(_RegBatchProcess, CustAccount));//5 MPCode  
 qbds__RegBatchProcess.addSortField(fieldnum(_RegBatchProcess, InventColorId));//6 Variety  
 qbds__RegBatchProcess.addSortField(fieldnum(_RegBatchProcess, _DistrictName));//7 District  
 qbds__RegBatchProcess.addSortField(fieldnum(_RegBatchProcess, _TName));//8 T  
 qbds__RegBatchProcess.addSortField(fieldnum(_RegBatchProcess, _VName));//9 V  
 //Add Sort Field  
 QueryRun = new QueryRun(q);  
 season = "";  
 crop = "";  
 Centername = "";  
 stage = "";  
 HeaderFlag = False;  
 Variety = "";  
 District ="";  
 T = "";  
 V = "";  
 NoOfSP = 0;  
 AreaRegistered = 0;  
 ProgFlag = False;  
 TotalNoOfSP =0 ;  
 TotalAreaReg =0;  
 FirstRun = True;  
 TotalFlag = False;  
 HeaderOnFirstRun = False;  
 chkMPCode = "";  
 QBR_TechYear = qbds__RegBatchProcess.findRange(fieldNum(_RegBatchProcess,TechYear));  
 if (QBR_TechYear.value() != "")  
 {  
 TechYear = QBR_TechYear.value();  
 // info("START");  
 /*while Select * from _RegBatchProcess_object  
 order by _RegBatchProcess_object.InventLocationId ,  
 _RegBatchProcess_object._seasonid ,  
 _RegBatchProcess_object._B_F_II ,  
 _RegBatchProcess_object.ItemId ,  
 _RegBatchProcess_object.InventColorId ,  
 _RegBatchProcess_object._DistrictName , _RegBatchProcess_object._TName,  
 _RegBatchProcess_object._VName*/  
 while(QueryRun.next())  
 {  
 _RegBatchProcess_Object = QueryRun.get(tablenum(_RegBatchProcess));  
 if(Centername != _RegBatchProcess_Object.InventLocationId)  
 {  
 HeaderFlag = True;  
 }  
 else if(season != enum2str(_RegBatchProcess_Object._SeasonId))  
 {  
 HeaderFlag = True;  
 }  
 else if(stage != enum2str(_RegBatchProcess_Object._B_F_II))  
 { HeaderFlag = True; }  
 else if(crop != _RegBatchProcess_Object.ItemId)  
 { HeaderFlag = True; }  
 else  
 {HeaderFlag = False;}  
 /*  
 else if(MPCode != _RegBatchProcess_Object.CustAccount)  
 { HeaderFlag = True; }  
 */  
 if(FirstRun == False)  
 {  
 if(Variety != _RegBatchProcess_Object.InventColorId)  
 {ProgFlag = True;}  
 else if(District != _RegBatchProcess_Object._DistrictName)  
 { ProgFlag = True; }  
 else if(T != _RegBatchProcess_Object._TName)  
 { ProgFlag = True; }  
 else if(V != _RegBatchProcess_Object._VName)  
 { ProgFlag = True; }  
 else if(MPCode != _RegBatchProcess_Object.CustAccount)  
 { ProgFlag = True; }  
 else  
 {ProgFlag = False;}  
 }  
 if (FirstRun == True)  
 {  
 Centername = _RegBatchProcess_Object.InventLocationId;  
 season = enum2str(_RegBatchProcess_Object._SeasonId);  
 stage = enum2str(_RegBatchProcess_Object._B_F_II);  
 crop = _RegBatchProcess_Object.ItemId;  
 MPCode = _RegBatchProcess_Object.CustAccount;  
 Variety = _RegBatchProcess_Object.InventColorId;  
 District = _RegBatchProcess_Object._DistrictName;  
 T = _RegBatchProcess_Object._TName;  
 V = _RegBatchProcess_Object._VName;  
 // Header  
 // if (Variety != "" && District != "" && T != "" && V != "")  
 // {  
 info ("HEADER # " + Centername + " : " + stage + " : " + season  
 + " : " + InventTable::find(crop).ItemName);  
 MPCode = _RegBatchProcess_Object.CustAccount;  
 Header1.executeSection();  
 chkMPCode = "";  
 HeaderOnFirstRun = True;  
 // }  
 ProgFlag = False;  
 NoOfSP = 0;  
 AreaRegistered = 0 ;  
 //Reset Total  
 TotalNoOfSP =0 ;  
 TotalAreaReg =0;  
 }  
 else  
 {  
 if(HeaderFlag == True)  
 {  
 Centername = _RegBatchProcess_Object.InventLocationId;  
 season = enum2str(_RegBatchProcess_Object._SeasonId);  
 stage = enum2str(_RegBatchProcess_Object._B_F_II);  
 crop = _RegBatchProcess_Object.ItemId;  
 MPCode = _RegBatchProcess_Object.CustAccount;  
 Variety = _RegBatchProcess_Object.InventColorId;  
 District = _RegBatchProcess_Object._DistrictName;  
 T = _RegBatchProcess_Object._TName;  
 V = _RegBatchProcess_Object._VName;  
 // if (Variety != "" && District != "" && T != "" && V != "")  
 // {  
 if (HeaderOnFirstRun != True)  
 {  
 info ("HEADER # " + Centername + " : " + stage + " : " + season  
 + " : " + InventTable::find(crop).ItemName);  
 Header1.executeSection();  
 chkMPCode = "";  
 HeaderOnFirstRun = True;  
 }  
 info ("PS # " + CustTable::find(MPCode).Name  
 + " : " +InventColor::find(Variety,Crop).Name  
 + " : " + _District::find(District)._DistrictName  
 + " : " + _T::find(T)._TName  
 + " : " + _V::find(V)._VName  
 + " : " + num2str(NoOfSP,4,2,0,0)  
 + " : " + num2str(AreaRegistered,4,2,0,0));  
 progdetail.executeSection();  
 TotalNoOfSP = NoOfSP + TotalNoOfSP;  
 TotalAreaReg = AreaRegistered + TotalAreaReg;  
 TotalFlag = True;  
 // }  
 if(TotalFlag == True)  
 {  
 info ("TOTAL # " + Centername + " : " + stage + " : " + season  
 + " : " + InventTable::find(crop).ItemName  
 + " : " + num2str(TotalNoOfSP,4,2,0,0)  
 + " : " + num2str(TotalAreaReg,4,2,0,0));  
 TotalFlag = False;  
 ProgTotal.executeSection();  
 }  
 // if (Variety != "" && District != "" && T != "" && V != "")  
 // {  
 info ("HEADER # " + Centername + " : " + stage + " : " + season  
 + " : " + InventTable::find(crop).ItemName);  
 this.newPage();  
 chkMPCode = "";  
 Header1.executeSection();  
 // }  
 ProgFlag = False;  
 NoOfSP = 0;  
 AreaRegistered = 0 ;  
 //Reset Total  
 TotalNoOfSP =0 ;  
 TotalAreaReg =0;  
 }  
 }  
 if(ProgFlag == True)  
 {  
 //programmable section execution  
 if (Variety != "" && District != "" && T != "" && V != "")  
 {  
 if (HeaderOnFirstRun != True)  
 {  
 info ("HEADER # " + Centername + " : " + stage + " : " + season  
 + " : " + InventTable::find(crop).ItemName);  
 Header1.executeSection();  
 chkMPCode = "";  
 HeaderOnFirstRun = True;  
 }  
 info ("PS # " + CustTable::find(MPCode).Name+ " : " +InventColor::find(Variety,Crop).Name+ " : " + _District::find(District)._DistrictName+ " : " + _T::find(T)._TName+ " : " + _V::find(V)._VName+ " : " + num2str(NoOfSP,4,2,0,0)+ " : " + num2str(AreaRegistered,4,2,0,0));  
 progdetail.executeSection();  
 TotalNoOfSP = NoOfSP + TotalNoOfSP;  
 TotalAreaReg = AreaRegistered + TotalAreaReg;  
 TotalFlag = True;  
 }  
 if(HeaderFlag == True)  
 {  
 if(TotalFlag == True)  
 {  
 info ("TOTAL # " + Centername + " : " + stage + " : " + season+ " : " + InventTable::find(crop).ItemName+ " : " + num2str(TotalNoOfSP,4,2,0,0)+ " : " + num2str(TotalAreaReg,4,2,0,0));  
 TotalFlag = False;  
 ProgTotal.executeSection();  
 }  
 // if (Variety != "" && District != "" && T != "" && V != "")  
 // {  
 info ("HEADER # " + Centername + " : " + stage + " : " + season+ " : " + InventTable::find(crop).ItemName);  
 this.newPage();  
 chkMPCode = "";  
 Header1.executeSection();  
 // }  
 ProgFlag = False;  
 NoOfSP = 0;  
 AreaRegistered = 0 ;  
 //Reset Total  
 TotalNoOfSP =0 ;  
 TotalAreaReg =0;  
 }  
 NoOfSP = 0;  
 AreaRegistered = 0 ;  
 }  
 Centername = _RegBatchProcess_Object.InventLocationId;  
 season = enum2str(_RegBatchProcess_Object._SeasonId);  
 stage = enum2str(_RegBatchProcess_Object._B_F_II);  
 crop = _RegBatchProcess_Object.ItemId;  
 MPCode = _RegBatchProcess_Object.CustAccount;  
 Variety = _RegBatchProcess_Object.InventColorId;  
 District = _RegBatchProcess_Object._DistrictName;  
 T = _RegBatchProcess_Object._TName;  
 V = _RegBatchProcess_Object._VName;  
 NoOfSP = NoOfSP + 1;  
 AreaRegistered = AreaRegistered + _RegBatchProcess_Object._Area;  
 info ("DATA # " + Centername + " : " + stage + " : " + season  
 + " : " + InventTable::find(crop).ItemName  
 + " : " + CustTable::find(MPCode).Name  
 + " : " + InventColor::find(Variety,Crop).Name  
 + " : " + _District::find(District)._DistrictName  
 + " : " + _T::find(T)._TName  
 + " : " + _V::find(V)._VName  
 + " : " + num2str(NoOfSP,4,2,0,0)  
 + " : " + num2str(AreaRegistered,4,2,0,0));  
 FirstRun = False;  
 }  
 // if (Variety != "" && District != "" && T != "" && V != "")  
 // {  
 info ("PS # " +InventColor::find(Variety,Crop).Name+ " : " + _District::find(District)._DistrictName+ " : " + _T::find(T)._TNam+ " : " + _V::find(V)._VName+ " : " + num2str(NoOfSP,4,2,0,0)+ " : " + num2str(AreaRegistered,4,2,0,0));  
 // TotalFlag = True;  
 progdetail.executeSection();  
 TotalNoOfSP = NoOfSP + TotalNoOfSP;  
 TotalAreaReg = AreaRegistered + TotalAreaReg;  
 info ("TOTAL # " + Centername + " : " + stage + " : " + season+ " : " + InventTable::find(crop).ItemNam+ " : " + CustTable::find(MPCode).Name+ " : " + num2str(TotalNoOfSP,4,2,0,0)  
 + " : " + num2str(TotalAreaReg,4,2,0,0));  
 // TotalFlag = False;  
 ProgTotal.executeSection();  
 // }  
 return true;  
 }  
 else  
 {  
 info("Select TechYear");  
 return False;  
 }  
 }