为什么在使用降低操作员时,为什么ABAP将一个数字圆向最近的整数?

发布于 2025-01-24 20:37:58 字数 550 浏览 2 评论 0原文

在下面的代码中,lv_sum_openamount应为3.45,但该程序将数字恰当地为3。

我想要lv_sum_sum_openamount AS 3。

我该怎么做?

DATA(lv_sum_openamount) = REDUCE dmbtr_cs( INIT sum = 0 FOR wa_amnt IN <fs_comp> NEXT sum += wa_amnt-open_amount.

LOOP AT <fs_comp> ASSIGNING <fs_comp_alv>.
  TRY.
    <fs_comp_alv>-pull_amount = ( <fs_pack>-reamount / lv_sum_openamount ) * <fs_comp_alv>-open_amount.
  CATCH cx_sy_zerodivide.
    <fs_comp_alv>-pull_amount = 0.
  ENDTRY.
ENDLOOP.

In the code below, lv_sum_openamount should be 3.45 but the program rounds the number as 3.

I want lv_sum_openamount as 3.

How can I do that ?

DATA(lv_sum_openamount) = REDUCE dmbtr_cs( INIT sum = 0 FOR wa_amnt IN <fs_comp> NEXT sum += wa_amnt-open_amount.

LOOP AT <fs_comp> ASSIGNING <fs_comp_alv>.
  TRY.
    <fs_comp_alv>-pull_amount = ( <fs_pack>-reamount / lv_sum_openamount ) * <fs_comp_alv>-open_amount.
  CATCH cx_sy_zerodivide.
    <fs_comp_alv>-pull_amount = 0.
  ENDTRY.
ENDLOOP.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

梦罢 2025-01-31 20:37:58

罪魁祸首是零件init sum = 0

0是一个整数,因此sum的类型会自动派生为整数。这意味着降低 -loop然后使用整数算术,因此其输出被舍入。

尝试init sum = Conv Dmbtr_cs(0)而不是。这将将0的文字转换为您需要的类型,进而将强制sum也转换为获得该类型。

The culprit is the part INIT sum = 0.

0 is an integer, so the type for sum gets automatically derived as an integer. That means that the REDUCE-loop then uses integer arithmetic, so its output is rounded down.

Try INIT sum = CONV dmbtr_cs( 0 ) instead. This will convert the literal of 0 to the type you need and in turn force sum to also get that type.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文