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.

OperationsDescription
+Addition
-Subtraction
*Multiply
/Division
DIVDivision with no remainder
MODModulus
**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.

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.

FunctionDescription
absReturns the absolute value of the argument
signReturns the sign of the argument
ceilReturns the argument rounded to the next highest number
floorReturns the argument rounded to the next lowest number
truncReturns only the integer, dropping any decimal values
fracReturns only the decimal values of the argument
ipowTakes 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.

Other math function and arithmetic operation you can try yourself on your ABAP Workbench.

Leave a Reply

Your email address will not be published. Required fields are marked *