为什么在使用降低操作员时,为什么ABAP将一个数字圆向最近的整数?
在下面的代码中,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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
更多
发布评论
评论(1)
罪魁祸首是零件
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 forsum
gets automatically derived as an integer. That means that theREDUCE
-loop then uses integer arithmetic, so its output is rounded down.Try
INIT sum = CONV dmbtr_cs( 0 )
instead. This will convert the literal of0
to the type you need and in turn forcesum
to also get that type.