SAP RAP Tutorial : Read Multiple Entities

In our last blog SAP RAP Tutorial : Object Page and Facets, we create object page and facets using one entity or data source and displayed it on our application. In this blog, we will read data from multiple entities and display it in our application in different facets.
For our scenario we will add a facet for flight details like Flight number, Flight date, plane type etc. We will start by first enhancing our data model.

We will create CDS views on Flight Details demo table and Carrier details demo table same way we did for connections table.
Simply right click on New -> Data Definition and enter details.

How to display multiple entities in SAP RAP object page,
Enhancing CDS view for multiple facets in SAP RAP,
SAP RAP tutorial for flight details facet,
Designing SAP Fiori UI with multiple CDS entities,
Using facets to organize data in SAP RAP applications,

Check for errors if any before activation like any currency or amount fields needing semantics annotation and activate.

How to display multiple entities in SAP RAP object page,
Enhancing CDS view for multiple facets in SAP RAP,
SAP RAP tutorial for flight details facet,
Designing SAP Fiori UI with multiple CDS entities,
Using facets to organize data in SAP RAP applications,


Now in our next step, we will relate both these table using concept of association.In Core Data Services (CDS) views in SAP ABAP, an association is a way to define a relationship between two entities (like tables or views), similar to a join, but with more flexibility and better performance optimization.

What is an Association in SAP RAP ?

In SAP RAP, an association in CDS is a declarative relationship between data models. Instead of writing explicit SQL joins, you define associations that can be used later when needed.

Key Features of Associations:

Improved readability: Makes CDS views cleaner and easier to maintain.

Lazy loading: Associations are not executed until explicitly used (via path expressions).

Reusable: You can define associations once and use them in multiple views.

Navigational access: You can access fields of the associated entity using path expressions.

So coming back to our scenario if we check the demo tables these two tables can be joined based on Carrier and connection Id. Also there is a one to many relationship between these tables.

How to display multiple entities in SAP RAP object page,
Enhancing CDS view for multiple facets in SAP RAP,
SAP RAP tutorial for flight details facet,
Designing SAP Fiori UI with multiple CDS entities,
Using facets to organize data in SAP RAP applications,

Tip: To open two tabs in parallel in eclipse just drag one tab to one side.

Also don’t forget to expose the association.

How to display multiple entities in SAP RAP object page,
Enhancing CDS view for multiple facets in SAP RAP,
SAP RAP tutorial for flight details facet,
Designing SAP Fiori UI with multiple CDS entities,
Using facets to organize data in SAP RAP applications,

Now lets try to display the details in a facet. For this we will create another facet same way we did for connections.

How to display multiple entities in SAP RAP object page,
Enhancing CDS view for multiple facets in SAP RAP,
SAP RAP tutorial for flight details facet,
Designing SAP Fiori UI with multiple CDS entities,
Using facets to organize data in SAP RAP applications,

Note here we have given type as Line Item reference because we want to display a table or a list.
Also since there are multiple facets, we need to provide ID property to uniquely identity them.
In our next step we need to tell the facet from where we need to get this data. For this we will use property targetelement.

How to display multiple entities in SAP RAP object page,
Enhancing CDS view for multiple facets in SAP RAP,
SAP RAP tutorial for flight details facet,
Designing SAP Fiori UI with multiple CDS entities,
Using facets to organize data in SAP RAP applications,

Also in the flight data definition we also need to give positions for the display of fields using lineitem annotations.

How to display multiple entities in SAP RAP object page,
Enhancing CDS view for multiple facets in SAP RAP,
SAP RAP tutorial for flight details facet,
Designing SAP Fiori UI with multiple CDS entities,
Using facets to organize data in SAP RAP applications,

Now lets try to refresh our application and go to our object page to check if a new facet is visible.

How to display multiple entities in SAP RAP object page,
Enhancing CDS view for multiple facets in SAP RAP,
SAP RAP tutorial for flight details facet,
Designing SAP Fiori UI with multiple CDS entities,
Using facets to organize data in SAP RAP applications,

