cancel
Showing results for 
Search instead for 
Did you mean: 

Difference between DEFINE VIEW and ENTITY statements (CDS-views)

Former Member
0 Kudos

Hi experts,

I am trying to learn how to work with CDS views and I don't exactly understand what we define with ENTITY statement.

As I understand with DEFINE VIEW we can create a CDS entity. But, then what we create with ENTITY statement. It is clear for me how it works when we write:


DEFINE VIEW <name> AS SELECT FROM <db_table>.

But in the internet I often saw the code like this:


ENTITY Employee

{

  name : String,

};

VIEW MyView AS SELECT FROM Employee

{

...
}

But I don't understnad in this case where we get the data? From which table? Can you please explain me how does it work in this case? And for what we need to define ENTITY if we can do the same it inside DEFINE VIEW statement?

Best Regards,

MIkhail

Accepted Solutions (1)

Accepted Solutions (1)

pfefferf
Active Contributor
0 Kudos

Hello Mihail,

with a CDS entity you define a database table. For each entity definition (design time) a db table (runtime) is generated.

The name of the table in the schema defined with annotation @SCHEMA is a concatenation of the package (in which the hdbdd file is stored), the (maybe) used context(s) within the hdbdd file and the entity name.

If you have e.g. following syntax in the hdbdd file


namespace test.db;

@Schema : 'MY_SCHEMA'

context data {

  @Catalog.tableType: #COLUMN

  entity testtab {

    key C1 : String(10);

    key C2 : String(10);

  };

}

in schema MY_SCHEMA a table "test.db::data.testtab" will be created, in which data can be persisted.

More information can be found in the CDS reference: http://help.sap.com/hana/SAP_HANA_Core_Data_Services_CDS_Reference_en.pdf

Best Regards,

Florian

Answers (0)