Table Functions, Hierarchies, Custom Entities and Aspects

This content was generated with the assistance of AI and should be verified against the official documentation before being relied on in production.

A plain ABAP CDS view reads database tables and shapes the result. Sometimes that is not enough. You may need a calculation that only the database can do, a tree of parents and children, data that does not come from a table at all, a description of a structure that is never stored, a bundle of fields that many views should share, or rows that live in another database. ABAP CDS has a special kind of entity for each of these needs: the table function, the hierarchy, the custom entity, the abstract entity, the aspect and the external entity. After reading this page you can say what each one is for, read the definition of each, tell which of them create something in the database and which exist only as a description, and look up in the feature tables since which release a keyword works. The page is written against Standard ABAP release 8.16 and ABAP for Cloud Development release 9.20 (2608). The six kinds do not all work in every edition: table functions are listed only for Standard ABAP (on premise), and the section on the feature tables shows how to check this yourself. Every definition below needs an SAP system to be activated, so those listings are labelled "requires an SAP system; not run here". One plain-ABAP listing, which shows what a hierarchy computes, was run in the local lab of this documentation set.

Before you read

  • Native SQL, ADBC and AMDP: a table function is implemented by an AMDP method, so read how AMDP classes and SQLScript methods work first.

  • ABAP for SAP HANA and Code Pushdown: why work is moved into the database, and the order ABAP SQL, then CDS, then AMDP.

  • Internal Tables: the hierarchy example holds its nodes in one.

  • DDIC Tables and Structures: the database tables that these entities read.

  • Plain CDS view entities, associations and annotations have pages of their own that come earlier in this section; this page assumes you know what a CDS view entity is.

Key terms

  • CDS table function: a CDS entity whose rows are produced by a database function that is written in SQLScript inside an ABAP class.

  • CDS hierarchy: a CDS entity that turns rows with a parent column into a tree and adds columns such as the level of each node.

  • CDS custom entity: a CDS entity that only describes a result; an ABAP class provides the rows when a framework asks for them.

  • CDS abstract entity: a CDS entity that only describes a structure and has neither data nor a database object.

  • CDS aspect: a named set of elements that several CDS view entities can reuse.

  • CDS external entity: a CDS entity that reads data from a table in another database.

  • Feature table: the page of the Keyword Documentation that lists every CDS language element with the release in which it appeared.

  • Client safety: the guarantee that a statement reads the data of the current client only.

One family, two groups

All six are CDS entities: each has a name, a list of elements, and a structured type that ABAP programs can use after the word TYPE. They differ in what the system builds when you activate them, and that decides where you may use them.

  • A table function is a CDS SQL entity: the system creates a function in the database. Its rows are computed by the database every time it is read, so you can read it in ABAP SQL and use it as a data source of other CDS entities.

  • A hierarchy and an external entity are persistent entities: a hierarchy creates a database view on top of a hierarchy function, and an external entity is a window onto a table of another database. You can read both with ABAP SQL.

  • A custom entity and an abstract entity are transient entities: activation stores only their metadata. Nothing is created in the database, so neither can be a data source of a SELECT.

  • An aspect creates only a runtime artifact. No view exists in the database, and no SELECT can read it.

flowchart TD A[ABAP CDS special entities] --> B{What does activation create?} B -- A database function --> C[Table function: read with ABAP SQL, data source of CDS entities] B -- A database view over a hierarchy function --> D[Hierarchy: read with ABAP SQL, SAP HANA only] B -- Access to another database --> E[External entity: read with ABAP SQL, optionally writable] B -- Metadata only --> F[Custom entity: an ABAP class supplies the rows] B -- Metadata only --> G[Abstract entity: a pure type description] B -- A runtime artifact only --> H[Aspect: reusable elements for view entities]

The feature tables: which release can do what

