You are on page 1of 34

SAP S/4 HANA

Analytics Overview
– Day 2

March 2020

1
Agenda
DCL Views

CDS Parametrization

CDS Functions & Expressions

Creating CDS Query View

Troubleshooting

Important Points to Remember

Best Practices

Deloitte Accelerators

Q&A

Copyright © 2017 Deloitte Development LLC. All rights reserved. 2


Data Control Language

• DCL objects are the authorization objects for CDS views.


• DCL uses conditions defined in the CDS and can draw upon the PFCG Roles to check the
authorizations of the user.
• If a CDS role is defined for a CDS entity, the access conditions are evaluated implicitly each time an
object is accessed using Open SQL or using an SADL query
• DCL can be used to define:
 Assignment roles that enable checks called instance-based authorization checks that are based
on the current data that are defined based on the CDS data model.
 Mapping roles which map CDS entities to classic authorization objects and are assigned to users
implicitly
• When a CDS entity is accessed using SADL or Open SQL, the following is checked:
 Is a role is defined for the CDS entity?
 Does the current user have the required authorizations?

3 Copyright © 2014 Deloitte Development LLC. All rights reserved.


DCL – CDS Roles

• A CDS role associates one or more CDS entities with CDS access control. An access condition is
defined in the role for each of these CDS entities. When a CDS entity of this type is accessed using
Open SQL or an SADL query, the access condition is evaluated as an additional selection condition.

• Two types of conditions are possible for CDS roles:


• Literal conditions :- compare an element of a CDS entity with fixed values.
• PFCG conditions :- associate an element of a CDS entity with authorizations in the SAP
authorization object.
• CDS authorization check can be turned on / off in the CDS view using the annotation:
• @AccessControl.authorizationCheck: #CHECK  Check for CDS authorization
• @AccessControl.authorizationCheck: #NOT_ALLOWED  Do not check for CDS authorization

4 Copyright © 2014 Deloitte Development LLC. All rights reserved.


Poll Question -1

5 Copyright © 2014 Deloitte Development LLC. All rights reserved.


Parameterized CDS Views
• Parameterized CDS Views can be created using the ..WITH PARAMETERS clause in the
DEFINE VIEW Statement when defining a CDS View.

Syntax
... WITH PARAMETERS pname1 : parameter_type, pname2
: parameter_type, ...

• This statement defines input parameters pname1, pname2 in a comma separated list. Each input
parameter must be typed with a data type parameter_type (which can be either a predefined
ABAP Data Type or an ABAP Dictionary Data Element).

6 Copyright © 2014 Deloitte Development LLC. All rights reserved.


Parameterized CDS Views

• An input parameter can be used as an operand in the following places in the SELECT statement
of the view using the syntax

:pname or $parameters.pname:

• Element in the SELECT list.


• Operand of an arithmetic expression.
• Operand directly after case in a case distinction.
• Right side of an expression in a WHERE clause or HAVING clause.
• Right side of an expression in an ON condition in an ABAP join or an association.
• Right side of an expression in a filter condition of a path expression.

7 Copyright © 2014 Deloitte Development LLC. All rights reserved.


Parameterized CDS Views- Eg.

• The following CDS view has a list of three input parameters used in
the WHERE clause of the SELECT statement.

@AbapCatalog.sqlViewName: 'DEMO_CDS_PARA'
define view demo_cds_parameters
with parameters p_distance_l:S_DISTANCE,
p_distance_o:S_DISTANCE,
p_unit:S_DISTID
as select from spfli
{ key carrid,
key connid,
cityfrom,
cityto,
distance,
distid }
where distid = :p_unit and
distance between :p_distance_l
and :p_distance_o;

8 Copyright © 2014 Deloitte Development LLC. All rights reserved.


