简体   繁体   English

REDUCE 运算符中的小数位精度

[英]Decimal places accuracy in REDUCE operator

In my below code, I declared sum and lt_req-dmbtr as dmbtr , but in the output it is not showing the decimal values and output is also less than 2 or 3 signs than the expected在下面的代码中,我将sumlt_req-dmbtrdmbtr ,但在 output 中,它没有显示十进制值,并且 output 也比预期的少 2 或 3 个符号

DATA(total) = REDUCE dmbtr( INIT sum = 0  FOR wa IN lt_req WHERE ( gsber = <fs_ba_det>-gsber AND gjahr = 2020 ) NEXT sum = sum + conv dmbtr( wa-dmbtr )   ).

Sometimes it is thworing the error有时它会引发错误

CX_SY_ARITHMETIC_OVERFLOW CX_SY_ARITHMETIC_OVERFLOW

The sum variable type is qualificative here, not the wa-dmbtr you convert from. sum变量类型在这里是限定的,而不是您转换的wa-dmbtr

Excerpt from REDUCE help:摘自REDUCE帮助:

The declarations after INIT create local variables x1, x2... INIT 之后的声明创建局部变量 x1, x2...

After the full evaluation, the content of the first variable x1 or the memory area pointed to by the first field symbol is assigned to the temporary result of the expression of type type in accordance with the assignment rules .完全求值后,按照赋值规则将第一个变量x1或第一个字段符号指向的memory区域的内容赋值给type类型表达式的临时结果。

And in your snippet your sum is zero, so it is Integer and it limits all other types.在您的代码段中,您的sum为零,因此它是 Integer 并且它限制了所有其他类型。

The correct form of REDUCE to achieve your requirement:满足您要求的REDUCE的正确形式:

TYPES:
  BEGIN OF ty_product,
    product TYPE char10,
    price   TYPE dmbtr,
    group   TYPE char10,
  END OF ty_product,
  tt_products TYPE STANDARD TABLE OF ty_product WITH EMPTY KEY.

DATA(t_prod) =
  VALUE tt_products(
    ( product = 'C0001' price = '1.005'     group = 'commodities' )
    ( product = 'C0002' price = '245.48575' group = 'crude' )
    ( product = 'C0003' price = '500.05'    group = 'crude' )
    ( product = 'C0004' price = '32'        group = 'commodities' )
  ).

DATA(total) = REDUCE dmbtr( INIT sum = CONV dmbtr( 0 ) FOR wa IN t_prod WHERE ( group = 'crude' ) NEXT sum = sum + wa-price ).

WRITE total.

That will give 745.53575 as a result.结果将给出745.53575

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM