ABAP CDS and AMDP: Views, DCL, SQLScript and Performance
Interview-ready concepts, code patterns, authorization rules and performance decisions for ABAP on SAP HANA.
Series navigation: All interview parts · Previous: Part 9 Workflow · Next: Part 11 OData and Gateway
1. Architecture interview map
CDS provides a reusable semantic data model. DCL adds declarative row-level authorization. ABAP SQL consumes CDS entities like data sources. AMDP places carefully selected database procedures in an ABAP class when CDS and ABAP SQL are not sufficient.
2. What is a CDS view entity?
A CDS view entity is the recommended modern CDS view type for ABAP data models. It defines fields, associations, calculated elements, semantic annotations and authorization behavior without requiring a separately generated DDIC SQL view.
@EndUserText.label: 'Sales Order Items'
@AccessControl.authorizationCheck: #CHECK
define view entity ZI_SalesOrderItem
as select from vbap
association [1..1] to I_SalesOrder as _SalesOrder
on _SalesOrder.SalesOrder = $projection.SalesOrder
{
key vbap.vbeln as SalesOrder,
key vbap.posnr as SalesOrderItem,
vbap.matnr as Material,
@Semantics.amount.currencyCode: 'TransactionCurrency'
vbap.netwr as NetAmount,
vbap.waerk as TransactionCurrency,
_SalesOrder
}3. Association vs join
A join is part of the source expression and is evaluated as defined. An association declares a relationship with a target and cardinality; it is converted to a join when a path expression is used. Correct cardinality matters for semantics, optimizer decisions and consumers.
Why prefer associations?
- They describe reusable business relationships.
- Consumers can navigate only the paths they need.
- They make large data models easier to extend and read.
Do not claim that an association is “always faster.” The generated SQL, requested fields, predicates, cardinality and database plan determine performance.
4. Annotations interview questions
Annotations add metadata. Common groups include @EndUserText, @Semantics, @AccessControl, @ObjectModel and UI/service annotations in relevant models. Interviewers often ask why currency and unit references matter: consumers need them to interpret amounts and quantities correctly.
5. CDS access control and DCL
A CDS role grants SELECT access to a CDS entity and can restrict rows with literal values, session values, inherited conditions or PFCG-based authorization aspects. The exact rule depends on the security model.
@MappingRole: true
define role ZR_SALES_ORDER {
grant select on ZI_SalesOrderItem
where SalesOrganization =
aspect pfcg_auth( V_VBAK_VKO, VKORG, ACTVT = '03' );
}This is a compact interview example; verify the authorization object, field mapping and supported DCL syntax in your release.
Does DCL automatically protect every consuming CDS view?
No. Access control is evaluated for the entity addressed by the consumer according to its authorization-check annotation and access-control definition. Do not assume a protected source automatically secures every higher-level consumption entity—design and test authorization at each exposed boundary.
#CHECK, #NOT_REQUIRED and #PRIVILEGED_ONLY?
- #CHECK: authorization checks are expected and warnings occur if no role exists.
- #NOT_REQUIRED: checks may exist but are not required.
- #PRIVILEGED_ONLY: the entity is intended for privileged access scenarios, not general consumption.
Availability and exact behavior can vary by release, so answer in the context of the target platform.
6. AMDP fundamentals
ABAP Managed Database Procedures are implemented as methods of an ABAP class. On SAP HANA, the class implements IF_AMDP_MARKER_HDB and the method body is written in SQLScript. Activation manages the corresponding database procedure.
CLASS zcl_so_amdp DEFINITION
PUBLIC FINAL CREATE PUBLIC.
PUBLIC SECTION.
INTERFACES if_amdp_marker_hdb.
CLASS-METHODS get_totals
IMPORTING VALUE(iv_vbeln) TYPE vbeln_va
EXPORTING VALUE(et_result) TYPE ztt_so_total.
ENDCLASS.
CLASS zcl_so_amdp IMPLEMENTATION.
METHOD get_totals BY DATABASE PROCEDURE
FOR HDB LANGUAGE SQLSCRIPT
OPTIONS READ-ONLY
USING vbap.
et_result =
SELECT vbeln,
SUM( netwr ) AS total
FROM vbap
WHERE vbeln = :iv_vbeln
GROUP BY vbeln;
ENDMETHOD.
ENDCLASS.Important AMDP interview details
USINGdeclares referenced ABAP-managed database objects.- SQLScript variables and parameters use a colon in SQL expressions.
OPTIONS READ-ONLYprevents database modifications in that procedure.- Client handling must be designed explicitly; native SQLScript does not automatically behave like every ABAP SQL statement.
- Database procedure access can bypass ABAP table buffering.
- Static checks and debugging are performed mainly in ABAP Development Tools (ADT).
7. CDS table function and AMDP
A CDS table function declares a tabular CDS result and is implemented by an AMDP database function. It is useful when declarative CDS cannot express required calculations, but it adds database-specific complexity and should not be the default for normal joins or aggregations.
8. When should you use AMDP?
| Need | Preferred choice |
|---|---|
| Portable reads, joins and expressions | ABAP SQL first |
| Reusable semantic model and associations | CDS view entities |
| Row-level authorization for CDS consumption | DCL access control |
| Advanced HANA-specific calculation not expressible efficiently above | AMDP / SQLScript after measurement |
The strongest interview answer is: start with readable, portable ABAP SQL or CDS, measure the bottleneck, and use AMDP only when the database-specific solution has a clear benefit.
9. Performance troubleshooting scenario
Scenario: A CDS-based report is slow only when users open all company codes.
- Reproduce with representative volume and parameters.
- Use SQL Monitor, SQL trace and ADT/HANA plan analysis to find the expensive statement.
- Check whether filters are pushed down and whether a calculated expression blocks pruning.
- Validate association cardinality and accidental to-many path expansion.
- Check unnecessary fields, nested views, unions and authorization predicates.
- Verify suitable database indexes and current statistics with the responsible database team.
- Change the model only after the execution evidence identifies the cause.
How do you debug AMDP?
Set an AMDP breakpoint in ADT, start the ABAP call in the matching user/session context, and inspect SQLScript variables and result tables. Breakpoint prerequisites and supported database features depend on the system release and authorizations.
10. Common mistakes
- Assuming pushdown means moving every calculation to SQLScript.
- Using
SELECT *in wide CDS consumption. - Declaring incorrect association cardinality.
- Forgetting currency/unit semantics.
- Expecting source DCL to secure every consumption layer.
- Ignoring client handling, null semantics or type conversions in AMDP.
- Choosing AMDP before measuring a real performance problem.
11. Practice exercise
Create a CDS view entity for sales totals by sales organization and currency. Add amount semantics and an authorization design. Then describe when a CDS aggregate is enough and one genuine case that would justify an AMDP table function. Prepare five positive and five negative authorization tests.
12. Rapid revision
- CDS models semantics close to the data.
- Associations describe navigable relationships; cardinality must be truthful.
- DCL restricts rows for a CDS entity.
- ABAP SQL is the default access path.
- AMDP embeds SQLScript in an ABAP class and is HANA-specific.
- Measure with traces and execution plans before tuning.
13. Official SAP references
- CDS View Entities
- CDS Authorization Concept
- ABAP Managed Database Procedures
- Rules for Accessing ABAP-Managed Database Objects
- Debugging AMDP
Next: Part 11 — SAP OData and Gateway interview questions.

0 Comments