Loading...
Loading...
Comprehensive SAP ABAP CDS (Core Data Services) reference for data modeling, view development, and semantic enrichment. Use when creating CDS views or view entities in ABAP, defining data models with annotations (@AbapCatalog, @AccessControl, @EndUserText, @Semantics, @UI, @Consumption, @ObjectModel), working with associations and cardinality, implementing input parameters, using built-in functions (string, numeric, date/time), writing CASE expressions and conditional logic, implementing access control with DCL (Data Control Language), handling CURR/QUAN data types with reference fields, troubleshooting CDS errors (SD_CDS_ENTITY105), querying CDS views from ABAP, or displaying data with SALV IDA. Covers ABAP 7.4+ through ABAP Cloud with production-tested patterns. Keywords: ABAP CDS, Core Data Services, CDS view, CDS view entity, define view, define view entity, DDL, Data Definition Language, DCL, Data Control Language, annotations, @AbapCatalog, @AccessControl, @EndUserText, @Semantics, @UI, @Consumption, @ObjectModel, @Metadata, associations, cardinality, TO ONE, TO MANY, path expressions, input parameters, WITH PARAMETERS, built-in functions, CASE expression, CAST, session variables, $session, aggregate functions, GROUP BY, HAVING, joins, INNER JOIN, LEFT OUTER JOIN, access control, DEFINE ROLE, pfcg_auth, authorization, SALV IDA, cl_salv_gui_table_ida, Eclipse ADT, ABAP Development Tools, CDS annotations, Fiori Elements, OData, RAP, ABAP RESTful Application Programming Model, currencyCode, unitOfMeasure, SD_CDS_ENTITY105
npx skill4agent add secondsky/sap-skills sap-abap-cds| Type | Syntax | Database View | Since |
|---|---|---|---|
| CDS View | | Yes | 7.4 SP8 |
| CDS View Entity | | No | 7.55 |
@AbapCatalog.sqlViewName: 'ZCDS_EXAMPLE_V'
@AbapCatalog.compiler.CompareFilter: true
@AccessControl.authorizationCheck: #NOT_REQUIRED
@EndUserText.label: 'Example CDS View'
define view ZCDS_EXAMPLE
as select from db_table as t
{
key t.field1,
t.field2,
t.field3 as AliasName
}@AccessControl.authorizationCheck: #NOT_REQUIRED
@EndUserText.label: 'Example View Entity'
define view entity Z_CDS_EXAMPLE
as select from db_table as t
{
key t.field1,
t.field2,
t.field3 as AliasName
}@AbapCatalog.sqlViewName@AbapCatalog.sqlViewName@AbapCatalog.compiler.CompareFilter@AccessControl.authorizationCheck@EndUserText.label@Metadata.allowExtensionsreferences/annotations-reference.md-- Currency fields
@Semantics.currencyCode: true
waers,
@Semantics.amount.currencyCode: 'waers'
amount,
-- Quantity fields
@Semantics.unitOfMeasure: true
meins,
@Semantics.quantity.unitOfMeasure: 'meins'
quantity@UI.lineItem: [{ position: 10 }]
@UI.identification: [{ position: 10 }]
@UI.selectionField: [{ position: 10 }]
field1,
@UI.hidden: true
internal_field@Consumption.valueHelpDefinition: [{
entity: { name: 'I_Currency', element: 'Currency' }
}]
waersreferences/annotations-reference.mdcase status
when 'A' then 'Active'
when 'I' then 'Inactive'
else 'Unknown'
end as StatusTextcase
when amount > 1000 then 'High'
when amount > 100 then 'Medium'
else 'Low'
end as AmountCategory=<><><=>=BETWEEN x AND yLIKEIS NULLIS NOT NULLreferences/expressions-reference.mdquantity * price as TotalAmount,
amount / 100 as Percentage,
-amount as NegatedAmount$session.user$session.client$session.system_language$session.system_datereferences/expressions-reference.md$session.user as CurrentUser,
$session.system_date as Todayreferences/functions-reference.md-- String operations
concat(first_name, last_name) as FullName,
upper(name) as UpperName,
substring(description, 1, 10) as ShortDesc
-- Numeric operations
abs(amount) as AbsoluteAmount,
round(value, 2) as RoundedValue,
division(10, 3, 2) as PreciseDivision
-- Date operations
dats_add_days(current_date, 7) as NextWeek,
dats_days_between(start_date, end_date) as Duration
-- Type conversion
cast(field as abap.char(10)) as TextField,
cast(amount as abap.curr(15,2)) as CurrencyField
**ABAP Types**: `abap.char()`, `abap.numc()`, `abap.int4`, `abap.dats`, `abap.tims`, `abap.curr()`, `abap.cuky`, `abap.quan()`, `abap.unit()`
---
## 5. Joins
### Join Types
```sql
-- INNER JOIN (matching rows only)
inner join makt as t on m.matnr = t.matnr
-- LEFT OUTER JOIN (all from left, matching from right)
left outer join marc as c on m.matnr = c.matnr
-- RIGHT OUTER JOIN (all from right, matching from left)
right outer join mvke as v on m.matnr = v.matnr
-- CROSS JOIN (cartesian product)
cross join t001 as codefine view Z_ASSOC_EXAMPLE as select from scarr as c
association [1..*] to spfli as _Flights
on $projection.carrid = _Flights.carrid
association [0..1] to sairport as _Airport
on $projection.hub = _Airport.id
{
key c.carrid,
c.carrname,
c.hub,
// Expose associations
_Flights,
_Airport
}[0..1][1]association to one[1..1]association to one[0..*][*]association to many[1..*]association to manyreferences/associations-reference.mdassociation to one _Customer on ... -- [0..1]
association to many _Items on ... -- [0..*]-- Expose for consumer use
_Customer,
-- Ad-hoc field access (triggers join)
_Customer.name as CustomerName-- Filter with cardinality indicator
_Items[1: Status = 'A'].ItemNoreferences/associations-reference.mddefine view Z_PARAM_EXAMPLE
with parameters
p_date_from : dats,
p_date_to : dats,
@Environment.systemField: #SYSTEM_LANGUAGE
p_langu : spras
as select from vbak as v
{
key v.vbeln,
v.erdat,
v.erzet
}
where v.erdat between :p_date_from and :p_date_to:p_date_from$parameters.p_date_fromSELECT * FROM z_param_example(
p_date_from = '20240101',
p_date_to = '20241231',
p_langu = @sy-langu
) INTO TABLE @DATA(lt_result).define view Z_AGG_EXAMPLE as select from vbap as i
{
i.vbeln,
sum(i.netwr) as TotalAmount,
avg(i.netwr) as AvgAmount,
max(i.netwr) as MaxAmount,
min(i.netwr) as MinAmount,
count(*) as ItemCount
}
group by i.vbeln
having sum(i.netwr) > 1000@MappingRole: true
define role Z_CDS_EXAMPLE_DCL {
grant select on Z_CDS_EXAMPLE
where (bukrs) = aspect pfcg_auth(F_BKPF_BUK, BUKRS, ACTVT = '03');
}#NOT_REQUIRED#CHECK#MANDATORY#NOT_ALLOWEDreferences/access-control-reference.mdwhere (field) = aspect pfcg_auth(AUTH_OBJECT, AUTH_FIELD, ACTVT = '03')where status <> 'DELETED'where created_by ?= aspect userwhere (bukrs) = aspect pfcg_auth(...) and status = 'ACTIVE'references/access-control-reference.mdSELECT * FROM zcds_example
WHERE field1 = @lv_value
INTO TABLE @DATA(lt_result).cl_salv_gui_table_ida=>create_for_cds_view(
CONV #( 'ZCDS_EXAMPLE' )
)->fullscreen( )->display( ).@Semantics.currencyCode: true
waers,
@Semantics.amount.currencyCode: 'waers'
netwrinner join t001 as c on ...
{
c.waers,
@Semantics.amount.currencyCode: 'waers'
v.amount
}association [0..1] to ... -- Use for optional relationships
association [1..*] to ... -- Use for required one-to-manyreferences/troubleshooting.mdCL_DD_DDL_ANNOTATION_SERVICEget_annos()get_label_4_element()references/annotations-reference.mdfunctions-reference.mdassociations-reference.mdaccess-control-reference.mdexpressions-reference.mdtroubleshooting.mdtemplates/basic-view.mdparameterized-view.mddcl-template.md