Application Development and Automation Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

Mathematical Functionsu00A0

Former Member
0 Likes
1,047

hai all...

can any one give me clear explanation of all the mathematical functions of numeric data types with an example.i.e for all the following

ABS

SIGN

CEIL

FLOOR

TRUNC

Will be rewarded if helpful

Thanks and Regards,

Jhansi

1 ACCEPTED SOLUTION
Read only

Former Member
1,009
REPORT demo_data_function .

* 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.

<b>

Output:

Mathematical Functions </b>

ABS: 5.55

SIGN: 1.00-

CEIL: 5.00-

FLOOR: 6.00-

TRUNC: 5.00-

FRAC: 0.55-

-1.0000000000000000E+00

Reward points. This is the code from ABAPDOCU.

9 REPLIES 9
Read only

Former Member
1,010
REPORT demo_data_function .

* 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.

<b>

Output:

Mathematical Functions </b>

ABS: 5.55

SIGN: 1.00-

CEIL: 5.00-

FLOOR: 6.00-

TRUNC: 5.00-

FRAC: 0.55-

-1.0000000000000000E+00

Reward points. This is the code from ABAPDOCU.

Read only

0 Likes
1,009

hai

judith.....

thank you very much for the reply,can u please tell me what is the ceil and floor of '-5'

Read only

0 Likes
1,009

<b>CEIL: 5.00-

FLOOR: 5.00-</b>

U can try this in ur program.

reward poinst and clso ethe thread if this solves.

Read only

Former Member
0 Likes
1,009

Hope the above code solve ur problem

Read only

Former Member
0 Likes
1,009

Jhansikiran,

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.

Pls. Mark if useful.

Read only

Former Member
0 Likes
1,009

ABS: Return the absolute value of a number

ABS(-1) = 1

ABS(2) = 2

SIGN: Returns the sign of a number

SIGN(-10) = -1

SIGN(100) = 1

CEIL: Returns the next highest integer

CEIL(2.5) = 3

CEIL(3.1) = 4

FLOOR: Returns the immediately lowest integer

FLOOR(8.5) = 8

FLOOR(8.9) = 8

TRUNC: Returns the integer portion of the number

TRUNC(6.3) = 6

Read only

Former Member
0 Likes
1,009

Hi Jhansi,

<b>abs - Absolute value of argument.

sign - Prefix of the 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.</b>

<b>Report zex33.

DATA n TYPE p DECIMALS 2.

DATA m TYPE p DECIMALS 2 VALUE '-8.68'.

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: 8.68

SIGN: 1.00-

CEIL: 8.00-

FLOOR: 9.00-

TRUNC: 8.00-

FRAC: 0.68-

</b>

Read only

Former Member
Read only

Former Member
0 Likes
1,009

hi,

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-

regards