CDS

ABAP CDS with parameter

Let’s check an example of CDS with parameters and how they can be called from the program.

@AbapCatalog.sqlViewName: 'ZCDSPARAM'
@AbapCatalog.compiler.compareFilter: true
@AccessControl.authorizationCheck: #CHECK
@EndUserText.label: 'Example of CDS with Parameters'

define view ZCDS_PARAMETERS
with parameters p_lang  :spras
as select from t023t {
    key t023t.matkl,
        t023t.wgbez60,
        t023t.spras
}
where t023t.spras = :p_lang

How to do select using such CDS view.

SELECT * FROM zcds_parameters( p_lang = 'E' )
  INTO TABLE @DATA(it_TAble1).

If you want to use the CDS with a parameter for fetching data/doing some calculation in another CDS view, the higher level CDS also need to have the same parameter. It is not a technical requirement, rather a logical one.

@AbapCatalog.sqlViewName: 'ZCDSPARAMC'
@AbapCatalog.compiler.compareFilter: true
@AbapCatalog.preserveKey: true
@AccessControl.authorizationCheck: #CHECK
@EndUserText.label: 'Example of CDS with select from CDS with parameter'

define view zCDS_parameter_call 
with parameters p_lang1  :spras
as select from ZCDS_PARAMETERS( p_lang: $parameters.p_lang1 ) { 
 key    matkl as MaterialGroup,       
        wgbez60 as Description
}

Leave a Reply

Your email address will not be published. Required fields are marked *

error

Enjoy this blog? Please spread the word :)

Follow by Email
Twitter
LinkedIn
LinkedIn
Share