ABAP CDS Components
Annotation
An annotation is extra information associated with a particular point in a document or other piece of information. It provides metadata for a field/view
which is understandable by different runtime frameworks eg. SADL framework/Analytic Framework. Annotation can be further categorized into,
• View Annotations : For the entire CDS View, placed in front of the DEFINE VIEW statement.
• Element Annotations : For elements in the Projection list, placed in front of or after the element.
• Parameters Annotations : For Parametrized CDS view, placed in front of or after the parameter.
• Extension Annotations : For CDS View extension, placed in front of the EXTEND VIEW statement.
• Function Annotations : For the CDS Table function, placed in front of the DEFINE TABLE FUNCTION statement.
Some of the important annotations,
@AbapCatalog.sqlViewName: ‘XXXX’ : Auto creates SQL view corresponding to CDS view with given name ‘XXXX’.
@AbapCatalog.preserveKey: true : Preserve key true ignores defaults keys from the database table/view and preserves keys defined explicitly in the View.
Possible Values — true/false
@AccessControl.authorizationCheck: #CHECK : Tells whether an authorization check should be performed or not.
@EndUserText.label: ‘XXXX’ : It's a free text which provides info to the end user. Maximum length would be 40 Characters.
@AbapCatalog.compiler.compareFilter: true : Defines the evaluation of filter conditions in path expressions of the CDS view.
@AbapCatalog.buffering<…> : Define the buffering of the CDS view in SAP buffering. e.g. @AbapCatalog.buffering.numberoffields,
Associations:
Associations are having similar functionality of Joins to fetch data from multiple tables based on Join Conditions, but they are ‘JOINS ON-DEMAND’
which mean they will only be triggered when user would access the required data which needs the Association of required tables.
Ex, CDS view has 3 Associations configured and user is fetching data form only 2 tables, the ASSOICATION on other table will not be triggered and the
system would return the results quickly which enable high turn-around time as compared to regular SQL JOINS.
Associations are defined with ‘Cardinality’. Syntax : association[<cardinality>]
• 0..1
• 0..n or 0..*
• 1..0
• 1..n or 1..*
n should be an integer(non-zero), this basically establishes the relationship between the source and target table.
Association Example:
@AbapCatalog.SqlViewName: ‘Name of Sql view’
@AbapCatalog.compiler.CompareFilter: true
@AbapCatalog.Preservekey: true
@AccessControl.AuthorizationCheck : #CHECK
@EnduserText.Label: ‘ Association Example’
Define view ‘ZCDS_ASSOC_EXAMPLE’
as select from VBAK V1 Association [1. . *] to VBAP _V2
On $Projection.Sales_Doc_Id = _V2.VBELN
{
Key V1.VBELN As Sales_Doc_ID,
Key _V2.POSNR as Sales_Item_ID,
V1.ERDAT as Create_Date
}
Here, the Source table is VBAK and the Target table is VBAP and which are associated together with cardinality 1..* which means, for every one record in
New Section 1 Page 1
Here, the Source table is VBAK and the Target table is VBAP and which are associated together with cardinality 1..* which means, for every one record in
VBAK with VBELN(On condition field) there can be a minimum of 1 record and a maximum of n(*) records in VBAP with VBELN(On condition field).
If we are confused about what kind of association we should configure in the CDS view then we can apply a rule of thumb: ‘always use: association[1]. This
will always trigger an OUTER join and will work in all cases.
Joins:
It used to join multiple table together to convert data into a meaningful information and represent to the business.
Unlike the association, if we have used 4 tables with join conditions in ABAP CDS view, all the joins will get executed when we trigger CDS view even
though business is looking for fields from any of two tables. This will lead to increase in execution time for CDS view.
Supported Join Types:
• Inner Join
• Left Outer Join
• Right Outer Join
• Cross Join
Considering same above example,
Define view ‘ZCDS_ASSOC_EXAMPLE’
as select from VBAK V1 Right Outer Join VBAP V2
On V1.Sales_Doc_Id = V2.VBELN
{
Key V1.VBELN As Sales_Doc_ID,
Key V2.POSNR as Sales_Item_ID,
V1.ERDAT as Create_Date
}
New Section 1 Page 2