Every CDS language element was introduced in some release, and the editions of ABAP do not receive them at the same time. The Keyword Documentation therefore has a page named "ABAP CDS - Feature Tables" that lists, for every keyword and addition, the release in four columns: the quarterly release of ABAP Cloud (a number such as 9.12), the release of Standard ABAP on premise (such as 8.16), the SAP BTP ABAP environment and SAP S/4HANA Cloud Public Edition (both give a four-digit year-and-month release such as 2408). A dash means that the element is not available in that edition. The table below copies the line that defines each of our six kinds from that page, read on 2026-11-13.

Language element ABAP Cloud quarterly Standard ABAP on premise SAP BTP ABAP environment S/4HANA Cloud Public Edition

DEFINE TABLE FUNCTION

7.61

7.50

-

-

DEFINE HIERARCHY

7.73

7.53

1808

1808

DEFINE CUSTOM ENTITY

7.75

7.54

1902

1902

DEFINE ABSTRACT ENTITY

7.70

7.53

1711

1711

DEFINE ASPECT, BIND ASPECT, INCLUDE ASPECT

9.12

8.16

2408

2408

DEFINE EXTERNAL ENTITY

9.12

8.16

2408

2408

Reading the table gives three facts you need in practice. First, hierarchies, custom entities and abstract entities are old and available everywhere. Second, aspects and external entities are the newest kinds and arrived in Standard ABAP with release 8.16, which is the baseline of this page. Third, the dashes on the table function line mean that the feature table lists no release for the BTP ABAP environment and the Public Edition. Other pages of the Keyword Documentation still describe table functions for ABAP for Cloud Development, for example by saying that their checks apply when the table function has the ABAP language version "ABAP for Cloud Development". Because the two statements sit side by side in the documentation, check a table function against the system you build for before you plan around it, and treat the feature table as the quick answer.

Some additions arrived later than the keyword itself. The table lists the following for external entities, and they show how to read a row. DEFINE EXTERNAL ENTITY and WITH FEDERATED DATA appear in 9.12 and 8.16. WRITABLE appears in 9.14 and 8.16. PROVIDED BY for a static external entity appears in 9.16 and 8.16. The keywords ROOT, ASSOCIATION, COMPOSITION and ASSOCIATION TO PARENT on an external entity appear in 9.18, which reaches Standard ABAP on premise only in release 8.24, so they are not part of 8.16. The newest row among the six kinds is DEFAULT on an external entity element in 9.20, in Standard ABAP 8.24 and in the BTP ABAP environment and Public Edition release 2608. The release news for 9.20 names this as the only CDS change of that release.

Older books on ABAP for SAP HANA show table functions and views written for ABAP 7.4 and 7.5. They predate hierarchies in their current form, aspects, external entities and the client-safety annotation described below, so use the Keyword Documentation for anything newer than those releases.

Table functions

A table function lets you use a calculation that CDS cannot express but SAP HANA can, such as a long SQLScript query with several steps, and use its result like a view. It has two halves. The first half is the definition in CDS: it names the input parameters, lists the columns of the result and says which ABAP method fills them. The second half is an AMDP method, a method of an ABAP class whose body is written in SQLScript and runs inside the database. The Keyword Documentation describes the CDS entity as a structured type, the AMDP method as its implementation, and states that CDS table functions can only be used in a database system that supports AMDP, which today means SAP HANA.

Our running example is the expense claim system. The table ZEXP_ITEM holds the items of each claim. The table function below returns the total of each claim, and only the claims whose total reaches a limit that the caller passes in. The annotations @ClientHandling.type: #CLIENT_DEPENDENT and @ClientHandling.algorithm: #SESSION_VARIABLE make the function client-safe, which means the database itself keeps the rows of other clients out of the result. The result carries a client column and the function has no client parameter. Requires an SAP system; not run here.

@AccessControl.authorizationCheck: #NOT_REQUIRED
@EndUserText.label: 'Claim totals above a limit'
@ClientHandling.type: #CLIENT_DEPENDENT
@ClientHandling.algorithm: #SESSION_VARIABLE
define table function ZEXP_TF_CLAIM_TOTAL
  with parameters
    p_min : abap.int4
  returns
  {
    client   : abap.clnt;
    claim_id : abap.char(10);
    total    : abap.int4;
  }
  implemented by method zcl_exp_claim_total=>get_totals;

