1. Basic CDS View
This example defines a basic view on the sflight
table, selecting specific fields:
@AbapCatalog.sqlViewName: 'ZBASIC_CDS' @AccessControl.authorizationCheck: #CHECK define view Z_Basic_CDS_View as select from sflight { key carrid, key connid, fldate, price }
2. Composite CDS View with Join
This example joins the Z_Basic_CDS_View
with the scarr
table to combine flight data with carrier information:
@AbapCatalog.sqlViewName: 'ZCOMPOSITE_CDS' define view Z_Composite_CDS_View as select from Z_Basic_CDS_View as Basic inner join scarr as Carrier on Basic.carrid = Carrier.carrid { Basic.carrid, Carrier.carrname, Basic.connid, Basic.price }
3. Analytical CDS View with Aggregation
This example creates an analytical view with aggregation to calculate total sales per carrier and connection:
@Analytics.dataCategory: #CUBE define view Z_Analytical_CDS_View as select from Z_Composite_CDS_View { carrid, connid, price, sum(price) as total_sales } group by carrid, connid
4. Consumption CDS View with Filter
This example defines a consumption view that filters data for a specific carrier ('LH') and provides a pre-aggregated total_sales
measure:
@Consumption.defaultAggregation: #SUM define view Z_Consumption_CDS_View as select from Z_Analytical_CDS_View { carrid, connid, total_sales } where carrid = 'LH'
5. CDS View with UNION
This example combines data from two tables (sflight
and spfli
) using UNION
:
define view Z_Union_View as select from sflight { carrid, connid, cityfrom } union select from spfli { carrid, connid, cityfrom }
6. CDS View with Calculated Field
This example adds a calculated field (price_eur
) to the view:
define view Z_Calculated_Field_View as select from sflight { carrid, connid, price, price * 0.85 as price_eur // Calculated field (assuming 0.85 is the exchange rate) }
7. CDS View with Parameter
This example defines a parameter (p_carrid
) to filter data based on user input:
define view Z_Parameter_View with parameters p_carrid : String(3) as select from sflight { carrid, connid, fldate, price } where carrid = :p_carrid
8. CDS View Extension
This example extends the standard CDS view I_Product
to add a new field (LastUpdatedDate
):
extend view I_Product with Z_Product_Extension { @UI.hidden: true LastUpdatedDate }
9. CDS View with Access Control
This example uses the @AccessControl.authorizationCheck
annotation to restrict access to the view based on authorization:
@AccessControl.authorizationCheck: #CHECK define view Z_Restricted_View as select from sflight { carrid, connid, fldate, price }
These examples demonstrate the versatility of CDS views and how they can be used to model and expose data for different purposes. Remember to adapt these examples to your specific needs and data sources.
No comments:
Post a Comment