If you have a need to evaluate dynamic calculations in RPG, you can use embedded SQL to make this easier. The example source below provides two sub-procedures; Calculate and SubValue, that can be used to replace variables within a formula with their values and to perform the actual calculation.