CDS view with association
2.Association in CDS view
- 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.
- 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.
- When ever we consume standard CDS view in our program we should go for association. Ex: to achieve F4 help(list of possible values).
- Standard CDS views starts with 'I_'
- All the association name should starts with '_'
- With the help of association we can expose one view with other view.
Code:
- @AbapCatalog.sqlViewName: 'ZSALORDER_ASSOV'
- @AbapCatalog.compiler.compareFilter: true
- @AbapCatalog.preserveKey: true
- @AccessControl.authorizationCheck: #CHECK
- @EndUserText.label: 'F4 help using std cds view'
- define view zsalesorder_association
- with parameters
- targer_currecny : abap.cuky,
- exchange_data : abap.dats
- as select from vbak as SalesHeader
- left outer join vbap as SalesItem on SalesHeader.vbeln = SalesItem.vbeln
- //Association with std cds view(I_material)
- association [1..*] to I_Material as _material on matnr = SalesItem.matnr
- {
- //Fields to be displayed in OP
- SalesItem.vbeln as SalesOrder,
- SalesItem.posnr as Item,
- SalesItem.erdat as OrderDate,
- SalesItem.matnr as Material,
- //Establishing FK
- @DefaultAggregation: #SUM
- @Semantics.amount.currencyCode: 'Currency'
- SalesItem.netwr as ActualPrice,
- @Semantics.amount.currencyCode:true
- SalesItem.waerk as Currency,
- concat(cast(SalesItem.netwr as abap.char( 20 )), SalesItem.waerk) as PriceCurrency,
- //Inbuild func for currency conversion
- currency_conversion( amount => SalesItem.netwr, source_currency => SalesItem.waerk, target_currency => $parameters.targer_currecny, exchange_rate_date => $parameters.exchange_data, exchange_rate_type => 'M' ) as ConvertedCurrency,
- //Exposing this cds view
- _material
- }
No comments:
Post a Comment