Source: CDS DDL - DEFINE TABLE FUNCTION; the shape follows its client-dependent example

The second half is the class. It implements the marker interface IF_AMDP_MARKER_HDB, which tells ABAP that the class holds methods for SAP HANA. The method is declared with CLASS-METHODS ... FOR TABLE FUNCTION and has no parameter list of its own, because the interface is generated from the table function: the input parameter p_min keeps its name and the result is a table named result. The declaration must stand in the public section of the class. The body is written with BY DATABASE FUNCTION FOR HDB LANGUAGE SQLSCRIPT OPTIONS READ-ONLY, and every database table that the SQLScript reads is listed after USING. Inside the body you refer to an input parameter with a colon, :p_min. The body ends with a RETURN of one query. Requires an SAP system; not run here.

CLASS zcl_exp_claim_total DEFINITION PUBLIC FINAL CREATE PUBLIC.
  PUBLIC SECTION.
    INTERFACES if_amdp_marker_hdb.
    CLASS-METHODS get_totals FOR TABLE FUNCTION zexp_tf_claim_total.
ENDCLASS.

CLASS zcl_exp_claim_total IMPLEMENTATION.
  METHOD get_totals BY DATABASE FUNCTION
                    FOR HDB
                    LANGUAGE SQLSCRIPT
                    OPTIONS READ-ONLY
                    USING zexp_item.
    RETURN SELECT mandt AS client,
                  claim_id,
                  SUM( amount ) AS total
             FROM zexp_item
            GROUP BY mandt, claim_id
           HAVING SUM( amount ) >= :p_min
            ORDER BY mandt, claim_id;
  ENDMETHOD.
ENDCLASS.

An ABAP program reads the table function like a view and gives the parameter in parentheses. The pragma ##db_feature_mode[amdp_table_function] acknowledges that the statement needs a database feature, because only some databases can run it. Requires an SAP system; not run here.

SELECT claim_id, total
  FROM zexp_tf_claim_total( p_min = 100 )
  INTO TABLE @DATA(big_claims)
  ##db_feature_mode[amdp_table_function].

LOOP AT big_claims INTO DATA(big_claim).
  WRITE / |{ big_claim-claim_id } { big_claim-total }|.
ENDLOOP.

The rules that the Keyword Documentation gives decide how to work with a table function.

  • Order of creation. The CDS entity must be activated first and the class afterwards, because the AMDP function implementation can only be linked to a table function that is already active. Until the class exists, the database holds an empty function that raises an exception when anything other than the AMDP framework reads it.

  • Transport. A transport moves the CDS entity first, with the dictionary objects, and the class later, with the ABAP objects. In between, the table function is not usable.

  • One to one. An AMDP function implementation can implement exactly one table function, and a table function names exactly one method.

  • Not a method call. You cannot call the AMDP function like an ordinary method in ABAP. You read the CDS entity with ABAP SQL, or call the function from another AMDP method.

  • No buffer. ABAP SQL does not serve a table function from the table buffer or from its in-memory engine, and a statement can send at most one internal table to the database through FROM @itab.

  • Client handling. A table function is client-dependent by default. The annotation @ClientHandling.clientSafe makes a client-dependent function explicitly client-safe and switches on the checks: the function must use the two client annotations shown above, must not have a parameter of the type CLNT, and must not use the client system field as a parameter. Release 8.16 introduced this annotation. The result row of the AMDP method does not contain a client field, although the CDS element list must declare one.

  • Read only. The only option that AMDP allows today for such a function is READ-ONLY.

sequenceDiagram participant Dev as Developer participant CDS as CDS table function participant Cls as AMDP class participant ABAP as ABAP SQL SELECT participant HANA as SAP HANA Dev->>CDS: 1. Activate DEFINE TABLE FUNCTION CDS->>HANA: Creates an empty function that raises an exception Dev->>Cls: 2. Activate the class with FOR TABLE FUNCTION ABAP->>CDS: 3. SELECT FROM the table function CDS->>Cls: First read: AMDP implements the function in the database HANA-->>ABAP: SQLScript runs next to the data and returns the rows

