nHow to pass dynamic values on the fly to CDS in SAP ABAP

While CDS (Core Data Services) views in SAP ABAP don't directly support passing dynamic values at runtime, there are several workarounds to achieve similar functionality depending on your specific use case.

Limitations of Dynamic Values in CDS

CDS views are compiled artifacts that cannot accept dynamic parameters like traditional ABAP methods. However, you can work around this limitation using the following approaches −

Method 1: Using DCL (Data Control Language) with Authority Objects

For authorization-based filtering, you need to declare and define the authority object in your DCL. This allows the system to automatically filter data based on user authorizations −

@EndUserText.label: 'Access Control for Sales Data'
@MappingRole: true
define role ZC_SALES_DATA_ACCESS {
    grant select on ZC_SALES_DATA
        where (CompanyCode) = aspect pfcg_auth (F_BKPF_BUK, BUKRS, ACTVT = '03');
}

Method 2: Filtering at Gateway Layer

If DCL cannot be implemented, you can retrieve all results from the CDS view and apply filtering logic in the Gateway layer using ABAP code −

DATA: lt_sales_data TYPE TABLE OF zc_sales_data,
      lv_company_code TYPE bukrs.

" Get all data from CDS view
SELECT * FROM zc_sales_data INTO TABLE lt_sales_data.

" Apply dynamic filtering
lv_company_code = '1000'.
DELETE lt_sales_data WHERE company_code NE lv_company_code.

Method 3: Using Parameters in Consumption Layer

Create parameterized CDS views that accept input parameters, then consume them in your ABAP program −

@AbapCatalog.viewEnhancementCategory: [#NONE]
define view ZC_SALES_PARAM 
  with parameters P_CompanyCode : bukrs
  as select from vbak
{
  vbeln,
  bukrs_vf
}
where bukrs_vf = $parameters.P_CompanyCode

Then consume it in ABAP −

SELECT * FROM zc_sales_param( P_CompanyCode = '1000' )
  INTO TABLE @DATA(lt_result).

While direct dynamic value passing isn't supported in CDS views, these methods provide flexible alternatives to achieve dynamic filtering based on your specific requirements.

Updated on: 2026-03-13T20:56:03+05:30

1K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements