Skip to Content
0
Apr 23, 2018 at 08:28 PM

Anyone have a good work around for no parameters allowed in a HAVING clause?

96 Views

I can't dynamically pass a parameter to this HAVING clause. My use case is selecting all accounting documents that have a P&L impact above some threshold passed to the view. I need to later join this CDS View with another to pull additional details. Documentation says that I must use a literal. I tried with the parameter replacing one of the "50000" values below but it won't let me. I definitely don't want to pull back all documents and then do a filter. Much too expensive. Anyone have any ideas?

@AbapCatalog.sqlViewName: 'Y_PLN_AUDIT_CDS' @AbapCatalog.compiler.compareFilter: true

@AccessControl.authorizationCheck: #CHECK

@EndUserText.label: 'View for P&L account relevant documents'

define view y_pnl_audit with parameters

p_blart : blart //Document Type

// p_ksl : FINS_VKCUR12

as select from acdoca {

acdoca.belnr,

sum(acdoca.ksl) as pnl_amt }

where racct between '0000500000' and '0000899999' and //P&L Accounts

blart = :p_blart //Document Type

group by acdoca.belnr

having sum(acdoca.ksl) < -50000 or sum(acdoca.ksl) > 50000 //Greater than some threshold