简体   繁体   English

从 CDS 获取不同键字段值的计数

[英]Get count of distinct key field values from CDS

I would like to ask if it is possible to get dynamically Count of distinct fields using ABAP.我想问一下是否可以使用 ABAP 动态获取不同字段的计数。

Key in our CDS has 9 fields which is quite a lot but it is not possible to split because of historical decisions.我们的 CDS 中的 key 有 9 个字段,数量很多,但由于历史决定,无法拆分。 What I need is code like below:我需要的是如下代码:

select count(distinct (lv_requested_elements)) from CDS_VIEW; 

or或者

select count(*) from (select distinct lv_requested_elements from CDS_VIEW);

I know that it is possible to read the select into memory and get sy-dbcnt but I want to be sure that there is no other option.我知道可以将 select 读入 memory 并获得sy-dbcnt但我想确定没有其他选择。

I assume that most simple and straightforward way is to read the smallest field into memory and then count by grouped (distinctified) rows:我假设最简单直接的方法是将最小字段读入 memory 然后按分组(区分)行计数:

DATA(fields) = ` BLART, BLDAT, BUDAT`.

DATA: lt_count TYPE TABLE OF string.
SELECT (fields(6))
  INTO TABLE @lt_count
  FROM ('BKPF')
 GROUP BY (fields).

DATA(count) = sy-dbcnt.

CTE , that was mentioned, uses the same memory read, so you'll receive no performance gain:前面提到的CTE使用相同的 memory 读取,因此您不会获得任何性能提升:

A common table expression creates a temporary tabular results set, which can be accessed during execution of the WITH statement公用表表达式创建一个临时表格结果集,可在 WITH 语句执行期间访问

If you going to count this key combination frequently, I propose to create consumption or nested CDS view which will do this on-the-fly.如果您要经常计算此组合键,我建议创建消费或嵌套 CDS 视图,它会即时执行此操作。

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

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