A CDS table entity defines a database table as an ABAP-managed database object. These are similar to DDIC based transparent tables. Table entities support relationship modeling with CDS associations, semantic metadata with CDS annotations, and typing with both CDS Simple Types and Enumerated Types.
CDS Table Entity : Usage
- Read and write access is possible using ABAP SQL SELECT, UPDATE, MODIFY, INSERT, and DELETE.
- A table entity can be used as a data type in ABAP.
- Restriction: The ABAP RESTful Application Programming Model does not support CDS table entities currently. But it will definitely be available in future releases. (This is my view)
CDS Table Entity : Syntax
// optional header annotations define [root] table entity entity_name { [field] [association] [optional element annotations] }
Properties of Table Entities
Key Fields – You can define one or more elements as the primary key using the keyword KEY. However, unlike database tables, key fields are optional and it is also possible to have a table entity without a primary key.
Note: The access pattern of a table entity without a primary key is that it is always read completely, which can result in longer processing times. Single record access is not provided.
Client Dependency
Client handling is defined using the header annotation @ClientHandling.type. The possible annotation values are #CLIENT_DEPENDENT or #CLIENT_INDEPENDENT.
Flag for Null Values
A null value on the database is an undefined value. Columns of table entities are by default created as NOT NULL on the SAP HANA database. It is possible to override this default behavior by using the optional addition NULL for a column.
Delivery Class
The delivery class of a table entity controls the transport of table data in installations, upgrades, or client copies, and in transports between customer systems. Annotation @AbapCatalog.deliveryClass is used to specify delivery class.
Annotation Value | Meaning |
---|---|
#APPLICATION_DATA | Master data and Transaction data |
#CUSTOMIZING_DATA | Customizing customer data |
#LOCAL_DATA | Table for local data |
Apart from these, we also have #SYSTEM_DATA, #SYSTEM_ADMINISTRATIVE_DATA and #SYSTEM_EDITABLE_DATA but these are used by SAP.
Note: Similar to DDIC table, when data exists and client handling is changed, the existing content must be adjusted on the database. Same is true for scenarios when key fields are added, or when changing the technical properties of table fields, such as changing the data type, or removing the flag for null values.
Enough of theory, now let us create a CDS Table Entity.
1. Right click on the package, and choose New > Other ABAP Repository Object.

2. Chose Data Definition from Core Data Services node

3. Provide Name and Description, click Next, provide a TR, and then click Next again.

4. Choose Template defineTableEntity
from the list and click Finish.

5. Complete the entity with the below code and Activate.
@ClientHandling.type: #CLIENT_DEPENDENT
@AbapCatalog.deliveryClass: #APPLICATION_DATA
@AccessControl.authorizationCheck: #NOT_REQUIRED
@EndUserText.label: 'Table Entity Demo'
define table entity ZJP_CDS_Table_Entity
{
key travel_id : /dmo/travel_id;
key booking_id : /dmo/booking_id;
booking_date : abap.datn;
customer_id : /dmo/customer_id;
carrier_id : /dmo/carrier_id;
connection_id : /dmo/connection_id;
flight_date : abap.datn ;
@Semantics.amount.currencyCode : 'currency_code'
flight_price : /dmo/flight_price;
currency_code : /dmo/currency_code;
number_flag : abap.int2 null;
}

Data added to the table entity will appear as below.

Code reference to add data to the table
CLASS zjp_book_data DEFINITION
PUBLIC
FINAL
CREATE PUBLIC .
PUBLIC SECTION.
INTERFACES if_oo_adt_classrun.
ENDCLASS.
CLASS zjp_book_data IMPLEMENTATION.
METHOD if_oo_adt_classrun~main.
DELETE FROM ZJP_CDS_Table_Entity.
INSERT ZJP_CDS_Table_Entity FROM (
SELECT FROM /dmo/booking
FIELDS
travel_id AS travel_id,
booking_id AS booking_id,
booking_date AS booking_date,
customer_id AS customer_id,
carrier_id AS carrier_id,
connection_id AS connection_id,
flight_date AS flight_date,
flight_price AS flight_price,
currency_code AS currency_code
ORDER BY booking_id
UP TO 10 ROWS ).
COMMIT WORK.
out->write( 'Booking data inserted' ).
ENDMETHOD.
ENDCLASS.
The table entity can be used in SELECT queries similar to DDIC table.
SELECT * FROM ZJP_CDS_Table_Entity INTO TABLE @DATA(lt_tab).

Important: The CDS table entities are not yet available to be used in ABAP RAP, and unless they are available, it will not be as useful.
Visit ABAP on HANA series for Tutorials on CDS, AMDP, Eclipse, and ALV IDA.
If you like the content, please subscribe…