# Interpolation

Hi Experts
I have created a report that is looking at a table called discount factor. This table has discount factor and commutation factors corresponding to each age. The reports looks at the age and pick the corresponding discount factor and commutation factor.
Now where you have a decimal age i.e an age between to ages which does not have a corresponding discount and commutation factors in the discount factor table, we want to interpolate.
Here is the code that picks up the discount and commutation factors when the ages are whole numbers or they correspond to a discount factor and commutation factor in the table.

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?
Here is how the interpolation should be:

To calculate discount facor
[(B-A * Additional months to A)/12] + A

To calculate commutation factor
A-[((A-B)*Additional months to B)/12]

in B- A , B is the next DF and A is the Previous and
in A-B A is the next CF and B is the previous
I hope thgis will help you to assist him.

Additional Months to A means the number of months added to A which makes it more than A but less than B
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.

How can i use the Above interpolation formula to fit in the code above/ Can someone help me please?

Hi Newcommer,

You need to do 2 seperate reads to the discount-table, using 2 different filters on Age, to get the record just before, and the record just after age of the employee…

You need 2 seperate instances of Discount-table defined as variable…
(I call them DiscRec1 and DiscRec2)

(This will find the record just before the age of the employee - A)
DiscRec1.SETFILTER(Age,’…%1’,AgeOfEmp);
IF NOT DiscRec1.FINDLAST THEN
ERROR(Some error telling the user that no record are lower than the age of the epmloyee);

(This will find the record just after the age of the employee - B)
DiscRec2.SETFILTER(Age,’%1…’,AgeOfEmp);
IF NOT DiscRec2.FINDFIRST THEN
ERROR(Some error telling the user that no records are higher than the age of the employee);