Saturday, December 5, 2020

CDS View : Explicit Name List use in CDS

 

ABAP CDS - DEFINE VIEW, name_list 

  • An explicit name list can be used, for example, to define the element names of a CDS view that defines a union set of multiple SELECT statements using UNION.
  • A CDS view with an explicit name list cannot be expanded using EXTEND VIEW.

Example

 

Syntax

... ( name1, name2, ... ) ...

Defines the element names of a CDS view in a name list. The specified names name1, name2, ... are assigned to the elements defined explicitly in the SELECT list of the SELECT statement in the order given. The names work like the alternative names defined in the SELECT list using AS and overwrite these names. If a name list is specified, it must contain a name for each element of the view.

The view field is created under the element name in the CDS database view

 

Example

Defines the names of the three elements of the CDS view employee_sales_figures as financial_year, employee_id, and gross_amount.

@AbapCatalog.sqlViewName: 'SALES_FIG_VW'
view employee_sales_figures
  (financial_year, employee_id, gross_amount) as
   select from sales_2011_tab
          { key '2011' as year,
            key id,
            amount }
   union
     select from sales_2012_tab
            { '2012' as year,
              employee_number,
              gross_amount }