In this lesson, you create an EGL Service part, which is a generatable part. You must place each generatable part in a separate source file, and the name of the part must be the same as the name of the file.
services
MortgageCalculationService
EGL
adds the .egl file extension.
package services;
service MortgageCalculationService
end
function amortize(inputData MortgageCalculationResult inOut)
amt MONEY = inputData.loanAmount;
// convert to monthly rate
rate DECIMAL(10, 8) = (1 + inputData.interestRate / 1200);
// convert to months
term INT = (inputData.term * 12);
// calculate monthly payment amount
pmt MONEY = (amt * (rate - 1) * Mathlib.pow(rate, term)) /
(MathLib.pow(rate, term) - 1);
totalInterest MONEY = (pmt * term) - amt;
// update result record
inputData.monthlyPayment = pmt;
inputData.interest = totalInterest;
end
When you paste code from these instructions,
the formatting might change. Press Ctrl+Shift+F to reformat the code.
You can change the formatting rules by clicking .
Because you have not yet defined a type named MortgageCalculationResult, EGL cannot create the inputData variable based on that type. When you create this Record type in the next exercise, EGL will remove the error markers from the display.
To create the Record part:
record MortgageCalculationResult
// user input
loanAmount MONEY;
interestRate DECIMAL(10,8);
term INT;
// calculated fields
monthlyPayment MONEY;
interest MONEY;
end

In the next lesson, you create the user interface for the first application portlet.