How to create ABAP CDS Views on HANA

3
22632

Hello everyone in this ABAP on HANA tutorial you will learn how to create ABAP CDS Views on HANA. The abbreviation for CDS is Core Data Services. To know about ABAP CDS click here.

Prerequisites

  • You have installed Eclipse IDE( Kepler/Juno version )on your local machine.Click here to know more about.
  • You have installed ABAP Development Tools in Eclipse IDE.
  • You have access to ABAP Netweaver 7.4 on HANA.
  • You have created ABAP Project in eclipse to connect to ABAP Netweaver 7.4 system.Click here to know how to create ABAP Project.

Step-by-Step Procedure

1. Choose the package in which you want to create CDS Views. Right-click on the package → New → Other ABAP Repository Object.

New ABAP Repository Object

2. In the New ABAP Repository Object window, search for DDL source object by typing in search field.Select the DDL Source and hit Next.

Search for DDL Source

3. In the New DDL Source window, enter Name and Description of the CDS View and hit Finish.

Creat a DDL Source

4. A new CDS view editor opens up like below.

ABAP CDS View-0

5. Here we are going to retrieve the data from the table SNWD_PD using ABAP CDS View.Look at the DDL source we need to replace few values

  • Replace data_source_name with table name “SNWD_PD” from which you want to get the data.
  • Provide new value for @AbapCatalog.sqlViewName as “ZV_DEMO_01” .

6. Now the DDL source looks like below.

ABA CDS View-1

7. Lets look at the syntax for the CDS View.

Syntax

@AbapCatalog.sqlViewName: ‘CDS_DB_VIEW’
[@view_annot1]
[@view_annot2] …
[DEFINE] VIEW cds_entity [name_list] [parameter_list] AS select_statement [;]

In the first part of the syntax we declare annotations.

Annotation “@AbapCatalog.sqlViewName” is mandatory when creating CDS views, by which it creates a view in the Data Dictionary.

  • cds_entity – is the name of the view.
  • name_list – list of field names displayed in the output when we run the CDS view.
  • parameter_list – list of input parameters to the CDS view.
  • select_statement – is the select statement to be provided from table.

Full syntax documentation is available here.

8. Lets get back to our CDS view, here we are retrieving PRODUCT_ID, TYPE_CODE and CATEGORY from the table SNWD_PD. All the table fields will be entered inside the curly braces {   } in DDL source editor like below. Now the code look like below.

@AbapCatalog.sqlViewName: 'ZV_DEMO_01'
@ClientDependent: true
@AbapCatalog.compiler.CompareFilter: true
@EndUserText.label: 'Demo'
define view Zcds_Demo_Example1 as select from snwd_pd 
{
    product_id,
    type_code,
    category   
}

To access all field from the table.

@AbapCatalog.sqlViewName: 'ZV_DEMO_01'
@ClientDependent: true
@AbapCatalog.compiler.CompareFilter: true
@EndUserText.label: 'Demo'
define view Zcds_Demo_Example1 as select from snwd_pd 
{ * }

9. Do a syntax check by clicking on syntax button Syntaxin the toolbar and the active the DDL Source.
Activate the DDL Source10. Now a new ABAP DDL Source object will created and available under ABAP DDL Sources folder and also new dictionary view will be created along with it under Views folder.

DDL Source and View11. Right click on the newly created DDL source object and choose Open Data Preview to view the data.

Open Data Preview12. You will see the output like below with data retrieving from the CDS view.

Output

You have successfully created a ABAP CDS View.In our next tutorial we will know how to use these ABAP CDS view in ABAP programs/reports and also will have deep dive into full features of ABAP CDS views.

Please stay tuned to us for more ABAP on HANA and ABAP in Eclipse tutorials.Please feel free to comment and let us know your feedback. You feedback will keep us alive.

Thank you

  • Balta

    Hello,

    I dont see Core Data Service tab or DDL source field in Dictionary tab. I’m searching reason for this. I have ADT for Core in Eclipse :/

    • Indradeo Digumber

      Hello,

      Seems like it has now been renamed to “Data Definition” in the latest version of ADT.

  • Sukumar

    Hi Prakash,

    You are doing great job by sharing your knowledge and providing us a reference on topics.
    It would more please if you share your knowledge on XS OData programming ( DPC ext class).