CDS Views

Association

  • Association is nothing but an on-demand/Lazy Join and is defined with Cardinality syntax.
  • Does not support with ABAP editor.
  • It is not a JOIN statement but we can join multiple tables.

Cardinality: [MIN...MAX] to define the association between entities in a CDS view

  • 0..1 - zero to one
  • 0..* - zero to many
  • 1..0 - one to zero
  • 1..* - one to many

@AbapCatalog.sqlViewName: 'zwm_sales_v'
@AbapCatalog.compiler.compareFilter: true
@AbapCatalog.preserveKey: true
@AccessControl.authorizationCheck: #CHECK
@EndUserText.label: 'sales info'
@ClientDependent: true
@OData.publish: true
 
define view zwm_cds_sales 
   with parameters p_vkorg : vkorg
   as select from vbak as header
   inner join vbap as items 
        on header.vbeln = items.vbeln
   association[1..*] to mara as _material
        on items.matnr = _material.matnr
   association[1..*] to makt as _text
        on items.matnr = _text.matnr
        and _text.spras = $session.system_language 

{
    key header.vbeln as SalesDoc,
        header.ernam,
        header.erdat,
        vbtyp,
        vkorg,
        header.netwr,
        header.waerk,
        case vbtyp
        when 'A' then 'Inquiry'
        when 'B' then 'Quotation'
        when 'C' then 'Order'
        else 'Others'
        end as Doc_Type,
        items.posnr,
        items.matnr,
        items.matkl,
        /* Associations */
        _material,
        _text

} where (vbtyp = 'A' or vbtyp = 'B' or vbtyp = 'C')
  and vkorg = $parameters.p_vkorg
  and header.netwr <> 0















Comments

Popular posts from this blog

Exception handing in OData

ALV reort using CL_SALV_TABLE