Mastering Basic Math Functions in ABAP with Examples
LIST OF VARIOUS MATHEMATICAL FUNCTIONS IN ABAP
ABAP FUNCTION
NAME |
DESCRIPTION |
ABS() |
This function calculates the absolute value of the
given argument. |
SIGN() |
This function calculates the sign of the given
argument. If the sign is positive it returns 1, if the sign is negative it
returns -1 otherwise it returns 0. |
CEIL() |
This function calculates the smaller integer value
of the given argument. |
FLOOR() |
This function calculates the largest integer value
of the given argument. |
TRUNC() |
This function Truncates and returns the integer part
of the given value as argument. |
FRAC() |
This function returns the fractional part of the
given value as argument. |
MOD |
This function calculates the remainder of a number
divided by another number. |
ROUND() |
This function Rounds off a number upto a given
number of decimal places. |
SIN() |
This function calculates the trigonometric ratio sine
of a given argument. |
COS() |
This function calculates the trigonometric ratio cosine
of the given argument. |
TAN() |
This function calculates the trigonometric ratio tangent
of the given argument. |
EXP() |
This function calculates the exponential value of
the given argument with the base e=2.7182818285 |
LOG() |
This function calculates the natural logarithm of a
given value as argument. |
LOG10() |
This function calculates the logarithm to the base
10 of a given argument. |
SQRT() |
This function calculates the square root of a given
value as argument. |
PROGRAM EXAMPLE IN ABAP
*&---------------------------------------------------------------------*
*& Report ZMATH
*&---------------------------------------------------------------------*
*&
*&---------------------------------------------------------------------*
REPORT ZMATH.
START-OF-SELECTION.
CONSTANTS: CO_PI TYPE F VALUE '3.14159265'.
DATA: LV_RESULT TYPE P DECIMALS 2.
WRITE: /'USING MATH FUNCTIONS IN ABAP'.
WRITE: /'----------------------------'.
LV_RESULT = ABS('-3').
WRITE: /'ABSOLUTE VALUE OF THE NUMBER', LV_RESULT.
LV_RESULT = SIGN('-3').
WRITE: /'SIGN OF A NUMBER', LV_RESULT.
LV_RESULT = CEIL('2.41').
WRITE: /'CEILING VALUE', LV_RESULT.
LV_RESULT = FLOOR('2.91').
WRITE: /'FLOOR VALUE', LV_RESULT.
LV_RESULT = TRUNC('4.7').
WRITE: /'TRUNCATE VALUE', LV_RESULT.
LV_RESULT = FRAC('4.7').
WRITE: /'FRACTIONAL VALUE', LV_RESULT.
LV_RESULT = SIN( CO_PI ).
WRITE: /'SINE VALUE OF PI', LV_RESULT.
LV_RESULT = COS( CO_PI ).
WRITE: /'COSINE VALUE OF PI', LV_RESULT.
LV_RESULT = TAN( CO_PI ).
WRITE: /'TANGENT VALUE OF PI', LV_RESULT.
LV_RESULT = 5 MOD 2.
WRITE: /'MODULUS OPERATOR', LV_RESULT.
LV_RESULT = ROUND( VAL = '5.296' DEC = 2 ).
WRITE: /'ROUNDED VALUE', LV_RESULT.
LV_RESULT = EXP('2.3026').
WRITE: /'EXPONENTIAL VALUE', LV_RESULT.
LV_RESULT = LOG('10').
WRITE: /'NATURAL LOGARITHM', LV_RESULT.
LV_RESULT = LOG10('10').
WRITE: /'LOG TO THE BASE 10', LV_RESULT.
LV_RESULT = SQRT('25').
WRITE: /'SQUARE ROOT OF A NUMBER', LV_RESULT.
Comments
Post a Comment