A table function is different from a CDS scalar function. A scalar function returns one value and sits wherever a built-in function would, for example in a select list. A table function returns a table and sits where a data source would. Both are implemented by an AMDP method. Use a table function only when plain CDS cannot do the job, in line with the order ABAP SQL, then CDS, then AMDP.

Hierarchies

Many business data are trees. A cost centre belongs to a parent cost centre, which belongs to another, up to the company. In a table such a tree is stored as rows that each name their parent. A CDS hierarchy turns these rows into a tree: it walks from the root nodes down, puts the children of each node in a stated order, and adds extra columns, the hierarchy attributes, that say where each row sits in the tree.

To define a hierarchy you need three objects. The first is a database table with the parent-child rows. The second is a CDS view entity on that table that has a self-association, an association to itself, which names the parent of each row. It is called the hierarchy association. The third is the hierarchy, defined with DEFINE HIERARCHY. The keyword documentation states the rules for the hierarchy association: it must be a self-association, its ON condition may only use = comparisons joined by AND, and the source of the hierarchy must expose it. The following two definitions model the cost centres of the company, one row per cost centre with its parent. Requires an SAP system; not run here.

@AccessControl.authorizationCheck: #NOT_REQUIRED
define view entity ZEXP_I_COSTCENTER_SRC
  as select from zexp_cost_center
  association to exact one ZEXP_I_COSTCENTER_SRC as _Parent
    on $projection.Parent = _Parent.Id
{
  _Parent,
  key id        as Id,
      parent_id as Parent,
      name      as Name
}
define hierarchy ZEXP_H_COSTCENTER
  with parameters
    p_root : abap.char(4)
  as parent child hierarchy(
    source ZEXP_I_COSTCENTER_SRC
    child to parent association _Parent
    start where Id = :p_root
    siblings order by Id ascending
  )
  {
    Id,
    Parent,
    Name,
    $node.hierarchy_level as Level
  }

Source: CDS DDL - DEFINE HIERARCHY; both definitions follow the pattern of its simple example

In the second listing, source names the view entity, child to parent association names its self-association, start where selects the root nodes (here the one given by the parameter), and siblings order by fixes the order of the children of one node. The element $node.hierarchy_level as Level lists a hierarchy attribute. The prefix $node. is how a hierarchy attribute is named in the element list.

The hierarchy attributes are extra information per row. HIERARCHY_RANK is a sequence number that identifies the node. HIERARCHY_TREE_SIZE is the number of descendants, counting the node itself. HIERARCHY_PARENT_RANK is 0 for a root node and otherwise the rank of the parent. HIERARCHY_LEVEL is 1 for a root node and the distance from the root plus one for the others. HIERARCHY_IS_CYCLE and HIERARCHY_IS_ORPHAN flag nodes that are part of a cycle or have no parent that exists. NODE_ID and PARENT_ID are the internal keys of the node and its parent.

An ABAP program reads the hierarchy with ABAP SQL, passes the parameter, and may select the hierarchy columns by name, whether or not they are in the element list. Requires an SAP system; not run here.

SELECT FROM zexp_h_costcenter( p_root = 'C100' )
  FIELDS id, name, hierarchy_level, hierarchy_tree_size
  INTO TABLE @DATA(nodes).

Some restrictions come with hierarchies. They can currently be used only when the standard database is SAP HANA. A hierarchy cannot be the source of another hierarchy. A hierarchy attribute becomes part of the structured type of the hierarchy only if you list it in the element list. No dictionary object is created for a hierarchy, so it cannot type a dictionary object. Hierarchies are not processed by the ABAP SQL in-memory engine, and an access bypasses the table buffer. Hierarchies generated with a start where condition are buffered in the database, so for a large hierarchy of slowly changing data the documentation advises fixed root nodes instead of arbitrary parameters.

