Spotlight on parameterized ABAP CDS Views
I just want to put the light on a feature – in the context of advanced view building with ABAP Core Data Services (CDS) – that is available starting with AS ABAP 7.4 SP8: CDS views with input parameters.
Yes, as a developer, you can now parameterize your CDS views. It means you can define one general views which produce context-specific result sets by using parameter values passed at execution time. This means that you do no longer need to create a view for each context!
- Language filter in combination with associations
Instead of creating a a CDS view for each language, only one parameterized view is now needed. The specific language key value is passed at execution time.
- Calculation of sales tax
Instead of creating a a CDS view for each country with the specific value-added tax, only one parameterized view is now needed. The country-specific value-added tax is passed at execution time and used in the related arithmetic expressions.
Watch the compact video tutorial below. It shows how to create and call parameterized views in ABAP.
Note that CDS views with parameters are not supported on all SAP certified databases – At least SAP HANA does 🙂 . However, the DDL of the ABAP CDS allows creating and accessing CDS views with parameters independent of the database system.
In case an Open SQL statement SELECT is access such a parameterized view or a view that contains such a view as data source, but the accessed database system does not support them, a non-handleable exception of the class CX_SY_SQL_UNSUPPORTED_FEATURE is raised.
The recommended approach when using a database-specific features (e.g. views with parameters) in ABAP programs is to use the method USE_FEATURES of the class CL_ABAP_DBFEATURES to check whether the accessed database system supports it.**
|(**) Starting with AS ABAP 7.50, CDS views with parameters are supported on any DB. Thus, it is no longer needed to check whether the feature is supported or not, i.e. an alternative (fallback) implementation is no longer needed.|
IF abap_true = cl_abap_dbfeatures=>use_features(
VALUE #( ( cl_abap_dbfeatures=>views_with_parameters ) ) ).
“Call of CDS view with input parameters
FROM demo_iparameter_02( p_langu = @sy-langu,
p_saving_rate = ‘0.04’,
p_lc_status = @p_status )
INTO TABLE @DATA(lt_data).
value = lt_data
name = ‘Demo: CDS View with Input Parameters’ ).
cl_demo_output=>display( ‘Database system does not support views with parameters’ ).
Find more detailed information on this topic in the ABAP Keyword Documentation.