Technology Blogs by SAP
Learn how to extend and personalize SAP applications. Follow the SAP technology blog for insights into SAP BTP, ABAP, SAP Analytics Cloud, SAP HANA, and more.
cancel
Showing results for 
Search instead for 
Did you mean: 
AndreaUS
Product and Topic Expert
Product and Topic Expert
14,040

CDS external entities provide a modern way to handle secondary database connections in ABAP Cloud. They allow ABAP programs to retrieve and modify data from other databases using SQL. Sounds interesting? Read this blog post for further details.

The standard database of AS ABAP is the SAP HANA database. Until now, if an ABAP program wanted to access a database system other than the standard database, the developer could configure a secondary connection in transaction DBCON and use this connection in ABAP SQL (addition CONNECTION), native SQL, or AMDP. Now, ABAP CDS provides CDS external entities for retrieving data from other database systems. The remote connection is managed using the data federation approach of the SAP HANA Smart Data Access technology.

Comparing secondary connections and external entities

 Secondary connectionExternal entity
Possible secondary databaseOnly to other SAP HANA databases.

SAP-HANA databases, non-SAP-HANA databases, other AS ABAP (for a full list of possible connection targets, see 2600176 - SAP HANA Smart Data Access Supported Remote Sources - SAP for Me)).

Note: External entities can be used to connect to public Cloud systems - SAP S/4HANA Cloud public edition, SAP BTP ABAP environment, or SAP HANA Cloud.

Remote objectRemote object name, field names, and types need to match local ABAP objects.External entity represents remote object. Object name and field names in ABAP and of the external object can differ.
Number of connections in a single SELECTOnly one connection per statement.A single select statement can retrieve data from multiple remote sources.
TechnologyABAP database connectionsSAP HANA Smart Data Access

Accessing data in ABAP SQL using a secondary connection

Here’s an example for an ABAP SQL SELECT statement using a secondary connection.

  • The connection my_conn is a secondary connection defined and configured in the database table DBCON.
  • Scarr and spfli are data sources in the remote database system. The names of the remote data sources, the field names, and the data types must match those of local repository object on AS ABAP for a successful data access.
  • Only one connection per statement is possible. In this case, all data sources (here spfli and scarr) must be available in the connection defined via my_conn.

 

SELECT
  FROM scarr
  LEFT OUTER JOIN spfli ON scarr~carrid = spfli~carrid
  FIELDS scarr~carrid, scarr~carrname, spfli~connid
  INTO TABLE @FINAL(lt_data)
  OPTIONS CONNECTION my_conn.

 

 

Accessing data in ABAP SQL using a CDS external entity

Here’s an example of an ABAP SQL SELECT statement that uses a CDS external entity.

  • A CDS external entity is a design-time CDS object that represents a specific data source in another system. The names of the remote data source don’t have to match the local ABAP objects, they don’t even have to follow the ABAP naming rules – the addition EXTERNAL NAME can specify HANA full names, it can even specify Unicode characters that are not supported by ABAP at all.
  • The remote connection is configured using a logical external schema that is specified after PROVIDED BY in the ABAP SQL statement. 
  • Multiple remote data sources can be used in a single SQL statement, even if these data sources reside in different remote systems. In this example, the data sources scarr and spfli are addressed by different connections.

CDS external entity: design time object that represents a remote data source 

 

define external entity as_external_scarr 
  external name VIEW_ON_SCARR
{
  key carrid   : s_carr_id external name ...;
      carrname : s_carrname external name ...;
...
      
} 
with federated data
provided at runtime

 

ABAP SQL SELECT statement retrieving data from a remote data source using an external entity and a logical external schema

 

SELECT
FROM demo_cds_external_entity AS scarr
  PROVIDED BY les_scarr
LEFT OUTER JOIN external_spfli AS spfli
  PROVIDED BY les_spfli
ON scarr~carrid = spfli~carrid
FIELDS scarr~carrid, scarr~carrname, spfli~connid
INTO TABLE @FINAL(lt_data).

 

How to establish outbound SQL access using an external entity

