Monday, June 13, 2022

4.Types of CDS view

 Types of CDS view

Types of views

There are three types of views
  1. Basic view - used to write basic operation like select operation. 
  2. Composite view - used to write all the business logics
  3. Consumption view - used to expose the view to outside environment 
Note:

  1. @VDM.viewType: #BASIC
  2. @VDM.viewType: #COMPOSITE
  3. @VDM.viewType: #CONSUMPTION
code:
    Basic view:

  1. @AbapCatalog.sqlViewName: 'ZSALESORDERV'
  2. @AbapCatalog.compiler.compareFilter: true
  3. @AbapCatalog.preserveKey: true
  4. @AccessControl.authorizationCheck: #CHECK
  5. @EndUserText.label: 'base view for sales order'
  6. @VDM.viewType: #BASIC
  7. //Join operaration
  8. define view zsalesorder_base
  9.   as select from    vbak as SalesHeader
  10.     left outer join vbap as SalesItem on SalesHeader.vbeln = SalesItem.vbeln
  11. {
  12.   //Fields to be displayed in OP
  13.   SalesItem.vbeln                         as SalesOrder,
  14.   SalesItem.posnr                         as Item,
  15.   SalesItem.erdat                         as OrderDate,
  16.   SalesItem.matnr                         as Material,
  17.   //Sum operation using annotation
  18.   @DefaultAggregation: #SUM
  19.   //creating FK rel btw actualprice and currency field
  20.   @Semantics.amount.currencyCode: 'Currency'
  21.   SalesItem.netwr                         as ActualPrice,
  22.   //currency field is key field for actual price
  23.   @Semantics.amount.currencyCode:true
  24.   SalesItem.waerk                         as Currency,
  25.   //concatenate price and currecny unit field
  26.   concat(cast(SalesItem.netwr as abap.char( 20 )), SalesItem.waerk ) as Price
  27.   //Exposing this cds view
  28. }

    Consumption view:

  1. @AbapCatalog.sqlViewName: 'ZSALORDER_CONSV'
  2. @AbapCatalog.compiler.compareFilter: true
  3. @AbapCatalog.preserveKey: true
  4. @AccessControl.authorizationCheck: #CHECK
  5. @EndUserText.label: 'Consumption view for sales order'
  6. @VDM.viewType: #CONSUMPTION
  7. @Analytics.query: true
  8. define view zsalesorder_consum
  9.   with parameters
  10.     //Annotation to default the value for parameter
  11.     @Consumption.defaultValue: 'USD'
  12.     target_currency : abap.cuky,
  13.     //Annotation to default system date for parameter implementing consumption view
  14.     @Environment.systemField: #SYSTEM_DATE
  15.     exchange_date   : abap.dats
  16.   //implementing consumption view
  17.   as select from zsalesorder_base
  18. {
  19.   //Annotation for select option
  20.   @Consumption.filter:{selectionType: #SINGLE, multipleSelections: true, mandatory: false}
  21.   //Annotation to filter the fields on rsrt display
  22.   @AnalyticsDetails.query.axis: #ROWS
  23.   //Creating key field in consumption view using keyword 'key'
  24.   key SalesOrder,
  25.   @AnalyticsDetails.query.axis: #ROWS
  26.   key Item,
  27.       @AnalyticsDetails.query.axis: #ROWS
  28.       OrderDate,
  29.       Material,
  30.       ActualPrice,
  31.       Currency,
  32.       Price,
  33.       //Inbuild currency conversion func
  34.       currency_conversion( amount => ActualPrice,
  35.                            source_currency => Currency,
  36.                            target_currency => $parameters.target_currency,
  37.                            exchange_rate_date => $parameters.exchange_date,
  38.                            exchange_rate_type => 'M' ) as ConvertedCurrency
  39. }

No comments:

Post a Comment

5.F4 help and Select option in CDS view.

F4 help and Select option in CDS view  F4 Help implementation Using Association Using Basic and Consumption view Code: Basic view: @AbapCata...