Calculation problem while printing many reports

poppins
Member Posts: 647
Hi everyone,
I have a problem in a report...
The structure of my report is :
There are two fields to calculate in my report.I used the following code:
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???
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???
0
Answers
-
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
KB0 -
Thanks a lot0
Categories
- All Categories
- 73 General
- 73 Announcements
- 66.6K Microsoft Dynamics NAV
- 18.7K NAV Three Tier
- 38.4K NAV/Navision Classic Client
- 3.6K Navision Attain
- 2.4K Navision Financials
- 116 Navision DOS
- 851 Navision e-Commerce
- 1K NAV Tips & Tricks
- 772 NAV Dutch speaking only
- 617 NAV Courses, Exams & Certification
- 2K Microsoft Dynamics-Other
- 1.5K Dynamics AX
- 320 Dynamics CRM
- 111 Dynamics GP
- 10 Dynamics SL
- 1.5K Other
- 990 SQL General
- 383 SQL Performance
- 34 SQL Tips & Tricks
- 35 Design Patterns (General & Best Practices)
- 1 Architectural Patterns
- 10 Design Patterns
- 5 Implementation Patterns
- 53 3rd Party Products, Services & Events
- 1.6K General
- 1.1K General Chat
- 1.6K Website
- 83 Testing
- 1.2K Download section
- 23 How Tos section
- 252 Feedback
- 12 NAV TechDays 2013 Sessions
- 13 NAV TechDays 2012 Sessions