01-15-2006 5:05 AM
i need to find an absolute value for a variable, how i do that
promise to reward points
regards,
anitha
01-15-2006 5:37 AM
couldnt get the question! can you eloborate little further
Regards
Raja
01-15-2006 5:42 AM
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
01-15-2006 6:01 AM
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
01-15-2006 7:38 AM
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
01-15-2006 9:32 AM
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
01-15-2006 5:15 PM
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
01-16-2006 9:54 AM
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