Calculation problem while printing many reports

poppinspoppins Member Posts: 647
Hi everyone,

I have a problem in a report...
The structure of my report is :
DataItem	Name
Employee	<Employee>
  Bull1	<Bulletin1>
  Bull2 	<Bulletin2>

There are two fields to calculate in my report.I used the following code:
       Bul1RESET;
       Bul1.SETRANGE("Codebull",Employee."Bulletin");
       Salary:=Employee."Base Salary";
       REPEAT
            Salary:=Salary+Bul1."DefaultAmount";
       UNTIL (Bul1NEXT = 0);

       Bul2.RESET;
       Bul2.SETRANGE("Codebull",Employee."Bulletin");
       SalaryN := Salary;
       REPEAT
           SalaryN :=SalaryN-Bul2."Taux";
       UNTIL (Bul2.NEXT = 0);

The code works just fine when I print a single report...but when I print many reports(for different employees) at the same time, the code gives correct values for only the first report, and no calculation is performed for the rest...The report just prints the value of Base Salary for both fields Salary and SalaryN...

What shall I do???

Answers

  • krzychub83krzychub83 Member Posts: 120
    Dear poppins

    1. Try to debug your code. Being able to see how variables are populated step after step is a great help.
    2. Regarding your report... It is dificult to tell you what is happening there without seeing whole report.
    a. In attached code I see that you are missing FINDSET/FIND('-') before each loop. Thus your will get wrong values if you will re-use that record. This is what is happening when you print this report for more than one Employee. Please review this code.
    Salary:=Employee."Base Salary";
    Bul1RESET;
    // Bul1.SETCURRENTKEY(...); //If codebull is not part of the primary key try to find a key which is using it
    Bul1.SETRANGE("Codebull",Employee."Bulletin");
    IF Bul1.FINDSET(FALSE,FALSE) THEB BEGIN //If you use NAV2009 and if you estimate to pull more than 50 rec use FIND('-') instead.
    	REPEAT
    		Salary:=Salary+Bul1."DefaultAmount";
    	UNTIL (Bul1NEXT = 0);
    END; 
    
    SalaryN := Salary;
    Bul2.RESET;
    // Bul2.SETCURRENTKEY(...); //If codebull is not part of the primary key try to find a key which is using it
    Bul2.SETRANGE("Codebull",Employee."Bulletin");
    IF Bul2.FINDSET(FALSE,FALSE) THEN BEGIN //If you use NAV2009 and if you estimate to pull more than 50 rec use FIND('-') instead.
    	REPEAT
    		SalaryN :=SalaryN-Bul2."Taux";
    	UNTIL (Bul2.NEXT = 0);
    END; 
    
    b. Why those records are defined in the Report hierarchy tree? You are lopping through them under the Employee dataitem, are you? I am assuming this is what you do. If I am wrong why don't you make any calculations on the OnAfterGetRecord trigger for Bull1, Bull2 dataitems, instead of looping through them under the Employee dataitem? Based on your description I am assuming that you pull the same data twice. Firstly you are taking them to make calculations and then they are retaken under each data item for print purposes... Am I right?

    Good luck
    KB
  • poppinspoppins Member Posts: 647
    Thanks a lot :D
Sign In or Register to comment.