Skip to Content
avatar image
Former Member

Is WHERE clause on field derived with Coalesce function a good practice ?

I have the following CDS. In my ABAP program would it be a good practice to write a query with only one WHERE condition on BSTKD (no other fields) OR would it just be better to write a query that starts with VBKD as the left most table.

define view Zcdsv_So_Cus_Po as 
select from vbap as Item inner join vbak as Head
    on Head.vbeln = Item.vbeln
association to vbkd as _to_vbkd
    on $projection.vbeln = _to_vbkd.vbeln 
association to vbpa as _to_vbpa
    on $projection.vbeln = _to_vbpa.vbeln  
{
    key Item.vbeln,
    key Item.posnr,
    Item.posex,
    Head.auart,
    Head.vkorg,
    Head.vtweg,
    Head.kunnr,
    Head.gbstk,
    coalesce( _to_vbkd[  posnr = $projection.posnr ].bstkd, _to_vbkd[ 1: inner where posnr = '000000' ].bstkd ) as bstkd,
    coalesce( coalesce( _to_vbpa[ posnr = $projection.posnr and parvw = 'ZZ' ].kunnr, _to_vbpa[ posnr = '000000' and parvw = 'ZZ' ].kunnr ), kunnr ) as endCustomer
    
} 
Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

1 Answer

  • Jul 25, 2017 at 08:30 PM

    In general, I'd probably say it's not a good idea but looking at this particular situation - you don't really have much choice. How would you use VBKD here? You'd probably end up reading some redundant data.

    As a side note - I really don't like the way VBKD and VBPA are designed in SAP. Hope they'll find a better option in S/4.

    Add comment
    10|10000 characters needed characters exceeded