Skip to Content

REDUCE a decilmal value

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

Add a comment
10|10000 characters needed characters exceeded

Assigned Tags

Related questions

3 Answers

  • Best Answer
    author's profile photo Former Member
    Former Member
    Posted on Aug 17, 2016 at 04: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

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Aug 17, 2016 at 03: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

    Add a comment
    10|10000 characters needed characters exceeded

  • Posted on Aug 17, 2016 at 03:44 PM

    Hi,

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

    Horst

    Add a comment
    10|10000 characters needed characters exceeded

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.