To see what the hierarchy computes without an SAP system, the next program does the same walk with an internal table in plain ABAP: it starts at the nodes without a parent, takes the siblings in ascending order of the key, and writes the level of each node. It is an illustration of the idea, not a CDS hierarchy, and it uses a recursive method. It ran in the local lab. The first number of each line is the depth, counted from 0 (the level of a CDS hierarchy counts from 1).

REPORT zexp_tree.

TYPES: BEGIN OF ty_node,
         id     TYPE c LENGTH 4,
         parent TYPE c LENGTH 4,
         name   TYPE string,
       END OF ty_node,
       ty_nodes TYPE STANDARD TABLE OF ty_node WITH DEFAULT KEY.

CLASS lcl_tree DEFINITION.
  PUBLIC SECTION.
    METHODS constructor IMPORTING nodes TYPE ty_nodes.
    METHODS walk IMPORTING parent TYPE ty_node-parent
                           depth  TYPE i.
  PRIVATE SECTION.
    DATA nodes TYPE ty_nodes.
ENDCLASS.

CLASS lcl_tree IMPLEMENTATION.
  METHOD constructor.
    me->nodes = nodes.
    SORT me->nodes BY id ASCENDING.
  ENDMETHOD.

  METHOD walk.
    LOOP AT nodes INTO DATA(node) WHERE parent = parent.
      DATA(indent) = repeat( val = `  ` occ = depth ).
      WRITE / |{ depth } { indent }{ node-id } { node-name }|.
      walk( parent = node-id depth = depth + 1 ).
    ENDLOOP.
  ENDMETHOD.
ENDCLASS.

START-OF-SELECTION.
  DATA(tree) = NEW lcl_tree( VALUE ty_nodes(
    ( id = 'C100' parent = ''     name = `Company` )
    ( id = 'C200' parent = 'C100' name = `Sales` )
    ( id = 'C210' parent = 'C200' name = `Sales North` )
    ( id = 'C220' parent = 'C200' name = `Sales South` )
    ( id = 'C300' parent = 'C100' name = `Engineering` )
    ( id = 'C310' parent = 'C300' name = `Platform` ) ) ).
  tree->walk( parent = '' depth = 0 ).

Output of the run in the local lab:

0 C100 Company
1   C200 Sales
2     C210 Sales North
2     C220 Sales South
1   C300 Engineering
2     C310 Platform

Source: ABAP CDS - Hierarchies; the listing is plain ABAP written for this page and shows only the idea of a parent-child walk

Custom entities

A custom entity is a CDS entity with no data source in CDS at all. You describe the structure and the parameters, and you name an ABAP class that supplies the rows at runtime. Use it when the data cannot be reached with SQL and the CDS features: the data sits in a non-relational store, for example a large object, it comes from an HTTP call or another service, it needs logic that only the application server can run, or the authorizations that CDS offers do not fit. In the ABAP RESTful Application Programming Model (RAP), a custom entity is the data model of an unmanaged query.

The class is not called by the ABAP runtime, but by a framework such as the RAP query engine. Because of this, a custom entity cannot be a data source of a SELECT or of a path expression, and an instance is not created as a database object. It is client-safe by default. It can be the target of an association, but that association can only be exposed and followed in a Fiori OData scenario where the RAP query engine runs the query. The annotation @ObjectModel.query.implementedBy binds the class, and it is mandatory in ABAP Cloud. Requires an SAP system; not run here.

@EndUserText.label: 'Claim statistics'
@ObjectModel.query.implementedBy: 'ABAP:ZCL_EXP_CLAIM_STATS_QUERY'
define root custom entity ZEXP_C_CLAIM_STATS
{
  key ClaimId       : abap.char(10);
      EmployeeName  : abap.char(60);
      ItemCount     : abap.int4;
}

Source: CDS DDL - DEFINE CUSTOM ENTITY; the entity is written for this page and follows the shape of its example and of the RAP unmanaged query example

The class implements the interface IF_RAP_QUERY_PROVIDER with its method select. The skeleton below checks that the request is for this entity, answers a request for data (with the rows of the page that was asked for), and answers a request for the number of rows. A Fiori application always asks for the count and sends paging options, so the example supports both. How the rows are collected is left to the comment, because it is the part that is specific to your data. Requires an SAP system; not run here.

