Technology Blog Posts 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,201

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
JPT
Participant
0 Kudos

Looks great esp also that static external entities are part of future releases.

The links in External Entities | SAP Help Portal which refer to the ABAP keyword doc are not working (yet).

 

AndreaUS
Product and Topic Expert
Product and Topic Expert
0 Kudos

Hi, thanks for your feedback 😀

The link should work, the docu is already published. The link target is the ABAP Data Models Guide.

The ABAP Keyword Documentation about external entities will be published in 2411, I will post it as soon as it is available.

Cheers

Andrea

fabriciocaete2
Explorer
0 Kudos

Good to know. Very good news!

BjörnS
SAP Mentor
SAP Mentor
0 Kudos

Hello @AndreaUS,

actual I'm trying to work through the steps and have updates ADT to 3.44. But there is no "Logical external schema" Object to create. Also the outbound service looks different and the service type does not exist:

Outbound.png

Maybe the steps should be checked again?

Greetings

Björn

HectorRodriguez
Associate
Associate
0 Kudos

Any plans to offer this in the ABAP Cloud Environment in S/4HANA Private Cloud and/or On Premise?

AndreaUS
Product and Topic Expert
Product and Topic Expert

Hi @HectorRodriguez 

yes. Will be included in 2025 FPS 00 S/4HANA Cloud, private edition and on premise. This corresponds to SAP basis release 8.16. Official release info: What's New | SAP Help Portal

Hope this helps.

Best

Andrea

AndreaUS
Product and Topic Expert
Product and Topic Expert
0 Kudos

Hi @BjörnS 

sorry for the late reply.

Re outbound service: yes you are right, the screenshot from this blog post needs to be updated. The service types is "Logical External Schema". Sorry for that.

Re logical external schema object: should be available. We've checked internally and we think it is part of ADT 3.44. Please check again and if you still encounter this issue, please open an incident.

Best

Andrea

ali-kaplan
Explorer
0 Kudos

Hi Andrea,

Thank you so much for the blog, just wanted to say that the ABAP Keyword Documentation for external entities  seem to be not working. 

thanks again & regards

AndreaUS
Product and Topic Expert
Product and Topic Expert
0 Kudos

Hi @ali-kaplan,

the ABAP Keyword Documentation for external entities will be published with 2411 and the link will be pasted then. 

The delivery was delayed, sorry for any inconveniences caused.

Best

Andrea 

0 Kudos

Hi Andrea, 

thank you for all the information. 

I've just followed your steps but I get error on Save in Communication Arrangements: Linking failed for LES Mapping '100...logical external schema name...'. Any idea what's wrong? Thanks

AndreaUS
Product and Topic Expert
Product and Topic Expert
0 Kudos

@ali-kaplan @JPT Link to ABAP Keyword Documentation about External Entities was now added. 

ABAP CDS - External Entities | ABAP Keyword Documentation

ali-kaplan
Explorer
0 Kudos

@AndreaUS thank you Andrea!

Muthuraja_M
Discoverer
0 Kudos

Hello @AndreaUS -

Thanks for the blog! Is it possible to expose data as SQL Service (Web API) from On premise system ?  We want to consume/select data from ABAP remote source instead of HANA DB but not sure about how to expose the SQL service outside onprem system.

Best Regards,

Muthu

AttilaBerencsi
Product and Topic Expert
Product and Topic Expert
0 Kudos

Hi @AndreaUS ,

first thank You for this post. Very useful ! 🙂
Our question is about that can we dynamically specify the name of the schema somehow ? The schema name would be a parameter in our scenario. Now it raises a syntax error. 

AttilaBerencsi_1-1733760803053.png

If yes, is there any ATC check we need to consider for dynamically specifying the schema ?
So far we safeguarded such dynamic selects using cl_abap_dyn_prg. 

Of course we could put a case statement and duplicate the code, but such we like to avoid when possible. 

Thank You

Attila

AndreaUS
Product and Topic Expert
Product and Topic Expert
0 Kudos

@Muthuraja_M Yes it is possible to expose data as SQL Service (Web API) from On premise system as of 2021 FP2. You can find the documentation here: Accessing ABAP-Managed Data from External ODBC-Based Clients | SAP Help Portal

Best

Andrea

Muthu21
Associate
Associate
0 Kudos

Hi

https://help.sap.com/docs/ABAP_PLATFORM_NEW/b5670aaaa2364a29935f40b16499972d/4082fe1b66164eeb8aa4119...

Instead of consuming from Front end tool we want to consume from BTP ABAP environment system but we don't know how to expose the SQL service created from on premise system to BTP ABAP system and no options were found with Cloud connector settings.

Any idea on this ?

Thanks a lot.

Best Regards,

Muthu

AndreaUS
Product and Topic Expert
Product and Topic Expert

@AttilaBerencsi 

This is not intended.
It only works if you do everything dynamically:
Instead of

SELECT FROM name PROVIDED BY schema
Use
SELECT FROM ('name PROVIDED BY schema')

This should do the trick.

Best

Andrea

AndreaUS
Product and Topic Expert
Product and Topic Expert
0 Kudos

@Muthu21 

Unfortunately, the scenario does not work currently because Steampunk is currently provisioning the HANA in such a way that we cannot use the Cloud Connector via the ABAP SDA Adapter. There is also no roadmap for this, so we cannot make any official statement on when it will be available.

FlaviuBodea
Advisor
Advisor
0 Kudos

Hi Andrea,

Very interesting topic, thanks for sharing. 

Is it possible to use the CDS external entities to read and retrieve data from Datasphere into an S/4HANA OP system? 

AndreaUS
Product and Topic Expert
Product and Topic Expert

Hi @FlaviuBodea 

Currently, external entities are available in Cloud systems only and they can be used to connect to other public Cloud systems - SAP S/4HANA Cloud, SAP BTP ABAP environment, or SAP HANA Cloud.

The feature will most likely be available with the next big on premise shipment 2025.

Does that answer your question?