Skip to Content

Hi everyone!

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!

For example:

  1. 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.
  2. 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.

Example:

IF abap_true = cl_abap_dbfeatures=>use_features(
       requested_features =

         VALUE #( ( cl_abap_dbfeatures=>views_with_parameters ) ) ).
   “Call of CDS view with input parameters
     SELECT *
       FROM demo_iparameter_02( p_langu       = @sy-langu,
                                p_saving_rate = ‘0.04’,
                                p_lc_status   = @p_status )
       INTO TABLE @DATA(lt_data).

  cl_demo_output=>display_data(
    EXPORTING
      value = lt_data
      name  = ‘Demo: CDS View with Input Parameters’  ).
ELSE.
   “alternative implementation
cl_demo_output=>display( ‘Database system does not support views with parameters’ ).
ENDIF.

Find more detailed information on this topic in the ABAP Keyword Documentation.

To report this post you need to login first.

8 Comments

You must be Logged on to comment or reply to a post.

    1. Thomas Gauweiler

      You can use the usual WHERE conditions including select options when selecting from a view with parameters. But you cannot pass select options as parameters.

      Regards, Thomas

      (0) 
  1. Sigurður Njarðvík

    I did try to create the following Parameterized view on my system

    @AbapCatalog.sqlViewName: ‘zddl_table_info’

    @AbapCatalog.compiler.CompareFilter: true

    @AccessControl.authorizationCheck: #CHECK

    @EndUserText.label: ‘System Dictionary info for transparent tables’

    define view Zcds_Table_Info

        with parameters p_tabname:tabname //Data element from dictionary

    as

      select from dd03l as l  left outer join dd04t as t

          on l.rollname = t.rollname and t.ddlanguage = ‘E’

      left outer join dd03t as f  on l.fieldname = f.fieldname and f.tabname = l.tabname

      {

         key l.tabname as Tablename,

         key l.fieldname as Fieldname,

         l.position as Position,

         l.keyflag as Iskey,  

         l.rollname as Dataelement,

         l.domname as Domainname,

         l.datatype as Datatype,

         l.leng as Length,

         COALESCE ( t.ddtext, f.ddtext) as Description 

      }

       where l.tabname = :p_tabname

    But I cant run it I always get the following error

    SQL error “SQL code: 215 Parameters supplied for object

      ‘ZDDL_TABLE_INFO’ which is not a function. If the parameters are intended as

      a table hint, a WITH keyword is required.

    any idea on what is wrong here, the demo view demo_cds_parameters works fine on my system
    /wp-content/uploads/2016/01/cds_error_874213.png

    (0) 
    1. Sigurður Njarðvík

      Fixed it !

      I had to delete the view and create again with a new name, then it worked with unchanged code.

      Probably because it was first activated without a parameter defined

      (0) 
  2. Suresh Ganti

    Hi,

    Can you please let us know how to use an Select-Option and also using For ALL entries in the Where condition.

    Appreciate your inputs.

    Thanks,

    Suresh

    (0) 
    1. Thomas Gauweiler

      Select options and FOR ALL Entries are features of Open SQL and can only be used in a SELECT statement in ABAP code. It can not be used within a CDS view itself and you cannot pass them as parameters into a CDS view.

      You can use Select options and FOR ALL Entries only in the WHERE condition when selecting from a CDS view with parameters:

      SELECT * FROM cds_view( p = @simple_scalar_param )

      FOR ALL ENTRIES OF @itab

      WHERE f1 = @itab-f1

      AND f2 in @seltab_for_f2

      INTO …

      Regards, Thomas

      (0) 

Leave a Reply