ABAP CDS View on HANA – Learn how to create them

5
81800

ABAP CDS view is used to define semantic data models on the standard database tables or dictionary views. A CDS view is defined with the statement DEFINE VIEW. In this ABAP on HANA tutorial, you will learn how to create ABAP CDS View 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 it.
  • 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 
{ * }
Activate the DDL Source

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

DDL Source and View

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

Open Data Preview

12. You will see the output like below with data retrieving from the CDS view.

Output

You have successfully created an ABAP CDS View on HANA. 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.

Thank you

Comments are closed.