4

我需要按 NUMC 列的总和对表进行分组,不幸的是,ABAP/OpenSQL 似乎无法做到这一点。

我的代码如下所示:

    SELECT z~anln1
    FROM zzanla AS z
    INTO TABLE gt_
    GROUP BY z~anln1 z~anln2
    HAVING SUM( z~percent ) <> 100  " percent unfortunately is a NUMC -> summing up not possible

由于我无法更改表格本身,这里最好/最简单的做法是什么?

4

4 回答 4

3

Unfortunately the NUMC type is described as numerical text, so at the end it lands in the database as VARCHAR and that is why the functions like SUM or AVG cannot be used.

It all depends on how big your table is. If it is rather small you could get the group fields and the values for sum into an internal table and then sum it using COLLECT statement and eventually remove the rows for which the sum is equal 100%.

于 2015-03-17T13:02:34.410 回答
1

一种解决方案是使用更合适的类型定义表中的字段。

NUMC 通常用于关键字段 - 例如文档编号,永远没有理由将它们加在一起。

于 2015-05-31T03:16:18.153 回答
0

我没有找到一个顺利的解决方案。我所做的是复制内部表中的所有内容,循环将 NUMC 值转换为 DEC 值。在那一点上,分组和总结起作用了。最后,我将 DEC 值转换回 NUMC 值。

于 2015-05-27T07:46:21.853 回答
0

有一阵子了。我回到这篇文章,因为有人投票赞成我原来的答案。我正在考虑编辑我的旧答案,但我决定发布一个新答案。正如 2017 年提出的这个问题,有一些限制,但现在可以通过使用CAST新 OpenSQL 中的函数来完成。

SELECT z~anln1
FROM zzanla AS z
INTO TABLE @gt_
GROUP BY z~anln1, z~anln2
HAVING SUM( CAST( z~percent AS INT4 ) ) <> 100
于 2020-10-08T15:08:08.653 回答