Parameterized CDS Views- Eg. Of System Variables
• While using parameters with CDS Views, we can easily program them to populate the variables from
system variables instead of user input.
• System Variables can be incorporated into the view using either of the 2 ways shown below:
• Use Annotation @Environment.systemfield to implicitly assign the value of a system variable to an
input parameter.
• Example:
define view demo_cds_select_t100_langu
with parameters
@Environment.systemField:#SYSTEM_LANGUAGE
p_langu : lang
as select from
• Use $session.* to directly access the system variable either in the selection list or as an operand or
on the right side of an expression.
• Example:
• as select from
demo_expressions
{ id, $session.user as system_user }
• These system variables can be used to populate the session client, system date, system time,
session language and the session user ID.

9 Copyright © 2014 Deloitte Development LLC. All rights reserved.


Poll Question -2

10 Copyright © 2014 Deloitte Development LLC. All rights reserved.


CDS Functions & Expressions

• CDS has many standard functions which can be used in select list of view or expressions

SQL CONCAT,SUBSTRING,LTRIM,RTRIM
Conversion CURRENCY_CONVERSION, UNIT_CONVERSION
DATS_DAYS_BETWEEN,
DATS_ADD_DAYS,TMSTP_SECONDS_BETWEEN
Date/Time
Date/Time Conversion DATS_TIMS_TO_TSTMP,TSTMP_TO_DATS

• We more often use CASE and CAST expressions in CDS


Creating CDS Query View

Now that we have the cube with the fields and the business logic ready, we can build the CDS Query where we would provide the query
definition.

We start with the header annotations, where in addition to the usual annotations we need to include the annotation ‘@Analytics.query:
true’. This annotation tells the system that this will be our CDS Query and will not act as the Cube/Dimension/Text.

Here, apart from listing the fields required from the CDS Cube and their descriptions, we can declare field level annotations which would
define the various aspects of the report like:

• Which of the fields need to be included on the selection screen for filtering?

12
Creating CDS Query View (contd..)

• Which of the fields would show up in the rows or columns or would stay as free characteristics for drilldown in the default view?
We can use the field level annotation ‘@AnalyticsDetails.query.axis:’ to specify the field location. The possible values are #ROWS,
#COLUMNS and #FREE

• In case of KPIs, what form of aggregation would be used in the report?


We can specify what should be the default aggregation of the KPI, whether any exception aggregation needs to be applied on the
KPI. We can also leave these properties unspecified in which case it will stick to standard summation for aggregation.

• We can also, specify any additional static filters that need to applied using the where clause of the SELECT statement defining the
CDS Query.

13
Poll Question -3

14 Copyright © 2014 Deloitte Development LLC. All rights reserved.


Troubleshooting Tools – RSRTS_ODP_DIS

This T-Code displays the metadata of the transient provider which is used at runtime for a specific CDS view (DIMENSION, HIERARCHY,
CUBE, FACT).

Can be used to
perform general check
Enter the SQL View
on the Transient
Name and execute Provider

This section provides


technical header level
details of the Transient
Provider like the
generated name,
package, activation
time, etc.

This section provides


technical field level
details like field
technical name,
description, master
data association, etc.
Whenever, master
data association is
available drilldown
icon is visible against
the field (like
2CIFICOMPANYCODE)

15
Troubleshooting Tools – RSRT

T-Code RSRT can be used to display the output of a CDS Query in the same way it is used with BEx Queries.

• The report can displayed by using the naming format:


2C<SQL View Name>

• So for the CDS Query ZCCQ_CX_ACDOCA which has the SQL View Name ZCCQCXACDOCA, the query name to be provided in RSRT
will be 2CZCCQCXACDOCA.

16
Important Points to Remember

• Time dependent objects and Language dependent have @Semantics set. These have to be handled based on the usage in the
view.
For example, in AO, records are fetched using the key date, but we need to explicitly specify date range conditions when using in
Select List

Time Dependency Objects

Language Dependency Objects

17
Important Points to Remember

• If there are multiple keys in a Dimension, Representative Key should be the most relevant field for given entity. Other key fields
should have @objectmodel.foreignkey.association or Business semantics assigned.
For example, we take the profit center view which has 2 keys.

