Wednesday, May 30, 2018

Notes Series : CDS view

DATA to CODE        VS    CODE to DATA

Earlier calculation logic used to be written on the application server, later with the invention of powerful HANA DB time-consuming calculation logic was pushed to database layer itself.

Bottom Up              VS     Top Down

Before 7.4 SP2 HANA view and Stored procedures were written on HANA layer and on application server they are consumed using External view and stored procedure proxy respectively.
Later with the help of CDS views and AMDP, it becomes possible to write the code in ABAP layer itself and push it down to HANA view & stored procedures in HANA layer.

CDS (Core data services)

Enhancement of SQL standard to define the semantically rich data model.
Go for it if functionality needed more than once else use direct SQL statement.

Value-add from SE11 views:
1.       Code to data paradigm/Code push down
2.       Complex expressions can be used
3.       The possibility of outer join
4.       Analytical adaptation
5.       Used for OData services
6.       Separate UI annotations & core functionality
7.       Built-in functions like Union, Union All, Intersection
8.       Parameters for dynamic selection

Annotations :

Annotations use metadata to enrich CDS objects. These data modifies the properties of the view and the behavior when accessed at runtime. These can be defined for entire CDS or elements of a SELECT statement.
During activation, annotations get saved in System tables & their system classes are available to evaluate them. ABAP annotations are evaluated directly by ABAP runtime environment during activation.

When a CDS view is created
1.       a DDL SQL view gets created which is visible in SE11 but can’t be edited
2.       a CDS VIEW ENTITY gets created which is the DDL source file (Actual view)

S4HANA virtual data model used to define the type of views.

1.      Interface View/Basic View->Directly access a DB master data table, reused by other CDS
2.       Composite View->Use of association, the composition of basic and other composite views (Just a guideline or convention)

3.       Consumption View->These are accessible to end user, exposed to ODATA





Example Basic View
@AbapCatalog.sqlViewName: 'YSD4_AIR_TEXT'
@AbapCatalog.compiler.compareFilter: true
@AccessControl.authorizationCheck: #CHECK
@EndUserText.label: 'Airline Text CDS'
@VDM.viewType: #BASIC
@Analytics.dataCategory: #DIMENSION
@Analytics.dataExtraction.enabled : true
@ObjectModel.representativeKey: 'Airline'


define view YCDS_airlineTXT as select from scarr

{
key scarr.carrid as airline,
@Semantics.text:true
@EndUserText.label : 'Airline Name'
scarr.carrname as AirlineName
   
}
Example of Basic view with association

@AbapCatalog.sqlViewName: 'YSD4_AIRLINE'
@AbapCatalog.compiler.compareFilter: true
@AccessControl.authorizationCheck: #NOT_REQUIRED
@EndUserText.label: 'Airline CDS'
@ObjectModel.dataCategory: #TEXT
@Analytics.dataExtraction.enabled: true
@VDM.viewType: #BASIC
@ObjectModel.representativeKey: 'Airline'

define view YCDS_airline as select from scarr
association [0..1] to YCDS_airline as _text
on $projection.Airline = _text.Airline
{
key scarr.carrid as Airline,
@Semantics.currencyCode: true
scarr.currcode as AirlineLocalCurrency,
@Semantics.url:true
scarr.url as AirlineURI,
_text
   
}
Example of Consumption view
@AbapCatalog.sqlViewName: 'YSD4_CAIRLINE'
@AbapCatalog.compiler.compareFilter: true
@AccessControl.authorizationCheck: #NOT_REQUIRED
@EndUserText.label: 'Airline Consumption View'
@VDM.viewType: #CONSUMPTION
@OData.publish: true
define view YCDS_C_Airline as select from YCDS_airline {
    //YCDS_airline
    key Airline,
    AirlineLocalCurrency,
    AirlineURI,
    /* Associations */
    //YCDS_airline
    _text
}
Example of CDS with parameter
@AbapCatalog.sqlViewName:’DEMO_INPUT_CDS’
    Define view demo_parameters_cds
    With parameters p_country:LAND1_GP,  p_region:REGIO
    as Select from KNA1
        { key kunnr,
                land1 as Country key,
                name1,
                ort01 as City,
                region as Region
        } where land1 = : p_country and regio = : p_region;


No comments:

Post a Comment