Sunday, June 12, 2022

3.CDS view with association

 CDS view with association

2.Association in CDS view

  1. Associations is nothing but joins, but these are on demand select. ie.. if we establish association between vbak and vbap, associations will be triggers only if we use any of the fields of vbap in our CDS view or else associations will not be triggered.
  2. We can define any number of association in our CDS view, but it will be triggered only if we used the fields in our CDS view. 
  3. When ever we consume standard CDS view in our program we should go for association. Ex: to achieve F4 help(list of possible values).
  4. Standard CDS views starts with 'I_'
  5. All the association name should starts with '_'
  6. With the help of association we can expose one view with other view.
Code:

  1. @AbapCatalog.sqlViewName: 'ZSALORDER_ASSOV'
  2. @AbapCatalog.compiler.compareFilter: true
  3. @AbapCatalog.preserveKey: true
  4. @AccessControl.authorizationCheck: #CHECK
  5. @EndUserText.label: 'F4 help using std cds view'
  6. define view zsalesorder_association
  7.   with parameters
  8.     targer_currecny : abap.cuky,
  9.     exchange_data   : abap.dats
  10.   as select from    vbak as SalesHeader
  11.     left outer join vbap as SalesItem on SalesHeader.vbeln = SalesItem.vbeln
  12.   //Association with std cds view(I_material)
  13.   association [1..*] to I_Material as _material on matnr = SalesItem.matnr
  14. {
  15.   //Fields to be displayed in OP
  16.   SalesItem.vbeln                         as SalesOrder,
  17.   SalesItem.posnr                         as Item,
  18.   SalesItem.erdat                         as OrderDate,
  19.   SalesItem.matnr                         as Material,
  20.  
  21.   //Establishing FK
  22.   @DefaultAggregation: #SUM
  23.   @Semantics.amount.currencyCode: 'Currency'
  24.   SalesItem.netwr                         as ActualPrice,
  25.   @Semantics.amount.currencyCode:true
  26.   SalesItem.waerk                         as Currency,
  27.   concat(cast(SalesItem.netwr as abap.char( 20 )), SalesItem.waerk) as PriceCurrency,
  28.  
  29.   //Inbuild func for currency conversion
  30.   currency_conversion( amount => SalesItem.netwr, source_currency => SalesItem.waerk, target_currency => $parameters.targer_currecny, exchange_rate_date => $parameters.exchange_dataexchange_rate_type => 'M' )             as ConvertedCurrency,
  31.   //Exposing this cds view
  32.   _material
  33. }

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...