18
Important Points to Remember

• You cannot have input parameters passed to a Dimension, in that case you will have to build a Cube.
For example, if you want to use input date to calculate number of days then the underlying layer where you do this has to be a
CUBE type.
• Just start typing keyword and press CTRL+SPACE to get list of all annotations.

• SAP suggests using Associations instead of joins due to its features. Just make sure to use all key fields in the ON condition of
the association.
• You can extend a standard view to include custom/not available table fields. Just follow a naming convention so the objects are
not affected after upgrade.

• The CDS views are exposed as a ODP transient InfoProvider which follows 2C<SQLVIEWNAME> naming convention.
• You can check the output of the views using Adhoc Queries which follow 2C<SQLVIEWNAME>/!2C<SQLVIEWNAME>

19
Poll Question -4

20 Copyright © 2014 Deloitte Development LLC. All rights reserved.


Best Practices

• Effective use of filter push down

• Avoid using DCL just for filtering data

• Avoid using Unions as far as possible

• Usage of Associations & Joins

• Avoid non-equi Joins

• Effective usage of Aggregations

• Effective usage of Associations


Best Practices - Effective Filter Push-Down

• Apply filters at lower levels before the joins and calculation logic is processed

• SAP delivered base views are normally more generic and pulls in more data than that
may be needed for custom requirements.
Best Practices – Avoid filtering using DCL

• If restrictions are mandatory then convert that to input parameter/variable

• Use DCL only for Authorization restriction and not for data filtering on certain logic
Best Practices – Avoid Unions as far as possible

• Unions are generally considered as expensive statements and cause performance


degradation

• Perform Unions only when required


Best Practices - Effective usage of Associations and Joins

• If we have a where condition which uses a field from the right table, then it is better to
go with Left Outer Join than Association.

• If the fields from the right table are only used for display then Association would be
recommended
Best Practices – Avoid Non-Equi Join

• Avoid Non equality operators in the Join Predicate.

• If in case we can’t avoid due to business requirement, then move those restrictions to
where clause rather having in Join Predicate
Best Practices – Effective usage of Associations

• Use Propagated associations wherever possible and avoid redundant associations


Best Practices – Effective usage of Aggregations

• Use Aggregation to reduce the record set involved in further computations like Joins,
calculation

• Remove unwanted fields from Group by Clause


Poll Question -5,6 & 7

29 Copyright © 2014 Deloitte Development LLC. All rights reserved.


Accelerators

• CDS Accelerator: References-


• https://dsam.deloitteresources.com/ram/assetDetail/generalDetails.faces?guid=A8F0DC88-1E30-2083-49A3-
FA33A82927B3&v=1.1.0

• Data Flow Accelerator: Code Reference:

• Jarvis (Report Blueprint & Code Review):still not published, only high level information shared.

• Casting in CDS Views: Reference- https://help.sap.com/doc/abapdocu_751_index_htm/7.51/en-US/abencds_f1_cast_expression.htm


Q&A

31
Appendix
Below are the code snippets used in Demo:

32
THANKS!!

33 Copyright © 2014 Deloitte Development LLC. All rights reserved.


About Deloitte
Deloitte refers to one or more of Deloitte Touche Tohmatsu Limited, a UK private company limited by guarantee (“DTTL”), its network of member firms, and their related entities.
DTTL and each of its member firms are legally separate and independent entities. DTTL (also referred to as “Deloitte Global”) does not provide services to clients. Please see
www.deloitte.com/about for a detailed description of DTTL and its member firms. Please see www.deloitte.com/us/about for a detailed description of the legal structure of Deloitte
LLP and its subsidiaries. Certain services may not be available to attest clients under the rules and regulations of public accounting.

Copyright © 2014 Deloitte Development LLC. All rights reserved.


36 USC 220506
Member of Deloitte Touche Tohmatsu Limited

You might also like