CLASS zcl_exp_claim_stats_query DEFINITION PUBLIC FINAL CREATE PUBLIC.
  PUBLIC SECTION.
    INTERFACES if_rap_query_provider.
ENDCLASS.

CLASS zcl_exp_claim_stats_query IMPLEMENTATION.
  METHOD if_rap_query_provider~select.
    DATA stats TYPE STANDARD TABLE OF zexp_c_claim_stats WITH DEFAULT KEY.

    TRY.
        IF io_request->get_entity_id( ) <> 'ZEXP_C_CLAIM_STATS'.
          RETURN.
        ENDIF.

        " Collect the statistics here: for example call an HTTP client or
        " compute values that SQL cannot express, and fill the table STATS.

        IF io_request->is_data_requested( ).
          DATA(offset)    = io_request->get_paging( )->get_offset( ).
          DATA(page_size) = io_request->get_paging( )->get_page_size( ).
          " Cut STATS to the requested page, then hand it over:
          io_response->set_data( stats ).
        ENDIF.

        IF io_request->is_total_numb_of_rec_requested( ).
          io_response->set_total_number_of_records( lines( stats ) ).
        ENDIF.
      CATCH cx_rap_query_provider.
        " Handle the error.
    ENDTRY.
  ENDMETHOD.
ENDCLASS.

Source: RAP development guide: Implementing an Unmanaged Query; the method calls are those of its example, the class is written for this page

The RAP guide warns not to use a custom query for the plain case of reading a database table. In that case use a CDS view entity and let the RAP runtime do the SQL.

Abstract entities

An abstract entity is the lightest kind: a named structure with annotations, elements, optional parameters and associations, that exists only as a description. Activation stores its metadata and creates nothing in the database or in AS ABAP. It is client-safe by default, and it cannot be the data source of a SELECT or of a path expression. Two uses stand out in the Keyword Documentation. An abstract entity can be a data type with properties that go beyond the structures of the ABAP Dictionary, for example in RAP, where a structure with annotations and associations describes an input. And it can be a prototype of a data model that is never instantiated. The structure is known in ABAP, so a program can say TYPE followed by its name, and the annotations can be read with the class CL_DD_DDL_ANNOTATION_SERVICE. Requires an SAP system; not run here.

@EndUserText.label: 'Approval input'
@Metadata.allowExtensions: false
define abstract entity ZEXP_A_APPROVAL
{
  key ClaimId : abap.char(10);
      Comment : abap.string;
}

Source: CDS DDL - DEFINE ABSTRACT ENTITY; the entity is written for this page after its example

The difference between a custom and an abstract entity is the class: a custom entity has a query implementation class that provides rows, an abstract entity has none and provides no rows at all.

Aspects

Fields such as "created by" and "created at" appear in many views. Writing them each time invites mistakes. An aspect is a named list of elements that is defined once and reused in CDS view entities and projection views. It creates only a runtime artifact, so it is not a database object and no SELECT can read it. It is supported by analytical runtimes such as the ABAP Analytical Engine, but it cannot currently be used in OData scenarios or in Fiori applications built with RAP. Aspects, like external entities, are among the newest kinds: they arrived in Standard ABAP 8.16 and in ABAP Cloud 9.12 (2408). Requires an SAP system; not run here.

@EndUserText.label: 'Audit fields'
define aspect ZEXP_A_AUDIT
{
  key id     : abap.char(1);
      user   : abap.char(12);
      stamp  : abap.utclong;
}

Source: CDS DDL - DEFINE ASPECT; the aspect is written for this page after its example, which defines the key element first

A view entity uses an aspect in two steps. BIND ASPECT ties the aspect to the view and maps each element of the aspect to an element of the view with =>. INCLUDE then puts chosen elements of the aspect into the select list. The syntax of the two steps in the Keyword Documentation is:

BIND ASPECT aspect ( element1 => $projection.element1,
                     element2 => $projection.element2 ) AS _aspectName

