Beyond ABAPdesigned by@Tejoram97
Beyond ABAP / ABAP on HANA / CDS Views

CDS Views

ABAP on HANA · ABAP Development ·

Open the interactive lesson →
  1. What CDS is
  2. DDIC-based views vs CDS view entities
  3. Syntax and annotations
  4. Joins
  5. Associations
  6. Parameters and session variables
  7. Built-in functions and aggregation
  8. View on view and extensions
  9. Virtual Data Model (VDM) and analytics
  10. Access control (DCL)
  11. CDS table functions (implemented by AMDP)
  12. Virtual elements and hierarchies
  13. Consuming CDS
  14. Limits, tools and legacy notes
  15. Interview questions

CDS (Core Data Services) is how you model and read data in S/4HANA. You define views in ADT, HANA executes them (code push-down), and annotations add meaning for UI, security and analytics. This page teaches the modern CDS view entity syntax. The old DDIC-based syntax is shown only so you can recognise it.

Part 1 – What CDS is

CDS is a set of languages for semantically rich data models. It extends SQL with associations, annotations, calculated fields and typed entities.

CDS = SQL plus associations, annotations, calculated fields, parameters and typed entities

Language

What it does

Example

DDL – data definition

Defines CDS entities (views, table functions, hierarchies)

define view entity …

DCL – data control

Defines access-control roles (row-level read authorisation) – not SQL GRANT/REVOKE

define role … grant select on …

Query / expressions

Reading data, CASE, functions, path expressions

case … end, _Customer.name1

ABAP CDS vs HANA CDS

ABAP CDS (this page)

HANA CDS (legacy)

Runs in

AS ABAP, on any supported database

HANA only (XS classic, .hdbdd)

Part of DDIC / ABAP transport

Yes

No – HANA repository / delivery units

Read with

ABAP SQL

Native SQL

Status

Current – basis of S/4HANA, RAP, Fiori

Deprecated – replaced by HDI / CAP CDS on HANA Cloud

Why CDS instead of SE11 database views

Feature

CDS view entity

Classic SE11 view

Code push-down (calculations in HANA)

Yes

Limited

Joins

Inner, left/right outer, cross; UNION

Inner join only

Expressions, CASE, SQL functions

Yes

No

Parameters, session variables

Yes

No

Associations (joins on demand)

Yes

No

Annotations (UI, analytics, semantics)

Yes

No

Access control (DCL)

Yes

No

Views on views, extensions

Yes

Limited

Basis of RAP, Fiori elements, embedded analytics, VDM

Yes

No

Created in

ADT only

SE11

Data sources of a view entity: DDIC tables, other CDS view entities, DDIC-based CDS views, CDS table functions, CDS hierarchies.

Part 2 – DDIC-based views vs CDS view entities

What activation creates for a DDIC-based view and for a view entity

DDIC-based view (define view)

View entity (define view entity)

Status

Obsolete since 7.57 / S/4HANA 2022

Use this (7.55+)

Extra SE11 SQL view

Yes – needs @AbapCatalog.sqlViewName

No

Activation

Slower (two objects)

Faster

Client handling

Annotation-driven

Automatic

compareFilter / preserveKey annotations

Needed

Not needed

Buffering

@AbapCatalog.buffering…

Separate entity buffer (define view entity buffer on …)

Extension

extend view + sqlViewAppendName

extend view entity

Name list after view name

Allowed (blocks extensions)

Not allowed

  • Migration: report RUTDDLS_MIGRATION_CANDIDATES lists candidates; from 7.56 RUTDDLSV2MIGRATION migrates.
  • Activation creates an SQL view on the database – not a "HANA CDS view". The DB view is not transported; activation in QA/PRD creates it again.
  • Never select from the generated SQL view name in ABAP – obsolete since 7.57. Always use the CDS entity name.

Part 3 – Syntax and annotations

Create in ADT: New → Other ABAP Repository Object → Core Data Services → Data Definition, template "Define View Entity". Header annotations come before define; element annotations before a field.

