SAP CDS SELECT STATEMENT V2



Get Example source ABAP code based on a different SAP table
  


• { } ABAP_CDS_SELECT
• SELECT ABAP_CDS_DEF_VIEW_ENT
• DISTINCT ABAP_CDS_SELECT
• FROM ABAP_CDS_SELECT

ABAP_CDS_DDL - CDS View Entity, SELECT

ABAP_SYNTAX
SELECT $[DISTINCT$] FROM data_source
$[association1 association2 ...$]
{select_list}
$[clauses$]

What does it do?
In a CDS view entity, as part of the statement DEFINE VIEW ENTITY, a SELECT statement defines a query performed on the data sources specified in data_source. Possible data sources are DDIC database tables, CDS view entities, CDS table functions, CDS hierarchies, or ABAP_CDS_V1_VIEWS .
DISTINCT removes duplicates from the result set. If DISTINCT is specified, the elements cannot have the type LCHR, LRAW, STRING , RAWSTRING, or GEOM_EWKB. ABAP_NOTE For determining duplicate rows, all columns are considered and not just key fields.
association1, association2, ... define CDS associations for the current SELECT statement. These CDS associations can be accessed in data_source and in select_list using path expressions.
The select_list defines the components read in a list.
The optional addition clauses are SELECT clauses that enable conditions, groupings, or set operators.



Latest notes:

The syntax SELECT * to select all elements from the data source is not supported in CDS view entities. This syntax can be used in AB_SQL and in ABAP_CDS_V1_VIEWS , but not in CDS view entities.
For an overview of all possible data sources of all available CDS entities, see Data Source Matrix.
NON_V5_HINTS
ABAP_HINT_END

ABAP_EXAMPLE_VX5
The CDS view entity DEMO_CDS_BUPA_NAME shown below is based on the existing ABAP_CDS_V1_VIEW DEMO_SALES_CDS_BUPA. In the SELECT list, the element family_name is defined, assigned the alias name last_name , and given the comment Business partner last name .
DDLS DEMO_CDS_BUPA_NAME
The CDS view entity DEMO_CDS_BUPA_NAME can be addressed in ABAP programs using AB_SQL , for example: SELECT * FROM demo_cds_bupa_name INTO TABLE @itab ...
ABAP_EXAMPLE_END

ABAP_EXAMPLE_VX5
The following CDS view entity removes any duplicate values of the result set using DISTINCT.
DDLS DEMO_CDS_DISTINCT
The class CL_DEMO_CDS_DISTINCT first fills the underlying database table and then accesses the view using SELECT. One duplicate entry is removed from the result set.
The addition DISTINCT of SELECT is no longer needed in this case.
ABAP_EXAMPLE_END