How to Import External Metadata in SAP CAP Easily
If you’re building applications with the SAP Cloud Application Programming Model (SAP CAP), integrating external systems is a common need. One of the easiest ways to do this is to import external metadata in SAP CAP. This allows you to reuse external OData services or EDMX files and reference their entities in your own services without reinventing the wheel.
In this guide, you’ll learn how to import external metadata, why it’s useful, and how to make the most of it in your project.
This guide shows you how to import external metadata from an OData service or EDMX file. Let’s get started!
What Is External Metadata?
External metadata refers to the structure and definitions of services or entities that exist outside your project. In SAP environments, this is usually exposed through OData services (RESTful APIs using metadata described in EDMX files). Instead of recreating these definitions in your app, you can import them and build on top of them.
Why Import External Metadata in SAP CAP?
There are several reasons to import external metadata in SAP CAP:
- Reuse existing data models from systems like SAP S/4HANA, SuccessFactors, or third-party OData APIs
- Avoid redundancy by not redefining the same entities
- Simplify integration with remote services
- Improve development speed and reduce errors
How to Import External Metadata
1️⃣ Import from an OData URL
You can use the cds import command with a live metadata endpoint. For example:
cds import https://services.odata.org/V2/Northwind/Northwind.svc/$metadata
This will fetch the metadata and generate CDS definitions in the srv/external folder.
2️⃣ Import from a Local EDMX File
If you’ve downloaded an .edmx file:
cds import ./metadata/Northwind.edmx
After this, your package.json will automatically include a reference to the imported service.
Using the Imported Metadata
After importing, you can use the service in your own CDS files. For instance:
using { Northwind as ext } from 'external-service';
service CatalogService {
entity Products as projection on ext.Products;
}
This maps the external Products entity into your local service, which can now be exposed through CAP’s endpoints.
Implement service handler
create an implement service handler for Product:
srv.on("READ", "Products", async (req, srv) => {
const backendconnect = await cds.connect.to("northwind");
const tx = backendconnect.tx(req);
return tx.run(req.query);
};
Configuring the Remote Connection
If the imported service is live, you need to tell CAP where to find it at runtime. Add this to your package.json:
"cds": {
"requires": {
"northwind": {
"kind": "odata",
"model": "srv/external-service",
"credentials": {
"destination": "external-service",
"path": "/destinations/northwind/V2/Northwind.svc/Product",
"timeout": 3000
}
}
}
}
Configuring Destination
To access the external system oData we need to connect with destination view more for destination configuring.
Common Issues and Troubleshooting
1. Entity not found error?
Make sure the namespace matches the one used in your using statement.
2. OData service unavailable?
Check the URL and ensure it’s publicly accessible or your credentials are correct.
3. Metadata not generating?
Check if the EDMX file is valid XML and follows the OData standard.
Benefits of Importing External Metadata
- Reuse trusted APIs instead of re-coding them
- Modularize your application structure
- Standardize data across your entire SAP landscape
- Save development time and improve reliability
Conclusion
To recap: You can import external metadata in SAP CAP using either an OData service URL or an EDMX file. This allows you to quickly integrate remote systems and services without duplicating data structures. With just a few steps, your application becomes more powerful, modular, and scalable.
Learn More
- Read the official SAP CAP documentation
- Learn how to use services in projections