ABAP CDS Views With Authorization
ABAP CDS Views With Authorization
Maksim Alyapyshev
February 27, 2017 11 minute read
Hi!
In this post I would like to consider a very important authorization aspect of ABAP CDS views. For each CDS
view we have to de ne an access control using DCL.
Part III. Access control for analytical CDS views with CUBE data category
Let’s start.
________________________________________________________________________________
First of all I recommend to begin with standard demo CDS views in SABAPDEMOS package based on Flight
Model.
https://blogs.sap.com/2017/02/27/abap-cds-views-with-authorization-based-on-access-control/ 1/25
2/15/2021 ABAP CDS views with Authorization based on Access Control | SAP Blogs
DDL:
@AbapCatalog.sqlViewName: 'DEMO_CDS_FULLACC'
@AccessControl.authorizationCheck: #CHECK
define view demo_cds_auth_fullaccess
as select from
scarr
{
key carrid,
carrname,
currcode,
url
};
DCL:
@MappingRole: true
define role demo_cds_role_fullaccess {
grant select on demo_cds_auth_fullaccess; }
DDL:
@AbapCatalog.sqlViewName: 'DEMO_CDS_LITERAL'
@AccessControl.authorizationCheck: #CHECK
define view demo_cds_auth_literal
as select from
scarr
{
key carrid,
carrname,
currcode,
url
};
DCL:
@MappingRole: true
define role demo_cds_role_literal {
https://blogs.sap.com/2017/02/27/abap-cds-views-with-authorization-based-on-access-control/ 2/25
2/15/2021 ABAP CDS views with Authorization based on Access Control | SAP Blogs
DDL:
@AbapCatalog.sqlViewName: 'DEMO_CDS_PFCG'
@AccessControl.authorizationCheck: #CHECK
define view demo_cds_auth_pfcg
as select from
scarr
{
key carrid,
carrname,
currcode,
url
};
DCL:
@MappingRole: true
define role demo_cds_role_pfcg {
grant select on demo_cds_auth_pfcg
where (carrid) =
aspect pfcg_auth (s_carrid, carrid, actvt='03'); }
Authorization object s_carrid could be found in t-code SU21 under BC_C object class.
DDL:
@AbapCatalog.sqlViewName: 'DEMO_CDS_LITPFCG'
@AccessControl.authorizationCheck: #CHECK
define view demo_cds_auth_lit_pfcg
as select from
scarr
{
key carrid,
carrname,
currcode,
https://blogs.sap.com/2017/02/27/abap-cds-views-with-authorization-based-on-access-control/ 3/25
2/15/2021 ABAP CDS views with Authorization based on Access Control | SAP Blogs
url
Follow RSS feed Like
};
DCL:
@MappingRole: true
define role demo_cds_role_lit_pfcg {
grant select on demo_cds_auth_lit_pfcg
where (carrid) =
aspect pfcg_auth (s_carrid, carrid, actvt='03') and
currcode = 'EUR'; }
DDL:
@AbapCatalog.sqlViewName: 'DEMO_CDS_INH'
@AccessControl.authorizationCheck: #CHECK
define view demo_cds_auth_inherited
as select from
demo_cds_auth_lit_pfcg
{
key carrid,
carrname,
currcode,
url
};
DCL:
@MappingRole: true
define role demo_cds_role_inherited {
grant select on demo_cds_auth_inherited
inherit demo_cds_role_lit_pfcg or currcode = 'USD'; }
In this example data records with USD and EUR currency code will be showed.
DDL:
https://blogs.sap.com/2017/02/27/abap-cds-views-with-authorization-based-on-access-control/ 4/25
2/15/2021 ABAP CDS views with Authorization based on Access Control | SAP Blogs
DCL:
@MappingRole: true
define role demo_cds_role_user {
grant select on demo_cds_auth_user
where
uname ?= aspect user; }
In this example data records will be ltered based on user name accessing CDS view.
Conclusion of Part 1: we considered standard demo examples with di erent options, let’s try to create our own
CDS view with access control.
________________________________________________________________________________
@AbapCatalog.sqlViewName: 'ZDEMO_CDS_PFCG'
@AccessControl.authorizationCheck: #CHECK
@EndUserText.label: 'Demo access pfcg'
define view Zdemo_Access_Pfcg as select from scarr
{
key carrid,
carrname,
currcode,
url
};
Now if we open data preview in HANA Studio we will see all records. Access control doesn’t exist yet.
https://blogs.sap.com/2017/02/27/abap-cds-views-with-authorization-based-on-access-control/ 5/25
2/15/2021 ABAP CDS views with Authorization based on Access Control | SAP Blogs
For each object de ne authorization eld(s) and Activity eld, include in permitted activities 03 Display. In our
case we include CARRID eld in ZS_CARRID and CONNID in ZS_CONNID.
https://blogs.sap.com/2017/02/27/abap-cds-views-with-authorization-based-on-access-control/ 6/25
2/15/2021 ABAP CDS views with Authorization based on Access Control | SAP Blogs
https://blogs.sap.com/2017/02/27/abap-cds-views-with-authorization-based-on-access-control/ 7/25
2/15/2021 ABAP CDS views with Authorization based on Access Control | SAP Blogs
@MappingRole: true
define role zdemo_access_pfcg {
grant select on Zdemo_Access_Pfcg
where (carrid) =
aspect pfcg_auth (zs_carrid, carrid, actvt='03'); }
If we open data preview in HANA studio we will not see any data.
4. Create a new role in PFCG and include authorization objects here. De ne what data based on selected elds
users should see. Don’t forget to generate pro le. Assign role to our user.
In rst case we will use only ZS_CARRID. We will use another object later in this post.
5. Go back to HANA studio to test authorization. Open data preview for our CDS.
https://blogs.sap.com/2017/02/27/abap-cds-views-with-authorization-based-on-access-control/ 8/25
2/15/2021 ABAP CDS views with Authorization based on Access Control | SAP Blogs
Now we see only records with de ned for Airline Company (CARRID) eld.
Note: If we open a view in ABAP Dictionary (SE11) the result is all data records.
Note: if we change annotation in DDL, activate CDS view for changes to be applied, we will see all records in
data preview once again. This means that a check is o .
@AccessControl.authorizationCheck: #NOT_ALLOWED
Conclusion of Part 2: We see how access control is working in simple case of selection from a table, let’s move
to analytic CDS views.
_____________________________________________________________________________
Part III. Access control for analytical CDS views with CUBE data category
1. Create a our own CDS view by coping existing one. This is CDS view with CUBE data category.
define view Z05_I_FlightByAirport as select from Z00_I_Flight // A CDS is implemented using a query
{ // No associations needed as these ar
// In the BASIC view we used alias to
// Also the associations from the oth
@ObjectModel.foreignKey.association: '_Airline' // Defines a foreignkey association f
key Z00_I_Flight.Airline, // Use the column Airline as a key fi
https://blogs.sap.com/2017/02/27/abap-cds-views-with-authorization-based-on-access-control/ 9/25
2/15/2021 ABAP CDS views with Authorization based on Access Control | SAP Blogs
/* Associations */
Z00_I_Flight._AircraftType, // The fields from the association _A
Z00_I_Flight._Airline, // The fields from the association _A
Z00_I_Flight._FlightConnection, // The fields from the association _F
Z00_I_Flight._FlightConnection._AirportFrom, // This needs to be added because air
Z00_I_Flight._FlightConnection._AirportTo // This needs to be added because air
}
Data preview for this CDS view in HANA Studio. Number of rows is 4894.
https://blogs.sap.com/2017/02/27/abap-cds-views-with-authorization-based-on-access-control/ 10/25
2/15/2021 ABAP CDS views with Authorization based on Access Control | SAP Blogs
3. In part II of this post we included ZS_CARRID authorization object to our user. Check result in data preview in
HANA Studio. Number of rows is 530.
https://blogs.sap.com/2017/02/27/abap-cds-views-with-authorization-based-on-access-control/ 11/25
2/15/2021 ABAP CDS views with Authorization based on Access Control | SAP Blogs
4. Check result in RSRT t-code. Number of rows is 530. The same result.
5. Check result in BO Analysis for Excel. The result is the same, only selected Airlines are availible for our user.
Note. There is no transnational data for AF Airline, that’s why it is not shown at the screen above.
________________________________________________________________________________
1. Create an analytical query CDS view in CUBE CDS from Part III.
https://blogs.sap.com/2017/02/27/abap-cds-views-with-authorization-based-on-access-control/ 12/25
2/15/2021 ABAP CDS views with Authorization based on Access Control | SAP Blogs
2. Data preview for this CDS view in HANA Studio. Number of rows is 4894. It seem that CDS view analytical
query is not use Cube CDS view authorization, but it is not true. You don’t need to create additional access
control for analytical query CDS view.
3. Check result in RSRT or BO Analysis for Excel. The results demonstrate that authorizations of Cube CDS view
are used in analytical query.
https://blogs.sap.com/2017/02/27/abap-cds-views-with-authorization-based-on-access-control/ 13/25
2/15/2021 ABAP CDS views with Authorization based on Access Control | SAP Blogs
Note: It is not required to create any variables in analytical query de nition, like we did in BEx query with
authorization characteristics.
4. Modify access control for Cube CDS view. Add eld authorization object ZS_CONNID instead of ZS_CARRID.
The analytical query result is more strict (look at ZS_CONNID de nition in Part II Step 4). Now number of rows
is 212 in my case.
https://blogs.sap.com/2017/02/27/abap-cds-views-with-authorization-based-on-access-control/ 14/25
2/15/2021 ABAP CDS views with Authorization based on Access Control | SAP Blogs
________________________________________________________________________________
1. Intersection of authorizations with “AND”. New authorization ZS_FLDAT was de ned for 3 days range only
(04.02.2015 – 06.02.2015). DCL modi cation for intersection:
https://blogs.sap.com/2017/02/27/abap-cds-views-with-authorization-based-on-access-control/ 15/25
2/15/2021 ABAP CDS views with Authorization based on Access Control | SAP Blogs
https://blogs.sap.com/2017/02/27/abap-cds-views-with-authorization-based-on-access-control/ 16/25
2/15/2021 ABAP CDS views with Authorization based on Access Control | SAP Blogs
Notes: Don’t forget to de ne authorizations at Cube CDS view level, not analytical query level. If you de ne the
same authorizations from Part V at analytical query level:
Notes: For analytical query for results in HANA Studio data preview showed all data, to correct this create
access control for analytical query:
@MappingRole: true
define role Z05_ROLE_2 {
grant select on Z05_C_FlightByAirportQuery
inherit Z05_ROLE; }
Conclusion for Part V: You can de ne intersection or union of authorizations for Analytical CDS views.
https://blogs.sap.com/2017/02/27/abap-cds-views-with-authorization-based-on-access-control/ 17/25
2/15/2021 ABAP CDS views with Authorization based on Access Control | SAP Blogs
Alert Moderator
Assigned tags
ABAP Development | SAP S/4HANA | abap cds | abap cds views | authorizations |
View more...
Related Questions
23 Comments
https://blogs.sap.com/2017/02/27/abap-cds-views-with-authorization-based-on-access-control/ 18/25
2/15/2021 ABAP CDS views with Authorization based on Access Control | SAP Blogs
Additional Note:
If you exclude from analytical query de nition elds by which authorizations are checked all will be ltered
correctly.
Like(0)
Former Member
Like(0)
Florian Henninger
Nice Work.
I like the owing style of the examples. Not something really new, but would suggest that it is easier to read
through your blog than working through the o cial help:-)
Like(0)
Like(0)
Horst Keller
Just for the sake of completeness, here’s the o cial help (where part one can also be found):
https://blogs.sap.com/2017/02/27/abap-cds-views-with-authorization-based-on-access-control/ 19/25
2/15/2021 ABAP CDS views with Authorization based on Access Control | SAP Blogs
https://help.sap.com/http.svc/rc/abapdocu_751_index_htm/7.51/en-US/index.htm?
Follow
le=abencds_authorizations.htm RSS feed Like
Like(0)
Praneeth Chintapalli
Great Job.
Like(0)
Cemal Aslan
Like(0)
Marcelo Berger
Like(0)
Former Member
Like(0)
https://blogs.sap.com/2017/02/27/abap-cds-views-with-authorization-based-on-access-control/ 20/25
2/15/2021 ABAP CDS views with Authorization based on Access Control | SAP Blogs
Sudarshan Survepalli
Follow RSS feed Like
August 16, 2017 at 4:06 pm
Like(0)
Additional Note 2:
If you are going to use ABAP CDS view in other ABAP logic, e.i. in ABAP reports I recommend you to look at
great Horst Keller blog:
https://blogs.sap.com/2015/12/07/abap-news-for-release-750-abap-cds-access-control/
Brie y:
In ABAP report use select from entity name (name after de ne view), not from DB view name (name
in @AbapCatalog.sqlViewName: 'DB_view') if you want DCL to be checked and data ltration occurred.
If you de ne @AccessControl.authorizationCheck: #CHECK or @AccessControl.authorizationCheck:
#NOT_REQUIRED it will work.
If you modify annotation in DDL to @AccessControl.authorizationCheck: #NOT_ALLOWED,then DCL will be
ignored.
Like(0)
Manish Majumdar
Hello Maksim,
Appreciate your time in getting the blog. I have two questions around the DCLs:
https://blogs.sap.com/2017/02/27/abap-cds-views-with-authorization-based-on-access-control/ 21/25
2/15/2021 ABAP CDS views with Authorization based on Access Control | SAP Blogs
Like(0)
Hi!
Link to documentation:
https://help.sap.com/viewer/f2e545608079437ab165c105649b89db/7.5.16/en-
US/707332186bf41014b5040bee4e204223.html
Also try to create new DCL (if you have system), in template there are useful comments. There are all available
features.
BR, Maksim
Like(0)
K Shiva
Hello Maksim,
This blog is very useful. I have one questions around the DCLs:
I have created an Analytical ori application with the back end implementation as SQL view of a CDS.
I have done this by adding the sql name in the X-Query of the URL Parameters in the target mapping of the tile
in Launchpad con guration.
Now i have created the DCL for the CDS view and the data when i execute the cds is getting ltered by DCL but
the data in the ori app is not getting ltered.
Seems the SQL View is not applying the DCL while rendering result on Analytical application.
Now how can i apply the DCL on the Analytical application which is using SQL view of a cds ?
https://blogs.sap.com/2017/02/27/abap-cds-views-with-authorization-based-on-access-control/ 22/25
2/15/2021 ABAP CDS views with Authorization based on Access Control | SAP Blogs
zaza Wang
Like(0)
viswanath thammineni
Like(0)
Hi,
As I know It is not possible to enhance Access Control, but you could create an additional one.
BR,
Maksim
Like(0)
https://blogs.sap.com/2017/02/27/abap-cds-views-with-authorization-based-on-access-control/ 23/25
2/15/2021 ABAP CDS views with Authorization based on Access Control | SAP Blogs
Dmitrii Sharshatkin
Follow RSS feed Like
December 15, 2020 at 10:42 am
Hi Maksim,
Is it then a bug ?…
Thanks, Dima
Like(0)
Olivier Souksamran
Dmitri,
This is actually acting like you experienced it. Maksim said it "should work as AND" but unfortunatly it does not.
Regards,
Olivier
Like(0)
Dmitrii Sharshatkin
Hi Olivier,
thanks for clarifying. Yes, indeed, they are joined with "OR" by default.
But I've discovered, in 7.54 (S/4 1908), there is an option 'COMBINATION MODE', which brings required
functionality:
https://help.sap.com/doc/abapdocu_754_index_htm/7.54/en-US/index.htm?
le=abencds_dcl_role_cond_rule.htm
Regards, Dima
Like(1)
Oli i S k
https://blogs.sap.com/2017/02/27/abap-cds-views-with-authorization-based-on-access-control/ 24/25
2/15/2021 ABAP CDS views with Authorization based on Access Control | SAP Blogs
Olivier Souksamran
December 15, 2020 at 1:33 pmFollow RSS feed Like
Dear Dmitrii,
Regards,
Olivier
Like(0)
Alexandra Marinescu
Like(0)
Pranav Kapoor
Like(0)
Find us on
Newsletter Support
https://blogs.sap.com/2017/02/27/abap-cds-views-with-authorization-based-on-access-control/ 25/25