AS an ABAP developer, here’s what you need to do to establish outbound SQL access using a CDS external entity:

  1. Define and activate an external entity that represents the external database object.
  2. Define and activate a logical external schema whose configuration specifies the connection details for the outbound communication.
  3. Create a Communication Scenario.
  4. Create an Outbound Service of the type Outbound SQL Access for your logical external schema.
  5. Include the outbound service in the communication scenario.
  6. Retrieve data from a remote source using an ABAP SQL Statement that binds the external entity to your logical external schema using a PROVIDED BY clause.

These are the steps performed by an ABAP developer in ABAP Development Tools for Eclipse. For the remote connection to work, a system administrator must configure the logical external schema with all the details required to establish the communication between the local system and the remote system.

The system administrator must perform the following steps using the SAP Fiori application Communication Arrangement:

  1. Create a Communication Arrangement.
  2. Create a Communication System.
  3. Create a new Outbound User.

Here’s an example:

ABAP Development

CDS external entity

A CDS external entity is a CDS artifact that represents an external database object. It specifies ABAP names and, optionally, the original field names of the remote data source are specified after EXTERNAL NAME.

 

@EndUserText.label: 'Demo CDS external entity'
define external entity demo_cds_external_entity 
  external name DATATYPES
{
  key charField   : abap.char(10) external name K_CHAR;
      F_INT1      : abap.int1;
      F_INT2      : abap.int2;
}
with federated data 
provided at runtime

 

Logical external schema

A logical external schema is created in a form-based editor in the ABAP development tools for Eclipse. It is a CDS proxy artifact whose configuration specifies the connection details required to connect to an external system. It has only one field – Default Remote Schema – that can be left empty.

AndreaUS_0-1722948154416.png

Communication scenario with outbound service

A communication scenario is a design-time description of how two communication partners communicate with each other. It consists of inbound and/or outbound services and supported authentication methods. A logical external schema must be included as an outbound service in a communication scenario. This is done in a form-based editor in the ABAP development tools for Eclipse.

Outbound service referring to a logical external schema

AndreaUS_0-1725287994318.png

Communication Scenario with outbound service

AndreaUS_2-1722948222088.png

ABAP SQL Access:

 

  select
      from demo_cds_external_entity
        provided by demo_cds_logicl_externl_schema
      fields *
      order by charField
      into table @final(lt_federated_data).

 

Result: (Data fetched from an SAP HANA system in the Canary landscape).

AndreaUS_3-1722948257028.png

Administration

A system administrator creates a new  Communication Arrangement, Communication System, and Outbound User in the SAP Fiori Application Communication Arrangement. The following screenshots show all the relevant fields that must be entered.

Communication Arrangement

AndreaUS_4-1722948297011.png

Communication System

AndreaUS_5-1722948312236.png

AndreaUS_6-1722948319438.png

For details on the adapters and their connection parameters, see the corresponding topics for the adapter types in Creating Remote Sources (Smart Data Access) | SAP Help Portal.

Outbound User

AndreaUS_7-1722948333252.png

AndreaUS_8-1722948339703.png

Writable External Entities

As of release 2502, an external entity can also be defined as writable. Writable external entities allow modifying data on external database systems using ABAP SQL operations, such as INSERT, UPDATE, MODIFY, and DELETE. This facilitates write access in data integration scenarios. Writing is always done via a service connection in order to decouple the remote transaction from the local transaction.

Here's what you need:

  • Add the keyword WRITABLE to your external entity
  • Create an ABAP SQL connection object for your logical external schema  using the method WRITE_ENABLED_4_LOGICAL_SCHEMA of the system class CL_ABAP_SQL_CONNECTION_BUILDER to establish a service connection.
  • Specify the connection object during write operations using the syntax addition CONNECTION.

Further details are described on SAP Help Portal under Writable External Entities | SAP Help Portal.

Outlook

This blog post introduces CDS external entities for outbound SQL access. Currently, only dynamic external entities are supported. This kind of external entity does not specify a logical external schema in its data definition, but uses the addition PROVIDED AT RUNTIME. Dynamic external entities can only be accessed using ABAP SQL. They cannot be used as a data source for other CDS entities.

It is planned to provide static external entities in one of the future releases. A static external entity defines a logical external schema directly in its data definition. Static external entities can be used as data sources in ABAP SQL SELECT statements, in other CDS entities, and in ABAP Managed Database Procedures (AMDP).

Further info

Feedback and questions are welcome!

20 Comments