REDUCE 运算符中的小数位数精度 [英] Decimal places accuracy in REDUCE operator

查看:31
本文介绍了REDUCE 运算符中的小数位数精度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我下面的代码中,我将 sumlt_req-dmbtr 声明为 dmbtr,但在输出中它没有显示十进制值并且输出也比预期的少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 ) ).

有时会出现错误

<块引用>

CX_SY_ARITHMETIC_OVERFLOW

解决方案

sum 变量类型在这里是限定性的,而不是您转换的 wa-dmbtr.>

摘自 REDUCE 帮助:><块引用>

INIT 之后的声明创建局部变量 x1, x2...

<块引用>

完整求值后,将第一个变量x1的内容或第一个字段符号指向的内存区域赋值给类型的表达式的临时结果根据分配规则输入.

在您的代码段中,您的 sum 为零,因此它是 Integer 并且它限制了所有其他类型.

满足您要求的正确形式的 REDUCE:

类型:开始 ty_product,产品类型 char10,价格类型 dmbtr,组类型 char10,ty_product 结束,tt_products 带有空密钥的 ty_product 类型标准表.数据(t_prod)=VALUE tt_products((产品 = 'C0001' 价格 = '1.005' 组 = '商品')(产品 = 'C0002' 价格 = '245.48575' 组 = '原油')(产品 = 'C0003' 价格 = '500.05' 组 = '原油')(产品 = 'C0004' 价格 = '32' 组 = '商品')).DATA(total) = REDUCE dmbtr( INIT sum = CONV dmbtr( 0 ) FOR wa IN t_prod WHERE ( group = 'crude' ) NEXT sum = sum + wa-price ).写总数.

结果是 745.53575.

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

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

解决方案

The sum variable type is qualificative here, not the wa-dmbtr you convert from.

Excerpt from REDUCE help:

The declarations after INIT create local variables 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.

And in your snippet your sum is zero, so it is Integer and it limits all other types.

The correct form of REDUCE to achieve your requirement:

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.

这篇关于REDUCE 运算符中的小数位数精度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