Application Development 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: 

REDUCE a decilmal value

marcelom_bovo
Participant
0 Kudos

Hi People.

I'm trying to use REDUCE to sum some decimal fields of a internal table but the result is being automatically rounded up.


SELECT matnr, werks, charg, clabs, cinsm, cspem

       FROM mchb

       INTO TABLE @DATA(lt_mchb)

      WHERE matnr = variable0

        AND werks = variable

        AND charg = variabl2


DATA(lv_saldo) = REDUCE LABST( INIT x = 0 FOR wa IN lt_mchb NEXT x = x + wa-clabs + wa-cinsm + wa-cspem  ).

The result should be 11.657 but LV_SALDO is receiving 12.000

What am I doing wrong?

thanks

1 ACCEPTED SOLUTION

Former Member

Hi,

Try this: INIT x = '0.000'

The declarations after INIT will create the variable as the value passed.

DATA(lv_saldo) = REDUCE labst( INIT x = '0.000' FOR wa IN lt_mchb NEXT x = x + wa-clabs + wa-cinsm + wa-cspem  ).

Douglas

9 REPLIES 9

Former Member
0 Kudos

You are working on N/W release 7.4 or greater to which I do not have access too but if your definition of  lv_saldo is an integer, the results will always be rounded.

If you want to avoid this, then you should change the definition to either F or P.

Thanks,

Vikram.M

0 Kudos

Hi, the variable is being created with type LABST which has 3 decimals

tks

horst_keller
Product and Topic Expert
Product and Topic Expert
0 Kudos

Hi,

Check your data type LABST. It must have decimals. Replace it with such a type and it should work.

Horst

0 Kudos

LABST already has three decimals

Former Member

Hi,

Try this: INIT x = '0.000'

The declarations after INIT will create the variable as the value passed.

DATA(lv_saldo) = REDUCE labst( INIT x = '0.000' FOR wa IN lt_mchb NEXT x = x + wa-clabs + wa-cinsm + wa-cspem  ).

Douglas

0 Kudos

Thanks Douglas, it worked

Actually I had to put an extra zero '0.0000' because with just three zeroes after the decimal point the result was getting wrong "10,710" instead of "10,712"...weird

The values that are being summed are 2.312 + 4 + 4.4

horst_keller
Product and Topic Expert
Product and Topic Expert

You are working with a type c field now. Use the init with type addition to get a numeric type .

Hi Horst.

Now its better

DATA(lv_saldo) = REDUCE LABST( INIT x TYPE LABST FOR wa IN lt_mchb NEXT x = x + wa-clabs + wa-cinsm + wa-cspem  ).

thanks

Thanks marcelom.bovo for the answer, it helped me today while I was struggling with the rounding up an amount field.