2007 Mar 15 10:29 AM
Hi every one,
can any one of please help me out to resolve one issue, i have one quantity which is of like 1.25 or any value, now my requirement is i have to make this quantity to the next integer.
so for the above it should become 2.
can any one of you send me some example code to resolve this thanks in advance
2007 Mar 15 10:31 AM
Hello,
check this example...
DATA: I TYPE I,
P TYPE P DECIMALS 2,
M TYPE F VALUE '-3.5',
D TYPE P DECIMALS 1.
P = ABS( M ). " 3,5
I = P. " 4 - business rounding
I = M. " -4
I = CEIL( P ). " 4 - next largest whole number
I = CEIL( M ). " -3
I = FLOOR( P ). " 3 - next smallest whole number
I = FLOOR( M ). " -4
I = TRUNC( P ). " 3 - integer part
I = TRUNC( M ). " -3
D = FRAC( P ). " 0.5 - decimal part
D = FRAC( M ). " -0.5
REgards,
Vasanth
Hi every one,
can any one of please help me out to resolve one issue, i have one quantity which is of like 1.25 or any value, now my requirement is i have to make this quantity to the next integer.
so for the above it should become 2.
can any one of you send me some example code to resolve this thanks in advance
2007 Mar 15 10:31 AM
Hello,
check this example...
DATA: I TYPE I,
P TYPE P DECIMALS 2,
M TYPE F VALUE '-3.5',
D TYPE P DECIMALS 1.
P = ABS( M ). " 3,5
I = P. " 4 - business rounding
I = M. " -4
I = CEIL( P ). " 4 - next largest whole number
I = CEIL( M ). " -3
I = FLOOR( P ). " 3 - next smallest whole number
I = FLOOR( M ). " -4
I = TRUNC( P ). " 3 - integer part
I = TRUNC( M ). " -3
D = FRAC( P ). " 0.5 - decimal part
D = FRAC( M ). " -0.5
REgards,
Vasanth
2007 Mar 15 10:35 AM
Hi
thanks for your reply, but here iam not getting the next integer.
if i have quantity 0.2
i want to make quantity as 1
if you have any clues please find for me thanks
2007 Mar 15 10:32 AM
Hi,
Use CEIL or FLOOR mathematical functions to get the value.
Regards,
Anji
2007 Mar 15 10:34 AM
hi
pls refer:
<a href="
http://help.sap.com/saphelp_nw2004s/helpdata/en/fc/eb3316358411d1829f0000e829fbfe/content.htm
">http://help.sap.com/saphelp_nw2004s/helpdata/en/fc/eb3316358411d1829f0000e829fbfe/content.htm</a>
pavan
2007 Mar 15 10:37 AM
this is matematical functions
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.
DATA: RESULT TYPE F,
PI(10) VALUE '3.141592654'.
RESULT = COS( PI ).
WRITE RESULT.
The output is -1.00000000000000E+00 . The character field PI is automatically converted to a type F field before the calculation is performed.
2007 Mar 15 10:37 AM
HI MADHAN,
try this example
REPORT zround2.
PARAMETER: p_value type p decimals 3 default '22.123'.
DATA: d_value type p decimals 2,
d_int1 TYPE i,
d_int2 TYPE i,
d_number(20) TYPE c,
d_num_result(20) TYPE c,
d_decimal(2) TYPE c.
************************************************************************
*START-OF-SELECTION.
START-OF-SELECTION.
d_number = p_value.
SHIFT d_number LEFT UP TO '.'.
SHIFT d_number LEFT.
d_decimal = d_number+0(2).
d_decimal = d_decimal + 1.
Clear: d_number.
d_number = p_value.
SHIFT d_number RIGHT DELETING TRAILING '123456789 '.
SHIFT d_number LEFT DELETING LEADING ' '.
CONCATENATE d_number d_decimal INTO d_num_result.
d_value = d_num_result.
write:/ 'Value rounded up to 2 decimal places is ', d_value.
reward points if useful
rgds,
Prajith
2007 Mar 15 10:38 AM
hi
see this sample code:
parameters a type p decimals 2.
data b type i.
b = ceil( a ).
write b.
thx
pavan
2007 Mar 15 10:42 AM
Hi,
Look at the following code segment.
data:
pack type p decimals 2 value '1.25',
int type i,
char1(8) type c,
char2(6) type c .
char1 = pack.
split char1 at '.' into char1 char2.
if char2 GT 0.
int = pack.
add 1 to int.
endif.
Reward if helpful.
Regards,
Sandhya
2007 Mar 15 10:50 AM
Hi madhan,
Check this code i am getting your required output.
data var1 type zs_vmeng .
var1 = '0.2'.
var1 = ceil( var1 ).
write var1.
2007 Mar 15 11:00 AM
data: v_num type p decimals 2,
v_num_round type i.
v_num = '0.2'.
add 1 to v_num.
v_num_round = v_num.
Gives the rounded value
write v_num_round .
2007 Mar 15 11:11 AM
Hi,
check this it worked for me
data v_num type p decimals 2 .
v_num = '1.25' .
v_num = ceil( v_num ).
write v_num.
Regards,
Sruthi