2016 Jul 20 1:14 PM
Hi ,
I am using BRGEW data type for a quantity field , which has length 13 of which 3 are decimal places.
(
for suppose if the value is 3.115 say I want to get 3 ( integer part ) into one variable of type i and remaining decimal 0.115 into another variable which is of type BRGEW.
I know we can pass that 3.115 into a char type variable and split into two variable of char type and than pass them back to required type variables .
I am looking for better way than this.
I already tried trunc and frac numerical operations but the problem is the frac operations makes the value to 0 if the value is 0.114 like that is any thing less than is 0.5 is considered as 0.
Please suggest.
Thanks,
RG
2016 Jul 20 1:25 PM
Use the ROUND function with the appropriate rounding mode:
DATA pack TYPE p LENGTH 13 DECIMALS 3 VALUE '3.115'.
DATA num TYPE i.
DATA rest TYPE p LENGTH 2 DECIMALS 3.
num = round( val = pack dec = 0 mode = cl_abap_math=>round_down ).
rest = pack - num.
2016 Jul 20 1:20 PM
2016 Jul 20 1:25 PM
Use the ROUND function with the appropriate rounding mode:
DATA pack TYPE p LENGTH 13 DECIMALS 3 VALUE '3.115'.
DATA num TYPE i.
DATA rest TYPE p LENGTH 2 DECIMALS 3.
num = round( val = pack dec = 0 mode = cl_abap_math=>round_down ).
rest = pack - num.
2016 Jul 20 2:23 PM
Could you please elaborate this line ..
num = round( val = pack dec = 0 mode = cl_abap_math=>round_down ).
Sorry if its too basic.
2016 Jul 20 2:33 PM
Hi, pls. follow the link to the documentation of the built-in function ROUND ...
If you copy the above code You'll see that it works.
2016 Jul 20 1:28 PM
DATA n TYPE decfloat16.
DATA m TYPE decfloat16 VALUE '5.55'.
n = TRUNC( m ). WRITE: / 'TRUNC:', n.
n = FRAC( m ). WRITE: / 'FRAC: ', n.
2016 Jul 20 2:19 PM
Hi,
Thanks for ur reply , I already tried this option but the problem is when the fraction part decimal places is less than 0.5 it is truncated to 0 . try it normally.
Thanks,
RG
2016 Jul 20 1:28 PM
2016 Jul 20 1:30 PM
As per the Expert suggestions.
DATA : wa_dec TYPE p DECIMALS 3 VALUE '11111111.011',
wa_p1 TYPE string,
wa_p2 TYPE string,
wa_dec1(20),
len TYPE i.
wa_dec1 = wa_dec.
BREAK-POINT.
SPLIT wa_dec1 AT '.' INTO wa_p1
wa_p2.
CONDENSE wa_p1.
len = STRLEN( wa_p1 ).
" len = number of characters before decimal
if len > 11.
" do ur work here
endif.
BREAK-POINT.
2016 Jul 20 2:20 PM
Hello,
I already know this method as mentioned , I want a better approach for getting the integer and decimal part of a variable.
Thanks,
RG