Application Development 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: 

what is an absolute value

Former Member
0 Kudos

i need to find an absolute value for a variable, how i do that

promise to reward points

regards,

anitha

7 REPLIES 7

athavanraja
Active Contributor
0 Kudos

couldnt get the question! can you eloborate little further

Regards

Raja

0 Kudos

i need find an absolute value. i am calculating a revenue.

The calulated revenue must be absolute, absolute means what does that mean?, is it positive value. Is there any function like abs(x).

regards,

anitha

0 Kudos

to check whether its a positive value you cando the following

if varA is GE 0 .

  • then varA is a positive value

endif .

is this what you want?

Regards

Raja

0 Kudos

Hi Anitha,

the ABS-function is available in ABAP:


DATA: lv_value    TYPE i,
      lv_abs      TYPE i.

lv_value = -5.
lv_abs   = ABS( lv_value ).

WRITE: /1 lv_value, lv_abs..

Regards,

Stefan

0 Kudos

Hi

In ABAP the absolute value has the mathematical mean:

every number has two components: the modulus (number value) and the sign.

The absolute value is mathimatical operation to get out the modulus of the number, so his value. The mathematical expression is the fallowing:

ABSOLUTE VALUE = |NUMBER|

In ABAP:

DATA: ABSOLUTE_VALUE TYPE I,

NUMBER TYPE I.

ABSOLUTE_VALUE = ABS( NUMBER ).

This is an example if your number is an integer, but you can use decimal number if you need. If you wan to know the sign of your number, the statament is SIGN.

The result of SIGN is:

-1 if NUMBER < 0,

0 if NUMBER = 0

+1 if NUMBER > 0.

PARAMETERS NUMBER TYPE P DECIMALS 2.

DATA: ABSOLUTE_VALUE TYPE P DECIMALS 2,

SIGN_VALUE TYPE I.

ABSOLUTE_VALUE = ABS( NUMBER ).

SIGN_VALUE = SIGN( NUMBER ).

WRITE: 'Number :', NUMBER,

/ 'Modulus:', ABSOLUTE_VALUE,

/ 'Sign :', SIGN_VALUE.

Max

Former Member
0 Kudos

Hi Anitha,

Any numeric value, when excluded its sign is a absolute value.

foe eg:

1.when numeric value is -2500.75, then its absolute value is 2500.75

2. When numeric value 845.25, then its absolute value is 845.25

in ABAP, <b>result = ABS( source-value ).</b>

Hope its clear...

Regards,

Raj

Former Member
0 Kudos

Hi Anitha,

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

<b>

Functions for all numeric data types</b>

<b>ABS</b>

Absolute value of argument.

<b>SIGN</b>

Sign of argument:

SIGN( X) = 1 if X > 0

= 0 if X = 0

= -1 if X < 0

<b>CEIL</b>

Smallest integer value not smaller than the argument.

<b>FLOOR</b>

Largest integer value not larger than the argument.

<b>TRUNC</b>

Integer part of argument.

<b>FRAC</b>

Fraction part of argument.

<b>Example :</b>

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-

For further info on numerical operations see the below link.

http://help.sap.com/saphelp_nw04s/helpdata/en/fc/eb3316358411d1829f0000e829fbfe/frameset.htm

Dont forget to reward pts, if it helps ;>)

Regards,

Rakesh.

Message was edited by: Rakesh