This is a test message to test the length of the message box.
Login
|

033: Core Data Service [Basics] - Consumption Modeling

4

In this episode, we look at the modeling of a Consumption View and examine various aspects such as functions, associations, session variables, and virtual fields.

Advertising


Introduction

In this episode, we'll discuss modeling Core Data Services on the Consumption Layer. We'll use the data model we created last time and generate a new view, which we'll then use to look at some examples.

 

Consumption View

To do this, we'll create a new view for the positions on the View interface. In this case, we want to create a Consumption View that our application will use later. With Consumption Views, we assume that we create them specifically for use cases and applications. Therefore, they are precisely tailored to a single use case and are usually not intended for reuse or further modeling. At the level of a Consumption View, computationally intensive and performance-intensive operations would also be found.

We should remember that we want to create a View Entity, as this is the standard in current releases. Once we have created the View, we clean up some annotations that we don't currently need, making the View more readable for the next steps. To inform other developers what the View is actually intended for, we add the ViewType of the virtual data model to the header of the CDS Views. Now we can further clean up the view and, in this case, remove the associations and the quantity plus unit, as we won't need them later.

 

Associations

We received the requirement to also output the partner ID in the data. For this, we no longer need a join, but instead use the association that we have already created in the data model. We can easily identify the connections using the underscore. The partner comes from the "Header", so we can include the field accordingly. If we don't specify an alias, the field receives its original name; the association is not part of the name. Now, if we call up the Data Preview, the PartnerID is now part of the data.

 

Functions

If you are working with Core Data Services, various functions are available to you, similar to ABAP. Our next requirement is to specify the full name of the partner. Using associations, we can navigate to the partner via the header and find the name there. However, the information is currently split across two fields, which we now want to combine into one. This is where the CONCAT functions come in. The first function joins two fields, but we have no way to cleanly separate the names. With the second function, we can link the fields and insert a certain number of spaces between them. To do this, we first specify the two fields we want to link, then the number of spaces, and finally, we must give the new field an alias. Without the alias, the system throws an error. Looking at the result again, the full name is now also displayed after the partner.

 

Session

The next requirement is that we should also output the product name along with the product ID. As before, we can navigate through the various modeled associations to include the product text in our view. Once we've done this, we receive a warning message that this relationship could change the cardinality. Let's activate the view and look at the preview. In contrast to previous tests, the result set has increased and no longer fits on one page. Looking at the data in detail, we now have the different languages as product text, and the actual key no longer matches the view. The document number and position are currently no longer unique and are assigned multiple times. The Core Data Service can handle this, but it's no longer entirely correct when accessing the data.

In this case, we actually only want to display the current login language to the user. To do this, we delimit the current text association, similar to a table with square brackets. We want to restrict this to the language. The `$session` variable is available to us for this purpose in the model. In the session, you'll find important user login information, such as the user ID, client, current date, and login language. We'll use this for access. The warning message will still appear, but when we run the view preview, the correct data will load again, and the product text will be in English.

Let's test the view on the same system with a different login language. To do this, we navigate to the system and start the data preview directly using ALT + F8, specifying our Core Data Service. After execution, we receive the data preview in German and the appropriate translations for the product. The data is still correct so far.

 

Alias

As a further requirement, we are to adjust the names of some fields, as the caller expects different fields. Here too, we have no problem and can simply use a new alias. Since we are not modeling further based on the view, we will not have any problems in the data model later either. You should always be careful when renaming fields within your model, especially if the fields are then also used in authorization checks.

 

New Fields

As a final adjustment, we are to make new fields available in the model. The fields do not currently exist in the data model or on the database. We need to derive the rank of a position from the quantity. In this case, we use the CASE function and compare the quantity against our KPIs. If the quantity is greater than or equal to 5, then it's a "High" performer. Two indicates a "Medium" performer, and anything below 2 indicates a "Low" performer. We'll assign an alias to the new field to clarify its use.

Finally, the caller wants the current date to also save the snapshot after subtracting the data. For this, we can again access the session and give the field an alias for the execution date. This way, we can provide fields and information that are not directly present in the database but can be derived from the context or other fields.

 

Summary

Finally, we run the Data Preview and look at the finished data. We have provided our first Consumption View and fulfilled all requirements. In doing so, we accessed the information in the data model, used session information, and created new content - all without writing a single line of ABAP.

That brings us to the end of the episode. Thanks for watching, and see you next time.

 

YouTube
Video


Included topics:
YouTubeScriptCore Data Service
Comments (0)



And further ...

Are you satisfied with the content of the article? We post new content in the ABAP area every Tuesday and Friday and irregularly in all other areas. Take a look at our tools and apps, we provide them free of charge.


032: Recycling-Heroes - Tags and Types

Category - YouTube

In this episode, we'll create additional business configurations that we'll need later in our data model. Some of the properties have changed, and we'll examine these changes in detail.

01/19/2026

031: Recycling-Heroes - Unit Testing (Configuration API)

Category - YouTube

Now that we've finished the Configuration API, let's take a look at unit tests and how we can automatically test our API. This will save us the effort of manual testing later on.

01/05/2026

030: Software-Heroes - My Community

Category - YouTube

Do you want to stay up-to-date with the latest ABAP and SAP knowledge without having to search through every blog individually? My Community brings all community content into a mini-app that you can customize to your liking, so you never miss any news.

12/22/2025

029: ABAP and SAP Material (Software-Heroes)

Category - YouTube

How do you actually find the right ABAP and SAP tutorials on the Software-Heroes platform? In this episode, we want to introduce you to some tools and overviews that will help you efficiently find topics and information in the future.

12/15/2025

028: Recycling-Heroes - Configuration API (Settings)

Category - YouTube

To easily access the business configuration data, we define an API that we can then reuse within the system. The various ABAP artifacts are also explained in more detail here.

12/08/2025