ERPClimb logoERPClimb
CDS Views
RAP / CDS / ODataintermediate 11 min read

CDS Views Part 4: Authorization with DCL and Clean-Core Data Access

Preview · a free account unlocks the full lesson

Key takeaway

Control which rows each user may see with CDS access control (DCL): authorizationCheck values, pfcg auth conditions, inheriting roles in projections, privileged access — and read SAP data the clean-core way through released CDS views.

In this lessonShow sections

Visual overview

CDS Views Part 4: Authorization with DCL and Clean-Core Data Access — learning sheetFlow: Create authorization object ZSO_ORG with fields VKORG and ACTVT; assign values in a test role → Set @AccessControl.authorizationCheck: #CHECK on ZI_SalesOrder → Right-click the view → New → Access Control; write the role from the code example; activate → Read the view with two users with different VKORG values and compare row counts. Key ideas: HOW CDS ACCESS CONTROL WORKS; THE @AccessControl.authorizationCheck ANNOTATION; WRITING THE CONDITION; PROJECTIONS AND STACKED VIEWS. Watch out: In clean core, read released views (I_…), never SAP tables.ERPClimb.com / RAP / LESSON 4/4 / LEARNING SHEETCDS Views Part 4: Authorization with DCL and Clean-CoreData Access1 · HOW IT FLOWS1Createauthorizationobject ZSO_ORG…2Set@AccessControl.authorizationCheck:#CHECK on…3Right-click theview → New →Access Control…4Read the viewwith two userswith different…2 · KEY IDEAS EXPLAINEDHow CDS Access Control WorksYou write a DCL role (Access Control object) nextto the view: "define role ZI_SALESORDER {grant select on ZI_SalesOrder where ... }".The condition refers to view fields and, usually,to a classic authorization object through"aspect pfcg_auth": the user's PFCG role…The @Accesscontrol.authorizationcheck…#CHECK — a role should exist; if none exists, asyntax warning appears and the view is readablewithout restriction. Use this for views with…#MANDATORY — a role must exist; reading fails ifnone is defined.Writing The Conditionpfcg_auth( object, field, ACTVT = '03' ): the viewfield is compared with the user's allowed valuesfor that authorization field, restricted to…Several fields: "where ( SalesOrganization,DistributionChannel ) = aspect pfcg_auth( ZSO_ORG,VKORG, VTWEG, ACTVT = '03' )".Projections And Stacked ViewsA consumption or projection view on top of aprotected view does not automatically inherit itsrole. Add a role for the projection that reuses…3 · REMEMBER · WATCH OUTRememberA DCL role adds a row filter to every read of the view.#CHECK without a role gives only a warning — data stays open.Projections need their own role: "inheriting conditions fromentity".!Watch outIn clean core, read released views(I_…), never SAP tables.4 · IN A REAL PROJECTAn analytics app on sales orders was used by regional managers. During UAT a manager from one region exporteddata of all regions. The CDS views had @AccessControl.authorizationCheck: #CHECK, but nobody had created theDCL roles — the activation only showed a warning, which was ignored. The team added a role on the interface…Original ERPClimb learning sheet • Verify against your SAP release and edition

Explanation

A DCL role adds a row filter to every read of a view. If @AccessControl.authorizationCheck is set to #CHECK but no role actually exists, you only get a warning — the data stays fully open. Projections need their own role too, typically written as "inheriting conditions from entity." And in clean core, you read released views, the I_… views, never SAP tables directly.

Your sales order views already return the right data fast, as built in Parts 2 and 3, but a sales manager in sales organization 1010 must not see orders belonging to 2020. CDS solves this declaratively through access control, and this part also covers how to read SAP data the clean-core way.

CDS access control works by writing a DCL role, an Access Control object, alongside the view — something like "define role ZI_SALESORDER { grant select on ZI_SalesOrder where ... }". The condition refers to view fields and, usually, to a classic authorization object via "aspect pfcg_auth," so the user's PFCG role values for that object become a filter.

When anyone reads the view, whether through ABAP SQL, through RAP/OData, or through analytics, the database query automatically picks up that extra WHERE condition — the user simply sees fewer rows, with no error and no extra code in the app. This is row-level security defined once and applied to every consumer.

The @AccessControl.authorizationCheck annotation on the view states whether access control is expected. #CHECK means a role should exist; if none does, a syntax warning appears and the view remains readable without restriction — this suits views carrying business data. #MANDATORY means a role must exist, and reading fails outright if none is defined. #NOT_REQUIRED means no role is needed at all, which suits value helps with public data like currencies or units. #NOT_ALLOWED means access control must not be used, and any roles present are simply ignored. #PRIVILEGED_ONLY means the view is only readable with privileged access. The annotation documents the intent; the actual filtering comes from the DCL role.

Free account

Create a free account to keep reading

You have read the opening of this lesson. A free ERPClimb account unlocks the rest of it, every other lesson and topic, and your learning history, so you can pick up exactly where you stopped. No card needed.

  • Full explanation
  • Code example
  • Real project scenario
  • Common mistakes
  • Best practices
  • Interview angle

One tap with Google works too. Every topic keeps its first lesson open to everyone.

Keep exploring

Referenced SAP objects

Reviewed reference pages for the objects this page mentions.

Check before use: lesson examples are educational, not a guarantee of correctness for your SAP edition or release. Sample code has not been executed on your SAP system. Confirm API availability, syntax, authorizations and business impact in an approved development or test environment.