Claude
Skills
Sign in
Back

sap-abap-cds

Included with Lifetime
$97 forever

Comprehensive SAP ABAP CDS (Core Data Services) reference for data modeling, view development, and semantic enrichment. Use when creating CDS views or view entities, defining data models with annotations, working with associations and cardinality, implementing input parameters, using built-in functions, writing CASE expressions, implementing access control with DCL, handling CURR/QUAN data types, troubleshooting CDS errors, querying CDS views from ABAP, or displaying data with SALV IDA. Covers ABAP 7.4+ through ABAP Cloud.

Cloud & DevOps

What this skill does


# SAP ABAP CDS (Core Data Services)

## Related Skills

- **sap-abap**: Use for ABAP programming patterns used with CDS or when implementing EML statements in ABAP
- **sap-btp-cloud-platform**: Use for CDS deployment scenarios on BTP or ABAP Environment configurations
- **sap-fiori-tools**: Use when building Fiori Elements applications that consume CDS views or working with UI annotations
- **sap-cap-capire**: Use for comparing CDS syntax between ABAP and CAP or when integrating ABAP CDS with CAP services
- **sap-api-style**: Use when documenting CDS-based OData services or following API documentation standards

**Quick Reference**: [https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/abencds.html](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/abencds.html) | SAP Cheat Sheets: [https://github.com/SAP-samples/abap-cheat-sheets/blob/main/15_CDS_View_Entities.md](https://github.com/SAP-samples/abap-cheat-sheets/blob/main/15_CDS_View_Entities.md)

## Version Compatibility

This skill covers CDS features from **7.40 SP8** through **ABAP Cloud**. Key version boundaries:

| Feature | 7.40 SP8 | 7.50 | 7.51 | 7.55+ |
|---------|:--------:|:----:|:----:|:-----:|
| CDS View (`DEFINE VIEW`) | x | x | x | x |
| CDS associations, parameters, built-in functions | x | x | x | x |
| CDS Table Functions (`DEFINE TABLE FUNCTION`) | | x | x | x |
| CDS Access Control (DEFINE ROLE / pfcg_auth) | x | x | x | x |
| CDS Access Control (implicit evaluation) | | x | x | x |
| Session variables (`$session.user/client/system_language`) | x | x | x | x |
| `@Environment.systemField` annotation | | x | x | x |
| `UPPER`/`LOWER` functions | | | x | x |
| `$session.system_date` | | | x | x |
| CDS Metadata Extensions (`ANNOTATE VIEW`) | | | x | x |
| Cross Join in CDS | | | x | x |
| **CDS View Entity (`DEFINE VIEW ENTITY`)** | | | | x |
| New cardinality syntax (`to one`/`to many`) | | | | 7.57+ |

**On a 7.40 system**: Use `DEFINE VIEW` (not `DEFINE VIEW ENTITY`). CDS table functions
are **not available** before 7.50. Basic DCL (`DEFINE ROLE` with `pfcg_auth`) is available
from 7.40 SP08, but implicit role evaluation in ABAP SQL requires 7.50+.
`$session.user/client/system_language` are available from 7.40 SP08.
The templates in `templates/` include both classic CDS View and View Entity variants.

## Table of Contents
- [1. CDS View Fundamentals](#1-cds-view-fundamentals)
- [2. Essential Annotations](#2-essential-annotations)
- [3. Expressions and Operations](#3-expressions-and-operations)
- [4. Built-in Functions](#4-built-in-functions)
- [5. Joins](#5-joins)
- [6. Associations](#6-associations)
- [7. Input Parameters](#7-input-parameters)
- [8. Aggregate Expressions](#8-aggregate-expressions)
- [9. Access Control (DCL)](#9-access-control-dcl)
- [10. Data Retrieval from ABAP](#10-data-retrieval-from-abap)
- [11. Common Errors and Solutions](#11-common-errors-and-solutions)
- [12. Useful Transactions and Tables](#12-useful-transactions-and-tables)
- [Bundled Resources](#bundled-resources)
- [Source Documentation](#source-documentation)

---

## 1. CDS View Fundamentals

### View Types

| Type | Syntax | Database View | Since |
|------|--------|---------------|-------|
| **CDS View** | `DEFINE VIEW` | Yes | 7.4 SP8 |
| **CDS View Entity** | `DEFINE VIEW ENTITY` | No | 7.55 |

**Recommendation**: Use CDS View Entities for new development.

### Basic CDS View Syntax

```sql
@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
}
```

### CDS View Entity Syntax (7.55+)

```sql
@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
}
```

**Key Difference**: View entities omit `@AbapCatalog.sqlViewName` - no SQL view generated.

### Eclipse ADT Setup
1. **File** → **New** → **Other** → **Core Data Services** → **Data Definition**
2. Enter name, description, and package
3. Select template (view, view entity, etc.)

---

## 2. Essential Annotations

### Core Annotations

**Essential annotations for CDS development**:
- `@AbapCatalog.sqlViewName` - SQL view name (max 16 chars)
- `@AbapCatalog.compiler.CompareFilter` - Optimize WHERE clauses
- `@AccessControl.authorizationCheck` - Set to #NOT_REQUIRED, #CHECK, #MANDATORY, or #NOT_ALLOWED
- `@EndUserText.label` - User-facing description
- `@Metadata.allowExtensions` - Allow view extensions

**Complete Reference**: See `references/annotations-reference.md` for 50+ annotations with examples.

### Semantics Annotations (Currency/Quantity)

**Required for CURR and QUAN data types** to avoid error SD_CDS_ENTITY105:

```sql
-- Currency fields
@Semantics.currencyCode: true
waers,
@Semantics.amount.currencyCode: 'waers'
amount,

-- Quantity fields
@Semantics.unitOfMeasure: true
meins,
@Semantics.quantity.unitOfMeasure: 'meins'
quantity
```

### UI Annotations (Fiori Elements)

```sql
@UI.lineItem: [{ position: 10 }]
@UI.identification: [{ position: 10 }]
@UI.selectionField: [{ position: 10 }]
field1,

@UI.hidden: true
internal_field
```

### Consumption Annotations (Value Help)

```sql
@Consumption.valueHelpDefinition: [{
  entity: { name: 'I_Currency', element: 'Currency' }
}]
waers
```

For complete annotation reference, see `references/annotations-reference.md`.

---

## 3. Expressions and Operations

### CASE Expressions

**Simple CASE** (single variable comparison):
```sql
case status
  when 'A' then 'Active'
  when 'I' then 'Inactive'
  else 'Unknown'
end as StatusText
```

**Searched CASE** (multiple conditions):
```sql
case
  when amount > 1000 then 'High'
  when amount > 100 then 'Medium'
  else 'Low'
end as AmountCategory
```

### Comparison Operators

**Standard operators**: `=`, `<>`, `<`, `>`, `<=`, `>=`
**Special operators**: `BETWEEN x AND y`, `LIKE`, `IS NULL`, `IS NOT NULL`

**Complete Reference**: See `references/expressions-reference.md` for all operators and expressions.

### Arithmetic Operations

```sql
quantity * price as TotalAmount,
amount / 100 as Percentage,
-amount as NegatedAmount
```

### Session Variables

**Available system variables** (SY fields equivalent):
- `$session.user` (SY-UNAME) - Current user **[7.40 SP08+]**
- `$session.client` (SY-MANDT) - Client **[7.40 SP08+]**
- `$session.system_language` (SY-LANGU) - Language **[7.40 SP08+]**
- `$session.system_date` (SY-DATUM) - Current date **[7.51+]**

> **Note**: `$session.user/client/system_language` are available from 7.40 SP08.
> `$session.system_date` requires 7.51+. `@Environment.systemField` requires 7.50+.

**Complete Reference**: See `references/expressions-reference.md` for all system variables.

```sql
$session.user as CurrentUser,
$session.system_date as Today
```

---

## 4. Built-in Functions

CDS provides comprehensive built-in functions for string, numeric, and date operations.

### Key Function Categories
- **String Functions**: concat(), length(), substring(), upper(), lower(), replace()
- **Numeric Functions**: abs(), ceil(), floor(), round(), division()
- **Date Functions**: dats_add_days(), dats_add_months(), dats_days_between()
- **CAST Expression**: Convert between ABAP data types

> **Note**: `upper()` and `lower()` in CDS require **7.51+**. On 7.40/7.50, case
> conversion must be performed in ABAP after selecting (there is no CDS equivalent).

**Complete Reference**: See `references/functions-reference.md` for all 50+ functions with examples.

### Quick Examples
```sql
-- 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 PreciseDivisio

Related in Cloud & DevOps