2016 Aug 17 3:36 PM
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
2016 Aug 17 5:06 PM
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
2016 Aug 17 4:13 PM
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
2016 Aug 17 5:33 PM
Hi, the variable is being created with type LABST which has 3 decimals
tks
2016 Aug 17 4:44 PM
Hi,
Check your data type LABST. It must have decimals. Replace it with such a type and it should work.
Horst
2016 Aug 17 6:10 PM
2016 Aug 17 5:06 PM
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
2016 Aug 17 5:41 PM
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
2016 Aug 17 5:59 PM
You are working with a type c field now. Use the init with type addition to get a numeric type .
2016 Aug 17 6:08 PM
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
2022 Oct 11 3:30 PM
Thanks marcelom.bovo for the answer, it helped me today while I was struggling with the rounding up an amount field.
2025 Mar 11 3:45 AM
Great, I also faced similar issue. Adding extra 0 worked. So '0.0000' is perfect. Thanks