@AccessControl.authorizationCheck: #CHECK
@EndUserText.label: 'Sales order header'
@ObjectModel.usageType: { serviceQuality: #B, sizeCategory: #L, dataClass: #TRANSACTIONAL }
define view entity ZI_SalesOrder
as select from vbak
association [0..*] to vbap as _Item
on $projection.SalesDocument = _Item.vbeln
association [0..1] to kna1 as _Customer
on $projection.SoldToParty = _Customer.kunnr
{
key vbeln                 as SalesDocument,
kunnr                 as SoldToParty,
vkorg                 as SalesOrganization,
vkgrp                 as SalesGroup,
erdat                 as CreatedOn,
ernam                 as CreatedByUser,
case vbtyp
when 'C' then 'Order'
when 'B' then 'Quotation'
when 'A' then 'Inquiry'
when 'H' then 'Returns'
else 'Others'
end                   as DocumentCategory,
@Semantics.amount.currencyCode: 'TransactionCurrency'
netwr                 as NetAmount,
waerk                 as TransactionCurrency,
_Customer.name1       as CustomerName,  // ad-hoc use of a to-one association
_Item,  // exposed association
_Customer
}
  • Rules: key fields first; alias every field in CamelCase; comments with // or /* */; no SELECT *; the client field is never listed (handled automatically).

Important annotations

Annotation

Purpose

@AbapCatalog.…

Technical settings: sqlViewName (DDIC-based only), viewEnhancementCategory, extensibility, buffering

@AccessControl.authorizationCheck

#CHECK (use DCL), #NOT_REQUIRED, #NOT_ALLOWED, #MANDATORY

@EndUserText.label / .quickInfo

Texts for the view or field (translatable)

@ObjectModel.…

Usage type, representativeKey, text.element, virtualElementCalculatedBy, data category

@Semantics.…

Meaning of a field: amount.currencyCode, quantity.unitOfMeasure, user.createdBy, businessDate.at, text

@VDM.viewType

#BASIC, #COMPOSITE, #CONSUMPTION (Part 9)

@Analytics.…

dataCategory (#DIMENSION / #FACT / #CUBE), query: true

@UI.…

Fiori elements layout: lineItem, selectionField, identification, facet – usually in a metadata extension, see RAP › 03 · Projection, UI, Access Control & Service

@Environment.systemField

Fill a parameter from a system field (Part 6)

ABAP annotations (AbapCatalog, AccessControl, ClientDependent (obsolete), ClientHandling, DataAging, EndUserText, Environment, MappingRole, Metadata, Semantics) are evaluated by the ABAP runtime. Framework annotations (Analytics, AnalyticsDetails, Consumption, DefaultAggregation, EnterpriseSearch, Hierarchy, OData, ObjectModel, Search, UI, VDM) are evaluated by SADL, OData, analytics and Fiori.

Part 4 – Joins

Join

Result

CDS syntax

Inner

Only rows with a match on both sides – no NULLs

inner join (or just join)

Left outer

All left rows; right columns NULL when no match

left outer join

Right outer

All right rows; left columns NULL when no match

right outer join

Cross

Every left row × every right row; no ON condition

cross join

UNION / UNION ALL

Rows of two selects appended (same structure)

union (view entities 7.56+)

define view entity ZI_FlightConnection
as select from spfli
inner join scarr on spfli.carrid = scarr.carrid
{
key spfli.carrid   as Airline,
key spfli.connid   as Connection,
scarr.carrname as AirlineName,
spfli.cityfrom as DepartureCity,
spfli.cityto   as ArrivalCity
}

Outer join pitfall and COALESCE

The billing example (VBRK + VBRP + MAKT) shows two classic traps:

  • A left outer join to MAKT without a language returns one row per language.
  • Putting makt.spras = $parameters.p_spras in the WHERE clause turns the outer join into an inner join: items without a text in that language vanish. Put such conditions into the join's ON condition, or use an association filter.

Final version – association with filter plus COALESCE fallback (first non-NULL value):

define view entity ZI_BillingItemText
with parameters
p_vbeln : vbeln_vf,
p_spras : spras
as select from vbrk
left outer join vbrp on vbrk.vbeln = vbrp.vbeln
association [0..*] to makt as _Text on $projection.Material = _Text.matnr
{
key vbrk.vbeln as BillingDocument,
key vbrp.posnr as BillingItem,
vbrk.erdat as CreatedOn,
vbrk.land1 as Country,
vbrp.matnr as Material,
coalesce( _Text[1: spras = $parameters.p_spras].maktx,
_Text[1: spras = 'E'].maktx )            as MaterialText
}
where vbrk.vbeln = $parameters.p_vbeln
  • [1: …] filters the association to one row. If no text exists in the requested language, the English text is returned (any language can serve as the fallback).
  • COALESCE examples: coalesce('A','B') → A; coalesce(NULL,'B') → B; all NULL → NULL.

Part 5 – Associations

An association is a join condition that is defined once and executed only when a field of the target is requested (as a LEFT OUTER JOIN by default). It makes models reusable and is the basis of RAP, OData $expand and Fiori navigation.

Join versus association in CDS

Cardinality

Classic syntax

New syntax (7.58+ / 2023)

Meaning

[0..1], [1] or none

of many to one / of exact one to one

Target has at most one row (to-one)

[1..1]

of many to exact one

Exactly one target row

[0..*], [*]

of many to many / of one to many

Zero or more target rows (to-many)

[1..*]

–

At least one target row

  • Always state the cardinality: association to sflight without it defaults to [0..1], but flights per connection are really [0..*].
  • Fields used in $projection.X must be in the element list; association names start with _ by convention.
  • For RAP parent–child trees use composition instead (see RAP › 02 · Data Model & CDS).

Exposed vs ad-hoc use

  • Exposed: list _Customer in the element list – consumers can navigate it later.
  • Ad-hoc: use a target field directly (_Customer.name1 as CustomerName) – the join is executed for this view.
  • Ad-hoc use of a to-many association (_Item.posnr) multiplies rows like a join – do it only on purpose.

Path expressions

Navigate through one or more associations, optionally with a filter: _Item[ItemCategory = 'TAN'].Material or _Customer._Address.PostalCode. In ABAP SQL a path is written with backslashes:

SELECT FROM zi_salesorder
FIELDS SalesDocument,
\_Customer-name1  AS CustomerName,
\_Item-posnr      AS Item  " to-many: one row per item
WHERE SalesOrganization = @p_vkorg
ORDER BY SalesDocument
INTO TABLE @DATA(lt_orders).
  • A path field needs an alias; with path expressions the strict syntax applies – INTO comes last, after WHERE and ORDER BY.
  • Multi-level: \_Connection\_Flight-fldate. In ADT Data Preview: right-click a row → Follow Association.
  • A path can set its own join type: _Item[inner].Material makes the association an inner join for this path (default: left outer).

Join

Association

Executed

Always

Only when a target field is used

Default type

As written

Left outer join (to-one: at most one row)

Reuse by consumers

No

Yes – consumers navigate as needed

Used by OData / RAP

No

Yes – navigation, $expand, value helps, texts

Part 6 – Parameters and session variables

A parameterised view needs input values on every read; a non-parameterised view does not. Parameters are typed with a data element or abap.<type> and read with $parameters.<name>.

@AccessControl.authorizationCheck: #NOT_REQUIRED
@EndUserText.label: 'Flight prices in a target currency'
define view entity ZI_FlightPriceConv
with parameters
p_carrid : s_carr_id,
p_curr   : abap.cuky( 5 ),
@Environment.systemField: #SYSTEM_DATE
p_date   : abap.dats
as select from sflight
{
key carrid as Airline,
key connid as Connection,
key fldate as FlightDate,
@Semantics.amount.currencyCode: 'TargetCurrency'
currency_conversion( amount             => price,
source_currency    => currency,
target_currency    => $parameters.p_curr,
exchange_rate_date => $parameters.p_date,
error_handling     => 'SET_TO_NULL' ) as PriceInTarget,
$parameters.p_curr as TargetCurrency
}
where carrid = $parameters.p_carrid
SELECT * FROM zi_flightpriceconv( p_carrid = @p_cid, p_curr = 'EUR' )
INTO TABLE @DATA(lt_flights).  " p_date omitted -> today's date is passed
  • @Environment.systemField makes a parameter effectively optional in ABAP SQL: if you omit it, the system value is passed. Values: #CLIENT, #SYSTEM_DATE, #SYSTEM_TIME, #SYSTEM_LANGUAGE, #USER.
  • Points to check in the example: no trailing comma after the last parameter, p_target_currency and p_conv_date declared, and the mandatory target_currency => argument passed.

Session variables – no parameter needed

Session variable

ABAP equivalent

$session.client

sy-mandt

$session.system_date

sy-datum

$session.system_language

sy-langu

$session.user

sy-uname

Typical use: association [0..1] to makt as _Text on $projection.Material = _Text.matnr and _Text.spras = $session.system_language.

Part 7 – Built-in functions and aggregation

CDS built-in functions in six groups, with one example each

Group

Functions

Generic

simple and searched case, coalesce

Numeric

abs, ceil, floor, div (integers), division (decimals), mod, round

String

concat, concat_with_space, substring, left, right, length, instr, lpad, rpad, ltrim, rtrim, replace, upper, lower

Conversion

cast, currency_conversion, unit_conversion, decimal_shift, hex2bin, bin2hex, fltp_to_dec

Date / time

dats_days_between, dats_add_days, dats_add_months, dats_is_valid, tstmp_current_utctimestamp, tstmp_seconds_between, tstmp_add_seconds, tstmp_is_valid

Aggregates

sum, avg, min, max, count( * ), count( distinct … ) with group by / having

define view entity ZI_SalesOrderCalc
as select from vbak
{
key vbeln                                          as SalesDocument,
substring( ernam, 1, 3 )                       as CreatorShort,
concat_with_space( vkorg, vtweg, 1 )           as SalesArea,
cast( netwr as abap.dec( 15, 2 ) )             as NetValue,
division( cast( netwr as abap.dec( 15, 2 ) ), 10, 2 ) as TenthOfValue,
dats_days_between( erdat, $session.system_date )      as AgeInDays,
case  // searched CASE
when netwr > 10000                then 'HIGH ORDER'
when netwr between 4000 and 10000 then 'MID ORDER'
else 'LOW ORDER'
end                                            as OrderSize
}
  • div needs integer arguments – for amounts use division( a, b, decimals ). CAST also solves type/length mismatches in join conditions.
  • unit_conversion( quantity => …, source_unit => …, target_unit => … ) works like currency conversion.

Aggregation

define view entity ZI_FlightRevenue
as select from sflight
{
key carrid                                     as Airline,
key connid                                     as Connection,
@Semantics.amount.currencyCode: 'Currency'
sum( price )                               as TotalPrice,
currency                                   as Currency,
count( * )                                 as NumberOfFlights
}
group by carrid, connid, currency
having sum( price ) > 10000

There is no ORDER BY in a CDS view – a view is an unordered set. The consumer sorts (ABAP SQL ORDER BY, OData $orderby, @UI.presentationVariant). A table function does not fix this either.

Part 8 – View on view and extensions

View on view

Build small reusable views and combine them, instead of one huge view. HANA optimises the stack as one statement. One table can feed many views, and one view can read many tables and views.

define view entity ZI_SalesOrderItem
as select from ZI_SalesOrder as Header
inner join vbap as Item on Header.SalesDocument = Item.vbeln
{
key Header.SalesDocument,
key Item.posnr as SalesDocumentItem,
Item.matnr as Material,
@Semantics.amount.currencyCode: 'TransactionCurrency'
Item.netwr as NetAmount,
Header.TransactionCurrency
}

Extending a view (add fields without changing it)

extend view entity ZI_SalesOrder with
{
case when vbak.netwr > 100000 then 'High impact'
else 'Fine'
end as ImpactCategory
}
  • Like an append structure for a table. Data Preview of the base view shows the new field; ADT marks the base view as extended.
  • Controlled by @AbapCatalog.viewEnhancementCategory: [#PROJECTION_LIST] (default – extendable, several extensions allowed), add #GROUP_BY / #UNION for aggregated / union views, [#NONE] (not extendable).
  • Legacy syntax: extend view … with … plus @AbapCatalog.sqlViewAppendName. A DDIC-based view with an explicit name list (define view Z (a, b, c)) could not be extended.
  • Clean core: extend only SAP views released for extension (C0 contract, @AbapCatalog.extensibility.extensible: true). See Clean Core › 01 Clean Core.

Finding SAP's CDS views

  • ADT: Ctrl+Shift+A, search type:ddls (filter on released APIs); where-used list of a table → data definitions.
  • Fiori apps View Browser and Custom CDS Views; SAP Business Accelerator Hub (api.sap.com).

Part 9 – Virtual Data Model (VDM) and analytics

The VDM is SAP's layered set of CDS views over the S/4HANA tables, ready for apps and analytics. Know the prefixes – details on Clean Core › 01 Clean Core.

VDM layers and analytical data categories

Prefix

View type

Rule

I_

Interface – basic #BASIC or composite #COMPOSITE

Public, stable, reusable. Basic views read tables; composite views combine basic views

C_

Consumption #CONSUMPTION

For one app / query; reads interface views only; exposed to UI / OData

R_

Restricted reuse

Base of SAP's transactional RAP BOs (e.g. R_SalesOrderTP)

P_

Private

SAP-internal helper – never use

Analytical model: dimension and fact views, cube, analytical query, consumers

Embedded analytics (short)

  • Analytical queries run in S/4HANA itself, no BW needed: #DIMENSION / #FACT → #CUBE → query (@Analytics.query: true, newer releases define transient view entity … provider contract analytical_query). Analytics can only use CDS views, not tables directly. In the cube, expose only the dimension fields the queries need. Generated queries are registered in table RSRREPDIR (check there if a query is missing).
  • Mark measures with @Semantics.amount… / @Aggregation.default: #SUM (older name @DefaultAggregation). Keys must identify a row uniquely – dimensions need not all be keys.
  • Tools: Fiori launchpad (/UI2/FLP), View Browser, Custom Analytical Queries, KPI Modeler, APF, Overview Page (OVP), Analytical List Page (ALP). Test: RSRT / RSRTS_ODP_DIS. Query Browser is deprecated. Users need a business role such as SAP_BR_EMPLOYEE; after assigning it in PFCG, run the user comparison.

Part 10 – Access control (DCL)

A CDS role adds a WHERE condition automatically to every ABAP SQL read of the view – row-level security without coding AUTHORITY-CHECK.

@EndUserText.label: 'Access control for ZI_SalesOrder'
@MappingRole: true
define role ZI_SalesOrder {
grant select on ZI_SalesOrder
where ( SalesOrganization ) = aspect pfcg_auth( V_VBAK_VKO, VKORG, ACTVT = '03' );
}
define role ZI_MyDrafts {
grant select on ZI_SalesOrder
where CreatedByUser ?= aspect user;  // only my own documents
}
  • The view needs @AccessControl.authorizationCheck: #CHECK.
  • aspect pfcg_auth( object, field, ACTVT = '03' ) reads the user's PFCG values. Conditions can be literal (Country = 'DE'), PFCG-based, aspect user, or combined with and / or.
  • Own authorisation object (user's steps): SU21 → authorisation class → object with field ACTVT (allow 03) plus e.g. LAND1 → maintain in PFCG roles → use it in pfcg_auth.
  • DCL is applied by ABAP SQL, RAP and OData. Native SQL / AMDP bypass it.

RAP uses the same DCL for read authorisation – see RAP › 03 · Projection, UI, Access Control & Service.

Part 11 – CDS table functions (implemented by AMDP)

When plain CDS cannot express the logic (e.g. aggregate a variable number of rows into one string), a table function gives a CDS signature whose result is computed by an AMDP function in SQLScript (7.50+).

CDS table function with AMDP implementation

Example: one row per airline with all destination cities in one field.

@EndUserText.label: 'Airlines with all destination cities'
@ClientHandling.type: #CLIENT_DEPENDENT
@ClientHandling.algorithm: #SESSION_VARIABLE
define table function ZTF_AirlineCities
returns {
client          : abap.clnt;
airline_code    : s_carr_id;
airline_name    : s_carrname;
cities_operated : abap.char( 1000 );
}
implemented by method zcl_amdp_flights=>flight_connections;
CLASS zcl_amdp_flights DEFINITION PUBLIC FINAL CREATE PUBLIC.
PUBLIC SECTION.
INTERFACES if_amdp_marker_hdb.
CLASS-METHODS flight_connections FOR TABLE FUNCTION ztf_airlinecities.
ENDCLASS.

CLASS zcl_amdp_flights IMPLEMENTATION.
METHOD flight_connections BY DATABASE FUNCTION FOR HDB LANGUAGE SQLSCRIPT
OPTIONS READ-ONLY
USING sflights.
lt_cities = SELECT DISTINCT mandt AS client, carrid, carrname, cityto
FROM sflights
WHERE mandt = SESSION_CONTEXT('CDS_CLIENT');
RETURN SELECT client,
carrid   AS airline_code,
carrname AS airline_name,
STRING_AGG( cityto, ', ' ORDER BY cityto ) AS cities_operated
FROM :lt_cities
GROUP BY client, carrid, carrname;
ENDMETHOD.
ENDCLASS.

Sample result: AA American Airlines "NEW YORK, SAN FRANCISCO"; AZ Alitalia "FRANKFURT, ROME".

  • The first returned field is the client; filter it with SESSION_CONTEXT('CDS_CLIENT') (the HANA variable behind $session.client).
  • Parameters: define table function … with parameters p_carrid : s_carr_id returns { … } – inside the AMDP read them as :p_carrid.
  • The method has no parameter list of its own (FOR TABLE FUNCTION), is static, and returns exactly one table with RETURN. AMDP rules and debugging: page 06 AMDP & SQLScript.
  • Use a table function only when a view entity cannot do it – it is HANA-only and harder to maintain.

Part 12 – Virtual elements and hierarchies

Virtual elements

A field that is not read from the DB but calculated in ABAP after the read. Evaluated only by SADL / OData / RAP – an ABAP SQL SELECT or the Data Preview returns it empty.

define view entity ZC_PurchaseOrderItem
as projection on ZI_PurchaseOrderItem
{
key PurchaseOrder,
key PurchaseOrderItem,
Material,
@ObjectModel.virtualElementCalculatedBy: 'ABAP:ZCL_PO_VIRTUAL'
virtual PoText : abap.char( 255 )
}
CLASS zcl_po_virtual DEFINITION PUBLIC FINAL CREATE PUBLIC.
PUBLIC SECTION.
INTERFACES if_sadl_exit_calc_element_read.
ENDCLASS.

CLASS zcl_po_virtual IMPLEMENTATION.
METHOD if_sadl_exit_calc_element_read~get_calculation_info.
et_requested_orig_elements = VALUE #( ( `PURCHASEORDER` ) ( `PURCHASEORDERITEM` ) ).
ENDMETHOD.

METHOD if_sadl_exit_calc_element_read~calculate.
DATA lt_items TYPE STANDARD TABLE OF zc_purchaseorderitem WITH DEFAULT KEY.
lt_items = CORRESPONDING #( it_original_data ).
LOOP AT lt_items ASSIGNING FIELD-SYMBOL(<ls_item>).
<ls_item>-PoText = |PO { <ls_item>-PurchaseOrder } item { <ls_item>-PurchaseOrderItem }|.
ENDLOOP.
ct_calculated_data = CORRESPONDING #( lt_items ).
ENDMETHOD.
ENDCLASS.
  • Interface is IF_SADL_EXIT_CALC_ELEMENT_READ; the class name needs the prefix 'ABAP:'.
  • Legacy form (DDIC-based view): @ObjectModel.virtualElement: true on cast( '' as abap.char(255) ) as PoText and @OData.publish: true to see it.

Hierarchies

Parent–child data in one table (CEO → SVP → manager → employee; company code → plant). Define a self-association child to parent ([0..1]) and a CDS hierarchy on top:

define view entity ZI_Employee
as select from zemployee
association [0..1] to ZI_Employee as _Manager
on $projection.Manager = _Manager.Employee
{
key employee_id as Employee,
manager_id  as Manager,
name        as EmployeeName,
_Manager
}

define hierarchy ZH_EmployeeHierarchy
as parent child hierarchy (
source ZI_Employee
child to parent association _Manager
start where Manager is initial
siblings order by Employee
orphans ignore
)
{
Employee,
Manager,
EmployeeName,
$node.hierarchy_level as HierarchyLevel
}

(Two DDL sources – one per entity.) Fiori tree tables and analytics use the hierarchy directly; in ABAP SQL select from it like a view.

Part 13 – Consuming CDS

ABAP SQL

SELECT FROM zi_salesorder
FIELDS SalesDocument, SoldToParty, NetAmount, TransactionCurrency
WHERE CreatedOn >= @lv_from
INTO TABLE @DATA(lt_orders).

SELECT * FROM zi_billingitemtext( p_vbeln = @lv_vbeln, p_spras = @sy-langu )
INTO TABLE @DATA(lt_items).

DCL is applied automatically; the client is handled automatically. Full ABAP SQL syntax: see the ABAP SQL page.

ALV with IDA on a CDS view

cl_salv_gui_table_ida=>create_for_cds_view( iv_cds_view_name = 'ZI_SALESORDER'
)->fullscreen( )->display( ).

" with parameters
DATA(lo_alv) = cl_salv_gui_table_ida=>create_for_cds_view( 'ZI_FLIGHTPRICECONV' ).
lo_alv->set_view_parameters( VALUE #( ( name = 'P_CARRID' value = 'AA' )
( name = 'P_CURR'   value = 'EUR' ) ) ).
lo_alv->fullscreen( )->display( ).

Only the visible rows are read from HANA. Field catalog, conditions, double-click navigation: see page 04.

Exposing CDS as OData

Technique

Status

@OData.publish: true on a DDIC-based view → service <VIEW>_CDS, register in /IWFND/MAINT_SERVICE

Legacy – read-only, not available for view entities or ABAP Cloud

SEGW project: import the generated DDIC view, or Reference Data Source on the CDS view

Legacy

RAP: define service (service definition) + service binding (OData V2/V4, UI or Web API)

Current – use this

@EndUserText.label: 'Sales order service'
define service ZUI_SALESORDER {
expose ZC_SalesOrder as SalesOrder;
expose ZI_Customer   as Customer;
}

Fiori apps read data through OData services, not from CDS views directly – so a view used by a Fiori app is always exposed through a service. Details: the OData page (CORE ABAP section) (legacy techniques, URIs, /IWFND/GW_CLIENT) and RAP › 03 · Projection, UI, Access Control & Service (service binding).

Part 14 – Limits, tools and legacy notes

What CDS cannot do

  • No imperative logic (loops, IF) and one result set per view → use a table function or AMDP.
  • No DML: a CDS view cannot insert/update/delete. With a RAP behaviour definition a CDS-based BO supports create/update/delete (legacy: BOPF).
  • No step debugger. Use Data Preview, SQL trace (ST05), "Show SQL CREATE Statement", Dependency Analyzer, and PlanViz.
  • No ORDER BY, no SELECT * in view entities, client field not in the element list.
  • DISTINCT and UNION: available in DDIC-based views for long (7.40 SP08 / 7.50); for view entities UNION came with 7.56.

Tools and transactions

Tool

Use

ADT (Eclipse)

The only editor for CDS – SE11 cannot create or change CDS

Data Preview (F8 in ADT)

Run the view, follow associations

SDDLAR

Display / check DDL sources in SAP GUI

ST05, PlanViz

See the SQL that HANA really executes

RUTDDLS_MIGRATION_CANDIDATES / RUTDDLSV2MIGRATION

Migrate DDIC-based views to view entities

Legacy – know it for interviews

  • BOPF with @ObjectModel.transactionalProcessingEnabled → replaced by RAP (RAP section).
  • HANA information models (attribute / analytic / calculation views) consumed via external views → replaced by ABAP CDS in S/4HANA development.

Part 15 – Interview questions

Q1. In which layer are CDS views created, and what happens on activation?

In the ABAP layer (ADT, DDIC). Activation creates an SQL view on the database (and for DDIC-based views also an SE11 SQL view). It is not a "HANA CDS view". Only the DDL source is transported; activation recreates the DB view in QA/PRD.

Q2. CDS view entity vs DDIC-based CDS view?

View entities (define view entity, 7.55+) have no extra SE11 view, no sqlViewName, faster activation, automatic client handling and stricter checks. DDIC-based views are obsolete; migrate with RUTDDLSV2MIGRATION.

Q3. Join vs association?

A join is always executed. An association is a reusable join condition executed only when a target field is requested (left outer join by default). Associations can be exposed for consumers, OData and RAP.

Q4. Does the database have to be HANA for CDS?

No. ABAP CDS views run on every database supported by AS ABAP (available since 7.40 SP05). Table functions (AMDP) are HANA-only.

Q5. Why use CDS when SE11 views exist?

Not just performance: expressions, outer joins and unions, parameters, associations, annotations, DCL, extensions, the VDM, and they are the foundation of RAP, Fiori elements and embedded analytics.

Q6. Can a CDS view create, update or delete data? Can you debug it?

Not by itself – CDS is read-only. With a RAP behaviour definition (or legacy BOPF) the BO supports CUD. There is no debugger; use Data Preview, ST05, the SQL CREATE statement and the dependency analyzer.

Q7. How do you implement authorisation in CDS?

@AccessControl.authorizationCheck: #CHECK plus a DCL role (define role … grant select … where … aspect pfcg_auth(…)). ABAP SQL adds the condition automatically. Native SQL / AMDP bypass DCL.

Q8. What is a CDS table function and when do you use it?

A CDS entity whose result is computed by an AMDP function (BY DATABASE FUNCTION) in SQLScript. Use it when CDS syntax cannot express the logic (e.g. STRING_AGG, procedural steps). It is HANA-only.

Q9. What are the VDM view types and S/4HANA naming conventions?

I_ interface (basic and composite – stable, reusable), C_ consumption (app-specific), R_ restricted reuse (RAP base), P_ private (never use). Data categories for analytics: #DIMENSION, #FACT, #CUBE.

Q10. How do you expose a CDS view as OData today?

With RAP: service definition (define service … expose …) and a service binding (OData V2/V4). @OData.publish: true and SEGW Reference Data Source are legacy and not available for view entities.

Q11. What is a virtual element?

A field calculated in ABAP after the DB read, via a class implementing IF_SADL_EXIT_CALC_ELEMENT_READ (@ObjectModel.virtualElementCalculatedBy: 'ABAP:ZCL_…'). Only OData / RAP evaluate it.

Q12. How do you make CDS views perform well?

Filter early (parameters, WHERE), keep joins minimal and use associations so unused joins are skipped, avoid to-many paths in field lists, CAST to matching types in join conditions, build on released I_ views, and check the plan with ST05 / PlanViz.

🏠 Start Here · ◀ 04 · ABAP SQL, ADBC & ALV IDA · 06 · AMDP & SQLScript ▶ · Sections: CORE ABAP | OOPS ABAP | ABAP on HANA | Clean Core | RAP | ABAP Points | SAP Fiori | SAPUI5 | Mobile Development (MDK) | BTP Foundations | BTP Development | CAP | SAP Build | ABAP on BTP | Integration Suite | SAP Business AI | SAP BASIS | Security | SAP SDLC

Functional: FICO ABAP | TRM ABAP | VIM | SAP BIS | SD ABAP | MM ABAP | PP ABAP | QM ABAP | PM ABAP | PS ABAP | EWM | TM ABAP | GTM ABAP | EHS ABAP | HR ABAP | BW | SAP Datasphere | SAP Business Data Cloud | SAP MDG | SAP Analytics Cloud | SAP Ariba | SAP CX | SAP IBP