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

Question on BRGEW data type

Former Member
0 Likes
2,239

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



1 ACCEPTED SOLUTION
Read only

retired_member
Product and Topic Expert
Product and Topic Expert
0 Likes
2,047

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.

9 REPLIES 9
Read only

RaymondGiuseppi
Active Contributor
0 Likes
2,047

Try to use DIV and MOD operators by 1000 on 1000 times the original quanity ?

Regards,

Raymond

Read only

retired_member
Product and Topic Expert
Product and Topic Expert
0 Likes
2,048

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.

Read only

0 Likes
2,047

Could you please elaborate this line ..

num = round( val = pack dec = 0 mode cl_abap_math=>round_down ).


Sorry if its too basic.

Read only

0 Likes
2,047

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.

Read only

former_member259807
Active Participant
0 Likes
2,047

DATA n TYPE decfloat16.

DATA m TYPE decfloat16 VALUE '5.55'.

n = TRUNC( m ). WRITE: / 'TRUNC:', n.

n = FRAC( m )WRITE: / 'FRAC: ', n.

Read only

0 Likes
2,047

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

Read only

former_member196331
Active Contributor
0 Likes
2,047

Hi,

Why don't you Try.

splist resv at '.' into rs_p1 rsp2.

Read only

former_member196331
Active Contributor
0 Likes
2,047

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.

Read only

0 Likes
2,047

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