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

ABAP Code Split at the decimal

Former Member
0 Likes
3,916

Dear experts,

I have a small requirement where in I need to split the qty at the decimal place and use the non decimal value as a character field.

Eg: WA_ITAB-LFIMG = 12.000

I want only 12 into one variable which has only capacity of 4 characters (Lfimg has 1313 characters).

I tried the following code, but it did not work.

I was able to successfully split the value and pass it onto the corresponsing entries but unable to pass the value into a variable of 4 characters,

Can some one please help me in this.

It_itab has lfimg

data : var(17) type c,

qty(13) type c,

qty_dec(3) type c,

val(4) type c.

constants : ca(1) type c value '.'.

read table it_itab into wa_itab index 1.

var = wa_itab-lfimg.

split var at ca into qty qty_dec. " This worked

val = qty. " This did not work

Thanks

-Amit

1 ACCEPTED SOLUTION
Read only

Clemenss
Active Contributor
0 Likes
1,507

Hi Amit,

use TRUNC function:

data : 
  qty_dec(3) type c,
  val(4) type c.

val = trunc( WA_ITAB-LFIMG ).
qty_dec = ( WA_ITAB-LFIMG - trunc( WA_ITAB-LFIMG ) ) * 1000.

Regards,

Clemens

2 REPLIES 2
Read only

ThomasZloch
Active Contributor
0 Likes
1,507

Debug your code and explain more clearly what did not work.

I suspect var and also qty are filled right bound with leading spaces, so your last statement moves only 4 spaces to val.

Thomas

Read only

Clemenss
Active Contributor
0 Likes
1,508

Hi Amit,

use TRUNC function:

data : 
  qty_dec(3) type c,
  val(4) type c.

val = trunc( WA_ITAB-LFIMG ).
qty_dec = ( WA_ITAB-LFIMG - trunc( WA_ITAB-LFIMG ) ) * 1000.

Regards,

Clemens