Dis.SETRANGE(Age,ageOfEmp); IF Dis.FIND('-') THEN BEGIN DF := Dis."Discount Factor"; DFpre08 := Dis."Discount Factor Pr08"; CF := Dis."Commutation Factor"; CFpre08 := Dis."Commutation Factor Pr08"; END ELSE BEGIN ERROR('Unable to get Discount Factors please ensure they are entered in the database'); END; // Updating DF and CF on Employee Table. Employee."Discount Factor" := DF; Employee."Discount Factor Pr08" := DFpre08; Employee."Commutation Factor" := CF; Employee."Commutation Factor Pr08" := CFpre08; Employee.MODIFY(); { End of code for search DF and update Employee table. }how can i do the interpolation on the above?
To calculate discount facor [(B-A * Additional months to A)/12] + A To calculate commutation factor A-[((A-B)*Additional months to B)/12]
Comments
I assume the table Discount Factor has "Age" as primary key... In this case you could try:
Hope I understood you and the above will somewhat help you... if not please give us some more details like what are A and B?
Is A the next available whole number age? or is it the next available age CF/DF? And B would be previous of whichever?
As far as the code provided by BBlue, I would probably use a better age range record finder.
ex...
That way you can at least get the previous and next ages if they aren't side by side.
in A- B , A is the next DF and B is the Previous and
in B-A B is the next CF and A is the previous
I hope thgis will help you to assist him.
How can you fity in the interpolation formula in?
Example A= 25 and B=26 and the age between them which should be interpolated is 25.5 and 0.5 is the addition months to A which is 6 months.
I hope this is clear?
I thought a bit more at this and I wrote some code which will hopefully help you. Of course, I believe it should be refined and maybe modified to serve your purpose.
First of all, I started with the assumption that the Discount Factor table has "Age" as a primary key, you dind't mentioned that, but this is the structure I would create such a table.
I calculated "CF" and "DF" based on the exact formulas you provided, you should check again... and "AgeDifference" is the difference from the age required to interpolate and the nearest lower age - multiplied by 12 gives you the difference in months.
dis_below and dis_above are rec variables for Discount Factor table which I used to search for the nearest lower and upper values of the age that will be interpolated.
As for "Discount Factor Pr08" and "Commutation Factor Pr08" - I believe it can be calculated the same as DF and CF.
Good luck!
(Ah nm, I didn't notice you used Record.*FINDLAST*) - Because essentially even the first record would be less than 'Var'. Best method to use would be to find the first record using '>%1' filter and then use NEXT(-1) to get the record before.
[edit: Oh and there's really no need to round the age in the filter. Ex: ageOfEmp = 53.6, Age: 54 is greater than ageOfEmp whether it is 53.6 or 53]
Thanks
You can use indeed setfilter '>%1' to find the next record and then NEXT(-1) to find the previous, that's just another way to do it... as for the ROUND, you are right, you don't necessary need to use it, but there is nothing wrong with that... I wonder what the real problem is :-k
kolaboy and/or web ,
What exactly does not work? How do you use this report? Don't you enter an ageOfEmp from RequestForm and the report calculates the CF and DF (if not found in table by interpolating)? I did't tested on real data and I used your exact formulas, as posted here... I see this report as a batch type with no data items and that just calculates the CF and DF you need. Please correct me if I am wrong.
We do want to help you, but if not providing more info we can just assume some details...
Here is BBLUE's code it used to test but not working. I am using 4.0 that is why it used FIND('-') instead of FINDFIRST. We are not making used of DFpre08 and CFpre08. We are considering two periods, before 2008 and after 2007.
BBLUE can check what i am not doing right?
Thanks
I assume that "Age" is not the primary key of your "Discount Factor" table as I believe you do a SETRANGE instead of a GET, just before the code mentioned:
Am I wrong? In this case you don't need the
... this was for the GET not give you an error... You should redesign the code
By the way? How do you calculate the age? Are you using:
I don't know... put messages during the code, see where and what does not behave correctly...
I have some small suggestions, which although may not provide a solution hopefully it might get you working in the right direction.
(Oh and.. I don't think it was too difficult for my company but, if I may suggest, upgrade to at least 4.0 SP1 so you not only can use new, more efficient, features like: Findfirst, Findlast, Findset as well as others.)
For your case, even though you probably don't have a huge table of employees, it would be better practice to use variables to store the small data rather than making reference to 3 record variables connecting to the same table. (Dis, dis_below, dis_above)
The main difference between my code and web's/BBlue's is that you two have a section of code that is shown twice. If ageOfEmp is a whole number and not found in the table, the same code to find the median DF/CF of a decimal age is used.
I have some small suggestions, which although may not provide a solution hopefully it might get you working in the right direction.
(Oh and.. I don't think it was too difficult for my company but, if I may suggest, upgrade to at least 4.0 SP1 so you not only can use new, more efficient, features like: Findfirst, Findlast, Findset as well as others.)
For your case, even though you probably don't have a huge table of employees, it would be better practice to use variables to store the small data rather than making reference to 3 record variables connected to the same table. (Dis, dis_below, dis_above)
The main difference between my code and web's/BBlue's is that you both have two sections of code which are identical. If ageOfEmp is a whole number and not found in the table, the same code to find the median DF/CF of a decimal age is used.