If I remember my math classes correctly, this sort of thing requires logarithms. With the ** operator, there is no problem! Use the ** operator in extended factor 2 or free-form calculations to specify exponentiation. The compiler generates code that uses floating-point arithmetic to perform the math. The result is then converted to decimal and moved into the specified answer or work field. If the definition of the answer field is too small to contain the result, the system compiler issues a floating point conversion exception, rather than passing a partial or invalid value.
To demonstrate the power of this capability, I've provided examples below to show how to code the computation of a future value. Financial math books include the formulas that I used in coding these examples.
First, let's compute the future value of a sum of money placed in an investment (like a savings account or certificate of deposit). After the initial investment, no additional money is added. Knowing the interest rate and the number of time periods, we can determine the future value.
If we let i equal the annual interest rate divided by 12, and n equal the total number of months between now and the future date, the formula is as follows:
Future Value (Single amount) = Present Value * ( (1 + i) ^ n )
The caret symbol (^) means "raised to the power of."
A single RPG IV calculation can perform this math:
Next, let's compute the future value of a sum of money that has periodic payments only.
Using the i and n as before, the formula is as follows:
Future Value (Annuity) = Periodic payment * ( ( (1+i) ^ n - 1) / i)
An RPG calculation can perform this math as well:
In the Eval's above, the operation extenders h (half adjust) and r (precision) were used to handle accuracy and precision issues.
To get a combination of both a single amount invested over a period of time and the future value of an annuity, simply run both lines of the above code and then add them together.
A real life application: If you place $5,000 in an investment account earning 5% annual interest and also put $100 per month into this account, how much money would be in the account after 10 years?
The $5000 grows to $8235.05 in 10 years, and the $100 per month grows to $15,528.23, so the answer is the sum of these two: $23,763.28.
Exponentiation in RPG IV is a powerful tool that we can use to make our application programming jobs easier.
Jim Martin is corporate technical instructor at Jack Henry & Associates in Monett, Missouri. He is a veteran of RPG programming, beginning in 1967 with a position at IBM as a systems engineer and later becoming a staff programmer at the Rochester systems programming lab. For eight years, he was at Lakeview Technology as an AS/400 and RPG instructor and was a speaker at various local midrange user group meetings and conferences. He can be reached by email at




Business users want new applications now. Market and regulatory pressures require faster application updates and delivery into production. Your IBM i developers may be approaching retirement, and you see no sure way to fill their positions with experienced developers. In addition, you may be caught between maintaining your existing applications and the uncertainty of moving to something new.
IT managers hoping to find new IBM i talent are discovering that the pool of experienced RPG programmers and operators or administrators with intimate knowledge of the operating system and the applications that run on it is small. This begs the question: How will you manage the platform that supports such a big part of your business? This guide offers strategies and software suggestions to help you plan IT staffing and resources and smooth the transition after your AS/400 talent retires. Read on to learn:
LATEST COMMENTS
MC Press Online