ABAP Tutorial for Beginner – Previously you have learned how to declare variables and assign them initial value, in this article we will learn how to do calculation in ABAP and it cover some basic math functions in ABAP Programming.
Arithmetic Operations in SAP ABAP
The value on the right-hand side of the equation can be a number or an arithmetic calculation. Let’s see following lists of ABAP arithmetic operation.
|DIV||Division with no remainder|
|**||Raise to the power of the right-hand number|
Order of Operations Arithmetic in ABAP
When using arithmetic operations, the order of operations is applied, Order of operations meaning that calculations in parenthesis are completed first, followed by exponents, multiplication, addition, and lastly, subtraction, this rule is the same with other programming language.
As a result, if you look at the two examples below, the first result will be 600, while the second result will be 303. This is because the operations within the parenthesis were completed first. Don’t forget to assign the result to an appropriate variable.
DATA : lv_result TYPE decfloat16 .
lv_result ( 3 + 3 ) * ( 10 * 10 ) .
1v_resu1t = 3 + 3 * 10 * 10 .
Note : You must enter space after parenthesis and between each arithmetic operation, you can see example before.
Math Functions in ABAP Programming
In addition to the basic math operations, ABAP provides other numerical functions to make your life easy when working with numbers. The syntax is function( argument) when using math functions.
This following list of ABAP Math Functions.
|abs||Returns the absolute value of the argument|
|sign||Returns the sign of the argument|
|ceil||Returns the argument rounded to the next highest number|
|floor||Returns the argument rounded to the next lowest number|
|trunc||Returns only the integer, dropping any decimal values|
|frac||Returns only the decimal values of the argument|
|ipow||Takes two arguments and raises the base argument to the
power of the expression
For Example :
We can use abs function which will return absolute return value.
abs( -10 ).
Will return value : 10
Other math function and arithmetic operation you can try yourself on your ABAP Workbench.
Incoming search terms:
- can we do arithmatic operations while selecting from databse abap
- direct numbers math operation tutrial
- arithmetic opertaion in sap abap
- abap arithmetic calculations
- sap mathematic operations
- sap math function min
- division operation in abap
- arithmetic operations in abap
- arithmetic operations ABAP
- abap math to find remainer