SU21SU53ST01SU01
Most learners can write a basic define view entity after one tutorial. The trouble starts when a Fiori app shows no data for a user, a view will not activate, or a consultant asks, "Where is the authorization check?" Those problems come from three things: annotations, associations and access control.
This guide covers CDS view annotations, associations and access control (DCL) in one flow, using a purchase order view that MM and EWM consultants will recognise. By the end you will be able to annotate a view, expose associations, write a DCL role against M_BEST_EKO, and troubleshoot activation errors. If CDS is new to you, read Core Data Services (CDS) Views for Beginners first.
- Annotations add meaning (labels, currency links, UI, authorization mode) to a CDS view; use ADT's Ctrl+Space to avoid invalid ones.
- An association is a lazy relationship: define it, then expose it in the select list so consumers can navigate with path expressions.
- DCL roles (define role) filter rows using PFCG authorizations, for example M_BEST_EKO for purchasing organization.
- @AccessControl.authorizationCheck: #CHECK with no DCL role usually means business users see no rows.
- Protect the lowest sensitive view and reuse conditions by inheriting, and always test with a real business user.
- Check ADT's Problems view first when activation fails; the cause is usually a missing exposed field, wrong $projection reference or inactive dependency.
- 1Create data definitionWrite the view entity with annotations in ADT and activate with Ctrl+F3.
- 2Add associationsDefine _Supplier and _CompanyCode, then expose them in the select list.
- 3Set authorization checkUse @AccessControl.authorizationCheck: #CHECK on the view.
- 4Write DCL roleCreate define role with aspect pfcg_auth(M_BEST_EKO, EKORG, ACTVT = '03').
- 5Assign PFCG roleGive the test user matching authorization values in PFCG and SU01.
- 6Test as business userRun data preview or ABAP SQL, and use SU53 or ST01 if rows are missing.
01How the three building blocks fit together
A CDS view has three layers of meaning. The select list says what data you read. Annotations say how the data is to be treated: labels, currency fields, UI behaviour, analytics type and the authorization mode. Associations say how this view relates to other views, without forcing a join. DCL (Data Control Language) says which rows a given user may read.
The reason this matters in S/4HANA is that the same view is consumed by ABAP reports, Fiori apps, OData services and analytics. Authorization has to live with the data model, not in each consumer. That is the idea behind DCL. It is also why code-pushdown work, as in ABAP on HANA code pushdown, normally ends with a CDS view plus an access control object.
| Element | Where it is written | Purpose |
|---|---|---|
| Annotations | Above or inside the DDL source (@...) | Metadata for labels, semantics, UI, analytics, authorization mode |
| Association | DDL source, after as select from | Reusable, lazy relationship to another entity |
| Access control | Separate DCL source (define role) | Row-level filtering based on PFCG authorizations or literals |
02Annotations: the ones you will actually use
There are hundreds of annotations. Learn the handful that appear in almost every project, and look up the rest in the ABAP CDS documentation inside ADT (ABAP Development Tools in Eclipse).
| Annotation | Example value | What it does |
|---|---|---|
@EndUserText.label | 'PO Header with Supplier' | Description shown in tools and the repository |
@AccessControl.authorizationCheck | #CHECK | Tells the framework to apply DCL. Other values: #NOT_REQUIRED, #NOT_ALLOWED, #PRIVILEGED_ONLY |
@VDM.viewType | #BASIC, #COMPOSITE, #CONSUMPTION | Position in the virtual data model layers |
@Semantics.amount.currencyCode | 'DocumentCurrency' | Links an amount field to its currency field |
@Semantics.quantity.unitOfMeasure | 'OrderQuantityUnit' | Links a quantity to its unit |
@Analytics.dataCategory | #DIMENSION, #FACT, #CUBE | Role of the view in analytics |
@UI.lineItem | [{ position: 10 }] | Shows the field as a column in a Fiori list report |
@Search.searchable | true | Enables fuzzy search on the view |
Annotations apply at three levels: view level (above define), element level (above a field) and, in some cases, parameter level. The same annotation name can be valid at one level only, so a misplaced annotation is a common activation error.
One annotation deserves special care: @AccessControl.authorizationCheck. If you leave it out on a view in a system with the check enforced, you get a warning in the activation log. If you set #CHECK and no DCL role exists, users with normal authorization see no rows at all. We return to this in the DCL sections.
03Associations: relationships without a join
An association defines a link to a target entity but does not execute until a consumer uses it. Think of it as a join that is only built when somebody navigates through it. This makes views smaller and faster than stacking joins into every view.
Here is a purchase order header view that exposes associations to supplier and company code. The released interface view names below are standard in S/4HANA, but confirm field names in your release using ADT's Open ABAP Development Object (Ctrl+Shift+A).
@AccessControl.authorizationCheck: #CHECK
@EndUserText.label: 'PO Header with Supplier'
@VDM.viewType: #COMPOSITE
define view entity ZI_PurchaseOrderHdr
as select from I_PurchaseOrderAPI01 as Po
association [0..1] to I_Supplier as _Supplier
on $projection.Supplier = _Supplier.Supplier
association [0..1] to I_CompanyCode as _CompanyCode
on $projection.CompanyCode = _CompanyCode.CompanyCode
{
key Po.PurchaseOrder,
Po.CompanyCode,
Po.PurchasingOrganization,
Po.PurchasingGroup,
Po.Supplier,
Po.PurchaseOrderDate,
_Supplier,
_CompanyCode
}Points to notice:
- The cardinality
[0..1]is the maximum and minimum number of target rows per source row. Wrong cardinality causes duplicate rows or wrong join type later. $projection.Supplierrefers to the field as exposed in the select list, not to the source table field.- The association name starts with an underscore by convention (
_Supplier). It only becomes usable by consumers when you add it to the select list, as in the last two lines.
Using the association in ABAP SQL
A consumer navigates with a path expression, which is a backslash followed by the association name:
SELECT PurchaseOrder,
\_Supplier-SupplierName AS SupplierName
FROM zi_purchaseorderhdr
WHERE CompanyCode = '1010'
INTO TABLE @DATA(lt_po).The database performs a left outer join to I_Supplier only for this query. The same navigation is used by Fiori elements, where a navigation property in the OData service maps to the association.
04Writing a DCL role for the purchase order view
Access control is a separate repository object created in ADT through New → Other ABAP Repository Object → Core Data Services → Access Control. For our view we want to restrict rows by purchasing organization, using the standard authorization object M_BEST_EKO (field EKORG, with ACTVT).
@EndUserText.label: 'Access control for PO header'
@MappingRole: true
define role ZI_PURCHASEORDERHDR {
grant select on ZI_PurchaseOrderHdr
where ( PurchasingOrganization ) =
aspect pfcg_auth( M_BEST_EKO, EKORG, ACTVT = '03' );
}Read this as: a user may select a row only if their PFCG authorizations contain activity 03 (display) for the purchasing organization in that row. The left side is the view field; the right side maps it to the authorization field.
Other DCL conditions you will meet
- Literal condition:
where PurchasingOrganization = '1000'. Useful for fixed scoping. - User condition:
where CreatedByUser = aspect user. The row is visible to its creator only, provided the view has such a field. - Unrestricted:
where true. Use it deliberately and rarely, for example on a value-help view that has to be visible to everyone. - Inheritance:
grant select on ZI_PurchaseOrderItem where inheriting conditions from entity ZI_PurchaseOrderHdr;. The item view reuses the header rule, so there is one place to maintain.
After activation, give the test user a PFCG role containing M_BEST_EKO with EKORG = 1000 and ACTVT = 03. Log in as that user, run a data preview of the view in ADT, and check that only organization 1000 rows return. If nothing appears, run SU53 for the failed check or trace with ST01.
05Step-by-step: build and test the secured view
- In ADT, create a package such as
ZMM_CDSand open the ABAP project connected to your S/4HANA system. - Create the data definition
ZI_PurchaseOrderHdrwith the DDL above. PressCtrl+F3to activate. - Run Open With → Data Preview (
F8). With#CHECKand no role, a user without special rights sees no rows, which confirms the check is live. - Create the access control object
ZI_PURCHASEORDERHDRwith thedefine rolecode and activate it. - Assign a test user a PFCG role with
M_BEST_EKOrestricted to one purchasing organization (PFCG, thenSU01for assignment). - Log on as the test user and repeat the data preview. Only authorised rows should appear.
- Run the ABAP SQL path expression from the earlier section to confirm the association works under the same user.
06CDS view activation: what goes wrong and how to fix it
Activation is the step that turns the DDL source into a runtime object. In ADT you activate one object with Ctrl+F3 and several inactive objects with Ctrl+Shift+F3. Activate the underlying views before the views that depend on them, and the DCL role after the view it protects.
| Symptom | Likely cause | Fix |
|---|---|---|
Activation log: unknown field in on condition | Used the source field instead of the projected field with $projection | Add the field to the select list or use the correct alias |
| Association not found by consumer | Association defined but not added to the select list | List _Supplier in the field list so it is exposed |
| Warning about missing authorization check | @AccessControl.authorizationCheck missing | Set #CHECK and create a DCL, or #NOT_REQUIRED if the data is not sensitive and your governance allows it |
| DCL cannot be activated | View inactive, or field name in where does not exist in the view | Activate the view first and use the exposed field names |
| Annotation rejected | Value or position not valid for that annotation | Use Ctrl+Space in ADT to see allowed values |
| Duplicate rows in the result | Wrong association cardinality or a join to a one-to-many target | Correct the cardinality and the on condition |
The "association cannot be used locally" problem
People search for this message when an association defined in one view does not work where they try to use it. In practice, the cause is usually one of three things: the association is used in the same view in a place or a way the syntax does not allow, the association was never exposed so another view cannot reach it, or the path expression is applied to a view type that does not support it. The exact wording differs between releases, so read the full message in the ADT Problems view and note the line it points to.
The working fix is almost always the same: define the association, expose it in the select list, and navigate to it from the consuming view or ABAP SQL statement through a path expression. If you need the target data in the same view, use an explicit join or define a path expression in the field list (for example _Supplier.SupplierName as SupplierName).
07Finance views: ACDOCA and ACDOCP in CDS
Two of the most searched finance tables in this area are ACDOCA and ACDOCP. ACDOCA is the Universal Journal table that stores actual line items; its standard CDS interface view is I_JournalEntryItem. See the Universal Journal (ACDOCA) guide for the table itself and New General Ledger for ledger concepts.
ACDOCP is the planning counterpart: it stores plan line items from integrated planning. For reporting on it, first search the system for released standard CDS views that read ACDOCP (in ADT use Open ABAP Development Object and the Where-Used list on the table). Build a custom view only if nothing standard fits.
For any custom view on these tables, three rules save trouble:
- Read from the standard interface view where one exists. It already carries the semantic annotations for amount, currency and ledger.
- Always annotate amounts with
@Semantics.amount.currencyCode, otherwise analytics tools cannot convert or sum them correctly. - Finance data is sensitive. Use
#CHECKwith a DCL role on company code (F_BKPF_BUK) or ledger, and neverwhere true.
08Common mistakes and interview questions
Common mistakes
- Writing the DCL on the consumption view only and leaving the basic view open, so another developer's view bypasses it. Protect the lowest view that holds sensitive data and inherit upwards.
- Testing as a developer with broad authorizations and shipping without a business-user test.
- Using
#NOT_REQUIREDto make an error go away. - Exposing associations with wrong cardinality, leading to duplicates in Fiori lists.
- Hard-coding client or organization values in DCL literals that later change.
Interview questions on this topic
- What is the difference between a join and an association in CDS?
- What does
@AccessControl.authorizationCheck: #CHECKdo and what happens without a DCL role? - How would you restrict a purchase order view by plant and purchasing organization?
- How do you reuse one DCL condition across header and item views?
- Where would you look when a Fiori list is empty for one user only?
For a logistics view of where such CDS models are consumed, see end-to-end logistics integration.
Get the 40+ lesson playlist, the most-asked interview questions and our 90-day roadmap on WhatsApp.
?Frequently asked questions
What is a CDS view DCL?
DCL (Data Control Language) is the language used to write access control objects for CDS views. A role defined with define role grants select on a view only for rows that match PFCG authorization values, literals or the current user. It is applied automatically when the view has authorizationCheck set to #CHECK.
How do I create a CDS view on ACDOCP?
ACDOCP holds plan line items. First search for a released standard CDS view that already reads it, using the where-used list in ADT. If none fits, create a view entity selecting from the table, add semantic annotations for amounts and currencies, and protect it with a DCL role on company code.
How does CDS view activation work?
You activate a data definition in ADT with Ctrl+F3, or several inactive objects with Ctrl+Shift+F3. Activation checks syntax and dependencies and generates the runtime object. Activate underlying views first, and activate the DCL role after the view it protects.
What does the error that an association cannot be used locally mean?
It generally points to an association being used in a place or way the view does not allow, or one that has not been exposed. The exact text varies by release, so read the Problems view in ADT. Normally you expose the association in the select list and navigate through it from the consumer, or use an explicit join in the same view.
Which CDS view reads ACDOCA?
The standard interface view I_JournalEntryItem reads the Universal Journal table ACDOCA. Use it as the base for custom reporting because it already carries semantic annotations. Confirm the view and its fields in your release using ADT.
What is the difference between an association and a join in CDS?
A join is executed whenever the view runs. An association is only resolved when a consumer navigates through it using a path expression. This keeps views lighter and lets the consumer decide which relationships to use.
Why does my CDS view return no data for a business user?
Most often the view has #CHECK and the user's PFCG role lacks matching authorization values, or no DCL role exists. Check SU53 right after the failure, or trace with ST01. Then adjust the role or the DCL condition.
Learn SAP hands-on with theTechMentor
Live weekday & weekend batches or 24/7 recorded courses, with S/4HANA practice server access and interview preparation.