Skip to Content
Author's profile photo mpreddy mettu

ABAP CDS View with input parameters

ABAP CDS Views:


A CDS is defined for existing database tables and any other views or CDS Views in ABAP Dictionary using the statement DEFINE VIEW in the DDL in ABAP Core Data Services(CDS) . This is done in CDS Source code in the ABAP Development tools(ADT). Every CDS view has its own CDS Source code.

Two objects are created in ABAP Dictionary of Every CDS View:


  • CDS Database View : It is read-only classical database view in ABAP Dictionary.
  • CDS Entity: It is actual CDS view. It covers the CDS Database view and makes other attributes possible, such as authorization checks defined in CDS view

A CDS View has two types of keys:


  • For CDS Entities ,KEY can be used to define key elements, This Key is the semantic key of the CDS View
  • The key of the CDS database view is determined implicitly, as in a classical view. This key is a technical key of the CDS View.

ABAP CDS- DEFINE VIEW parameter list


Syntax:


…..WITH PARAMETERS pname1:parameter type,pname2…

Effect: Defines Input parameters pname1,pname2 in a CDS View in ABAP CDS in a comma separated list. Each input parameter must be typed with a data type parameter type.

.

Example:


The following CDS View has a list of two input parameters in the WHERE Clause of the SELECT statement.

@AbapCatalog.sqlViewName:’DEMO_INPUT_CDS’

    Define view demo_parameters_cds

    With parameters p_country:LAND1_GP,

                                p_region:REGIO

    as Select from KNA1

        { key kunnr,

                land1 as Country key,

                name1,

                ort01 as City,

                region as Region

        } where land1 = : p_country and regio = : p_region;

Steps to be shown in this document:

  1. Define input parameters in a CDS View
  2. Use input parameters in a CDS View.
  3. Define a View as a parameterized view.
  4. Call a parameterized view with open SQL.

1.Define input parameters in a CDS View.


  • Start ABAP in Eclipse
  • Right click on the package icon,and from the context menu select New->other ABAP repository object.

/wp-content/uploads/2016/06/image1_970113.jpg

/wp-content/uploads/2016/06/image2_970114.jpg

/wp-content/uploads/2016/06/image3_970145.jpg

/wp-content/uploads/2016/06/image4_970146.jpg

2.Use input parameters in a CDS View.


@AbapCatalog.sqlViewName:’ZCDS_DDL_IP1′

@EnduserTextLabel :’ABAP CDS View with input parameters’

Define view ZCDS_DD1_IP_TEST

    With parameters matnr:abap.numc(18),

                                Lang:abap.char(1)

  As select from mara as a

        inner join  makt as b

        on a.matnr = b.matnr

      {

        key a.matnr as material,

              b.maktx as description,

              $parameters.Lang as language

      } where a.matnr = $parameters.matnr and b.spras = $parameters.Lang;

image15.JPG

image17.JPG

 

3.Define a Parameterized view.


Shown the material description as per the language specified on input parameter.

/wp-content/uploads/2016/06/image5_970165.jpg

/wp-content/uploads/2016/06/image6_970169.jpg

image8.JPG

image7.JPG

4.Call a parameterized view with open SQL.

Define view ZCDS_DD1_IP_CALLCDS

    With parameters  matnr:abap.numc(18),

                                 Lang:abap.char(1)

     As select * from ZCDS_DD1_IP_TEST(matnr:$parameters.matnr,lang:$parameters.Lang)

imag11.JPG

image13.JPG

Reference Links:


https://scn.sap.com/thread/3682537

Assigned Tags

      15 Comments
      You must be Logged on to comment or reply to a post.
      Author's profile photo Former Member
      Former Member

      hi mpreddy,

          I did a test on the system, but there was a problem.

          .

      QQ截图20160616223238.png

      Author's profile photo Thomas Gauweiler
      Thomas Gauweiler

      Which version (ABAP, HANA, ADT) do you use?

      Author's profile photo mpreddy mettu
      mpreddy mettu
      Blog Post Author

      ADT version.JPG

      Author's profile photo Former Member
      Former Member

      TKS

      ABAP version 740 ,ADT version is the latest version

      May be the system database is not hana ?

      Author's profile photo Panneer Selvam
      Panneer Selvam

      What is the 7.40 SP Version in your system?

      Author's profile photo Former Member
      Former Member

      QQ截图20160630173750.png

      Author's profile photo Panneer Selvam
      Panneer Selvam

      This explains the reason for your error. CDS with input parameter is supported only from 7.40 SP8 onwards.

      Regards,

      Panneer

      Author's profile photo Former Member
      Former Member

      thank you

      Author's profile photo Venkatesh Veera
      Venkatesh Veera

      just give a try with colon(:) instead of dollar($) symbol.

      :lang as language

      } Where a.matnr = :matnr and b.spras = :lang

       

       

      Author's profile photo Former Member
      Former Member

           Can you please guide me, from which version of  BEx query designer, supports parameterized CDS view?

      Thanks,

      Tejaswini.

      Author's profile photo Former Member
      Former Member

      Hello experts,

      From which version of NW ABAP parameterized CDS views are supported as BEx queries?

      Thanks.

      Author's profile photo Former Member
      Former Member

      Hi,

      Is it possible that the parameters are displayed in Web Intelligence?

      Thanks

      Author's profile photo Sai Kowluri
      Sai Kowluri

      Can CDS views with parameters be used in JOIN conditions ?

      Author's profile photo mandar athavale
      mandar athavale

      Yes. It can be used. While defining join condition  itself, you need to pass required parameter to parameterized view.

       

      e.g.

      Define view abc with parameters

      p_abc : char4 as select .................

       

       

      Define view XYZ

      with parameters p_xyz:char4

      as select from ABC(p_abc:$parameters.p_xyz) inner join PQR on ABC.field1=PQR.field1

      {

      ABC.field1,

      PQR.field1

      }

       

       

      Hope this is what you were looking for.

      Author's profile photo Avinash Kumar
      Avinash Kumar

      Hello,

      Thanks for the information. Real good for the newbies to CDS Views.

      A query - We are using SAP Data Intelligence to extract data from S4 CDS. How can we use selection parameters to filter records while running the SQL query in CDS views?

      or how can we pass CDS View selection parameters to SAP Data Intelligence?

      Regards,

      Avinash