Types of CDS view
Types of views
There are three types of views
- Basic view - used to write basic operation like select operation.
- Composite view - used to write all the business logics
- Consumption view - used to expose the view to outside environment
Note:
- @VDM.viewType: #BASIC
- @VDM.viewType: #COMPOSITE
- @VDM.viewType: #CONSUMPTION
code:
Basic view:
- @AbapCatalog.sqlViewName: 'ZSALESORDERV'
- @AbapCatalog.compiler.compareFilter: true
- @AbapCatalog.preserveKey: true
- @AccessControl.authorizationCheck: #CHECK
- @EndUserText.label: 'base view for sales order'
- @VDM.viewType: #BASIC
- //Join operaration
- define view zsalesorder_base
- as select from vbak as SalesHeader
- left outer join vbap as SalesItem on SalesHeader.vbeln = SalesItem.vbeln
- {
- //Fields to be displayed in OP
- SalesItem.vbeln as SalesOrder,
- SalesItem.posnr as Item,
- SalesItem.erdat as OrderDate,
- SalesItem.matnr as Material,
- //Sum operation using annotation
- @DefaultAggregation: #SUM
- //creating FK rel btw actualprice and currency field
- @Semantics.amount.currencyCode: 'Currency'
- SalesItem.netwr as ActualPrice,
- //currency field is key field for actual price
- @Semantics.amount.currencyCode:true
- SalesItem.waerk as Currency,
- //concatenate price and currecny unit field
- concat(cast(SalesItem.netwr as abap.char( 20 )), SalesItem.waerk ) as Price
- //Exposing this cds view
- }
Consumption view:
- @AbapCatalog.sqlViewName: 'ZSALORDER_CONSV'
- @AbapCatalog.compiler.compareFilter: true
- @AbapCatalog.preserveKey: true
- @AccessControl.authorizationCheck: #CHECK
- @EndUserText.label: 'Consumption view for sales order'
- @VDM.viewType: #CONSUMPTION
- @Analytics.query: true
- define view zsalesorder_consum
- with parameters
- //Annotation to default the value for parameter
- @Consumption.defaultValue: 'USD'
- target_currency : abap.cuky,
- //Annotation to default system date for parameter implementing consumption view
- @Environment.systemField: #SYSTEM_DATE
- exchange_date : abap.dats
- //implementing consumption view
- as select from zsalesorder_base
- {
- //Annotation for select option
- @Consumption.filter:{selectionType: #SINGLE, multipleSelections: true, mandatory: false}
- //Annotation to filter the fields on rsrt display
- @AnalyticsDetails.query.axis: #ROWS
- //Creating key field in consumption view using keyword 'key'
- key SalesOrder,
- @AnalyticsDetails.query.axis: #ROWS
- key Item,
- @AnalyticsDetails.query.axis: #ROWS
- OrderDate,
- Material,
- ActualPrice,
- Currency,
- Price,
- //Inbuild currency conversion func
- currency_conversion( amount => ActualPrice,
- source_currency => Currency,
- target_currency => $parameters.target_currency,
- exchange_rate_date => $parameters.exchange_date,
- exchange_rate_type => 'M' ) as ConvertedCurrency
- }
No comments:
Post a Comment