INCLUDE aspect.element1, INCLUDE aspect.element2
INCLUDE aspect.* EXCLUDING element1, element2

The rules to remember are these. The names of the elements of the view and of the aspect must be unique, because they live in one namespace. The right-hand side of a binding may be a parameter expression, a typed literal or an enumerated value. INCLUDE aspect.* takes all elements, and an EXCLUDING clause removes some of them. Read the complete working example of the Keyword Documentation (a view entity that binds an aspect with all dictionary types) before you write your own, because the interplay of bound and included elements is easier to see in running code than in the syntax.

External entities

An external entity reads a table of another database as if it were a CDS entity. The other database may be another SAP HANA system or a database of another make. The connection is configured separately, in a CDS logical external schema, which is a transportable object that maps the external entity to a particular system, database and schema, and which must be configured for the connection to work. SAP HANA Smart Data Access manages the connection. External entities are read-only unless you add WRITABLE, and a writable one allows INSERT, UPDATE, MODIFY and DELETE through ABAP SQL with an ABAP SQL connection object.

There are two sorts. A static external entity names its logical external schema in its definition with PROVIDED BY, and may then be used in ABAP SQL, as a data source of other CDS entities, and in AMDP. A dynamic external entity says PROVIDED AT RUNTIME, and the schema is given in the SELECT statement with a PROVIDED BY clause. A dynamic entity can be read only with ABAP SQL. The element list must mirror the names and types of the columns of the remote table, and the optional EXTERNAL NAME must equal the name of the remote object exactly, including upper and lower case, or a runtime error occurs. The addition WITH FEDERATED DATA is mandatory today and is the only supported way of transfer.

The sketch below shows the shape of the syntax from the Keyword Documentation for a static external entity with exchange rates that live in a finance database. The names of the entity, the remote table and the logical external schema are placeholders. Requires an SAP system; not run here.

define external entity ZEXP_X_RATE
  external name EXCHANGE_RATES
{
  key currency : abap.cuky;
      rate     : abap.dec(9,5);
}
with federated data provided by ZEXP_LS_FINANCE

Further rules: external entities are client-safe by default, and for a client-dependent one the system filters on the client ID in the SAP HANA session variable CDS_CLIENT, whose value the logical external schema sets. They cannot be released as APIs, they cannot be extended with a CDS entity extension, and table buffering with a CDS entity buffer is not supported for them. The keyword DEFAULT in an element, new in 9.20 (2608), gives a value that is returned when the remote source has no column of that name.

Choosing the right kind

You need Use Because

A database calculation CDS cannot express, read like a view

Table function

SQLScript runs next to the data, and the result is a data source

A tree of parents and children with levels

Hierarchy

The database generates the tree and its attributes

Rows produced by ABAP code, for a RAP query

Custom entity

The class supplies the rows and the entity only describes them

A structure with annotations and no data

Abstract entity

It is a type description only

The same fields in several view entities

Aspect

Define once, bind and include

A table of another database

External entity

Smart Data Access reads it for you

Source: ABAP CDS - Feature Tables and the topics of the previous sections

Summary

  • ABAP CDS has six special kinds of entity: table function, hierarchy, custom entity, abstract entity, aspect and external entity. Each answers a need that a plain view entity cannot.

  • A table function pairs a CDS definition with an AMDP method written in SQLScript. Activate the CDS entity first, then the class, and read the result with ABAP SQL. It needs SAP HANA.

  • A hierarchy turns parent-child rows into a tree with attributes such as the level. It needs a view entity with a self-association and works only on SAP HANA.

  • Custom and abstract entities are transient: only metadata is stored. A custom entity gets its rows from an ABAP class through IF_RAP_QUERY_PROVIDER, and neither can be read with SELECT.

  • An aspect shares elements between view entities, and an external entity reads a table of another database.

  • The feature tables of the Keyword Documentation give the release of every keyword in every edition. Aspects and external entities are new in 8.16, and table functions have no release listed for the BTP ABAP environment and the Public Edition, so check the edition you build for.