Back to: ILE RPG in Easy Bytes

Unit 5 discusses arithmetic calculations, examining how to express calculations by using free-form expressions and appropriate operation codes. It also introduces you to some of RPG’s built-in functions that facilitate going beyond the traditional addition, subtraction, multiplication, and division functions used by basic arithmetic. Additionally, you learn how to determine the correct size for fields that store the results of arithmetic operations and how to round calculations to avoid truncation.
This course is a unit of the ILE RPG in Easy Bytes series, a complete introductory ILE RPG programming self-guided tutorial.
- Before starting this course you must complete the required prerequisite course: 4. Program Workflow – ILE RPG in Easy Bytes
One-Time Payment
Members Only
Instead of paying for each unit individually, you may purchase a membership which will automatically enroll you at a discount in the entire “ILE RPG in Easy Bytes” series.
Numeric Operations and Functons
Assigning a value to a field simply means giving the field a value. Previous lessons used the Eval operation to evaluate simple assignment expressions. Eval always works together with an assignment expression, which consists of a result (target) variable, followed by the assignment operator (=), followed by an expression.
The expression for evaluation can contain the arithmetic operators + (addition), – (subtraction), * (multiplication), / (division), and ** (exponentiation, or raising a value to a power), as well as parentheses, relational symbols (e.g., <, >), logical operators (e.
These provide new functions that aren’t available by coding simple expressions. Built-in functions always begin with a percent sign (%). You typically code built-in functions within free-format expressions in the program.
+ for addition, – for subtraction, * for multiplication, / for division, and ** for exponentiation. Because the traditional Calculation format did not allow expressions, RPG programs written in the past may rely on several fixed-format operations to accomplish arithmetic: ADD DIV (Divide) MULT (Multiply) MVR (Move remainder) SQRT (Square root) SUB (Subtract) Z-ADD (Zero and add) Z-SUB (Zero and subtract) All these operation codes work only with numeric Factor 1 and Factor 2 and a numeric Result.
- Before starting this course you must complete the required prerequisite course: 4. Program Workflow – ILE RPG in Easy Bytes