No not there yet, but why?
Let us try to find out. Comment the target element, activate and refresh again.

How to display multiple entities in SAP RAP object page,
Enhancing CDS view for multiple facets in SAP RAP,
SAP RAP tutorial for flight details facet,
Designing SAP Fiori UI with multiple CDS entities,
Using facets to organize data in SAP RAP applications,

Congratulations it is visible now. Any guesses?

Yes we are trying to use the zi_abhi_flight_r but we have not exposed it in our service definition. So let us expose it.

How to display multiple entities in SAP RAP object page,
Enhancing CDS view for multiple facets in SAP RAP,
SAP RAP tutorial for flight details facet,
Designing SAP Fiori UI with multiple CDS entities,
Using facets to organize data in SAP RAP applications,

Activate, refresh .

Voila!
Now on our list page we have airline name column but it is a ID and not a name.

To fetch name we will need to check table /dmo/carrier

Create new data definition.

How to display multiple entities in SAP RAP object page,
Enhancing CDS view for multiple facets in SAP RAP,
SAP RAP tutorial for flight details facet,
Designing SAP Fiori UI with multiple CDS entities,
Using facets to organize data in SAP RAP applications,
How to display multiple entities in SAP RAP object page,
Enhancing CDS view for multiple facets in SAP RAP,
SAP RAP tutorial for flight details facet,
Designing SAP Fiori UI with multiple CDS entities,
Using facets to organize data in SAP RAP applications,

Commented the ones not needed.
Save and activate.

Now create relationship with main view.

How to display multiple entities in SAP RAP object page,
Enhancing CDS view for multiple facets in SAP RAP,
SAP RAP tutorial for flight details facet,
Designing SAP Fiori UI with multiple CDS entities,
Using facets to organize data in SAP RAP applications,

Now to display name or descriptions there are two ways.

In the 1st approach we use object model annotation but we will also need to tell the text field of annotation to our system.

For that In the associated view we will need to use annotation semantics.text.

How to display multiple entities in SAP RAP object page,
Enhancing CDS view for multiple facets in SAP RAP,
SAP RAP tutorial for flight details facet,
Designing SAP Fiori UI with multiple CDS entities,
Using facets to organize data in SAP RAP applications,

But what will happen if there are multiple fields with this annotation in our view.

Then it will take the first one.

But lets say if there are descriptions in multiple languages how to handle it?

In that case we also need to use semantics.languague : true so that both fields are considered. We will discuss the other approach in our next blogs.
Activate and refresh our application.

How to display multiple entities in SAP RAP object page,
Enhancing CDS view for multiple facets in SAP RAP,
SAP RAP tutorial for flight details facet,
Designing SAP Fiori UI with multiple CDS entities,
Using facets to organize data in SAP RAP applications,

Go to object page.

How to display multiple entities in SAP RAP object page,
Enhancing CDS view for multiple facets in SAP RAP,
SAP RAP tutorial for flight details facet,
Designing SAP Fiori UI with multiple CDS entities,
Using facets to organize data in SAP RAP applications,

Still in flight details name not coming because we have not connected flight view with our airline view.
Let us relate them as well using association.

How to display multiple entities in SAP RAP object page,
Enhancing CDS view for multiple facets in SAP RAP,
SAP RAP tutorial for flight details facet,
Designing SAP Fiori UI with multiple CDS entities,
Using facets to organize data in SAP RAP applications,

Activate and refresh our application.

How to display multiple entities in SAP RAP object page,
Enhancing CDS view for multiple facets in SAP RAP,
SAP RAP tutorial for flight details facet,
Designing SAP Fiori UI with multiple CDS entities,
Using facets to organize data in SAP RAP applications,

So we have now used multiple data sources and entities to display details on our application. Hope you found this helpful.
In our next blog, we will try to incorporate a generic search and search help for the selection criteria.

Also read – Understanding OData Services with Metadata

Leave a Comment

Your email address will not be published. Required fields are marked *