Skip to Content Former Member

### Math Functions in SAP

What are the math functions in SAP?

##### Add comment
10|10000 characters needed characters exceeded

### 3 Answers

• Best Answer Former Member
Feb 07, 2008 at 09:57 AM

Hi,

This is what u want may be

Mathematical Functions

ABAP contains a range of built-in functions that you can use as mathematical expressions, or as part of a mathematical expression:

[COMPUTE] <n> = <func>( <m> ).

The blanks between the parentheses and the argument <m> are obligatory. The result of calling the function <func> with the argument <m> is assigned to <n>.

Functions for all Numeric Data Types

The following built-in functions work with all three numeric data types (F, I, and P) as arguments.

Functions for all numeric data types

Function

Result

ABS

Absolute value of argument.

SIGN

Sign of argument: 1 X > 0

SIGN( X) = 0 if X = 0

-1 X < 0

CEIL

Smallest integer value not smaller than the argument.

FLOOR

Largest integer value not larger than the argument.

TRUNC

Integer part of argument.

FRAC

Fraction part of argument.

The argument of these functions does not have to be a numeric data type. If you choose another type, it is converted to a numeric type. For performance reasons, however, you should use the correct type whenever possible. The functions itself do not have a data type of their own. They do not change the numerical precision of a numerical operation.

DATA N TYPE P DECIMALS 2.

DATA M TYPE P DECIMALS 2 VALUE '-5.55'.

N = ABS( M ). WRITE: 'ABS: ', N.

N = SIGN( M ). WRITE: / 'SIGN: ', N.

N = CEIL( M ). WRITE: / 'CEIL: ', N.

N = FLOOR( M ). WRITE: / 'FLOOR:', N.

N = TRUNC( M ). WRITE: / 'TRUNC:', N.

N = FRAC( M ). WRITE: / 'FRAC: ', N.

The output appears as follows:

ABS: 5.55

SIGN: 1.00-

CEIL: 5.00-

FLOOR: 6.00-

TRUNC: 5.00-

FRAC: 0.55-

DATA: T1(10),

T2(10) VALUE '-100'.

T1 = ABS( T2 ).

WRITE T1.

This produces the following output:

100

Two conversions are performed. First, the contents of field T2 (type C) are converted to type P. Then the system processes the ABS function using the results of the conversion. Then, during the assignment to the type C field T1, the result of the function is converted back to type C.

Floating-Point Functions

The following built-in functions work with floating point numbers (data type F) as an argument.

Functions for floating point data types

Function

Meaning

ACOS, ASIN, ATAN; COS, SIN, TAN

Trigonometric functions.

COSH, SINH, TANH

Hyperbolic functions.

EXP

Exponential function with base e (e=2.7182818285).

LOG

Natural logarithm with base e.

LOG10

Logarithm with base 10.

SQRT

Square root.

For all functions, the normal mathematical constraints apply (for example, square root is only possible for positive numbers). If you fail to observe them, a runtime error occurs.

The argument of these functions does not have to be a floating point field. If you choose another type, it is converted to type F. The functions themselves have the data type F. This can change the numerical precision of a numerical operation.

Regards

##### Add comment
10|10000 characters needed characters exceeded
• Former Member
Feb 07, 2008 at 09:56 AM

Following maths functionas are there in SAP:

abs -Absolute value of the argument arg

sign- Plus/minus sign of the argument arg: -1, if the value of arg is negative; 0 if the value of arg is 0; 1 if the value of arg is positive.

ceil -Smallest integer number that is not smaller than the value of the argument arg.

floor- Largest integer number that is not larger than the value of the argument arg.

trunc- Value of the integer part of the argument arg

frac- Value of the decimal places of the argument arg

acos -Arcuscosinus [-1,1]

asin- Arcussinus [-1,1]

atan- Arcustangens

cos- Cosinus

sin- Sinus

tan- Tangens

cosh- Hyperbelcosinus

sinh -Hyperbelsinus

tanh -Hyperbeltangens

exp -Exponential function for basis e [-709, 710]

log -Natural logarithm > 0

log10 -Logarithm for basis 10 > 0

sqrt -Square root

##### Add comment
10|10000 characters needed characters exceeded
• Former Member
Feb 07, 2008 at 09:58 AM

check this example from abapdocu

```
* numeric datatypes

DATA n TYPE p DECIMALS 2.
DATA m TYPE p DECIMALS 2 VALUE '-5.55'.

n = abs( m ).   WRITE:   'ABS:  ', n.
n = sign( m ).  WRITE: / 'SIGN: ', n.
n = ceil( m ).  WRITE: / 'CEIL: ', n.
n = floor( m ). WRITE: / 'FLOOR:', n.
n = trunc( m ). WRITE: / 'TRUNC:', n.
n = frac( m ).  WRITE: / 'FRAC: ', n.

ULINE.

* floating points

DATA: result TYPE f,
pi(10) TYPE c VALUE '3.14159265'.

result = cos( pi ).

WRITE result.
```

##### Add comment
10|10000 characters needed characters exceeded