SAP Business Application Studio, SAP Business Technology Platform, SAP Cloud Application Programming Model

Complex OData Annotation Editing using CDS Graphical Modeler

In this blog post, we will demonstrate how to annotate CDS models with OData annotations using the CDS Graphical Modeler.

Complex OData Annotation Editing using CDS Graphical Modeler

In this blog post, we will show you how to create complex OData annotations for CDS projections in a separate app/annotations.cds file using the CDS Graphical Modeler so that as a user you don’t need to remember the complex details of the OData annotation terms.

Let’s say we have an ESPM model and we have a service model defined in a service CDS file that defined all the projections:

SAP Business Application Studio, SAP Business Technology Platform, SAP Cloud Application Programming Model

and we can open the ESPM service model using the CDS modeler:

SAP Business Application Studio, SAP Business Technology Platform, SAP Cloud Application Programming Model

and we want to annotate the projections and manage the annotations in a separate CDS file, for example, app/annotations.cds.

First create app/annotations.cds and open the file using the CDS modeler, and you will see an empty CDS model because the CDS file doesn’t contain any CDS objects:

SAP Business Application Studio, SAP Business Technology Platform, SAP Cloud Application Programming Model

Now let’s import the service model to the annotations.cds file. Click “Import” -> “External File” from the toolbar:

SAP Business Application Studio, SAP Business Technology Platform, SAP Cloud Application Programming Model

In the file selection dialog, select srv/cat-service.cds which is your service CDS file:

SAP Business Application Studio, SAP Business Technology Platform, SAP Cloud Application Programming Model

After the import is complete, the modeler will show the details of the imported service:

SAP Business Application Studio, SAP Business Technology Platform, SAP Cloud Application Programming Model

Let’s say we want to annotate the service entity “Customers” in the service, we click the entity “Customers” in the canvas and select “Pin to the Main Namespace” context menu. By doing so, CDS modeler will place the imported entity “Customers” to the main namespace so that we can directly operate on it:

SAP Business Application Studio, SAP Business Technology Platform, SAP Cloud Application Programming Model

After the “pin” is done, you will be able to see the entity “Customers” from the CatalogService directly in the main canvas in annotations.cds, just like any other regular entities:

SAP Business Application Studio, SAP Business Technology Platform, SAP Cloud Application Programming Model

Now since we want to annotate this entity, we click “Manage Annotation” context menu as shown in the above screenshot and the annotation dialog shows up:

SAP Business Application Studio, SAP Business Technology Platform, SAP Cloud Application Programming Model

And you can see both entity/projection as well as its properties are shown in the annotation editor, and you would be able to annotate both the entity and the properties directly from the app/annotations.cds file.

Now let’s show how to create complex OData annotations for this projection. First click “+” button and show all the annotation terms in the list for you to choose:

SAP Business Application Studio, SAP Business Technology Platform, SAP Cloud Application Programming Model

Let’s try to add term @ApplySupported from the Aggregation vocabulary defined in https://oasis-tcs.github.io/odata-vocabularies/vocabularies/Org.OData.Aggregation.V1.html:

SAP Business Application Studio, SAP Business Technology Platform, SAP Cloud Application Programming Model

and try to provide the values for @Aggregation.ApplySupported term:

SAP Business Application Studio, SAP Business Technology Platform, SAP Cloud Application Programming Model

Please note that the annotation editor will take care of all the OData annotation schema itself and facilitate the user as much as possible, and the use just need to pick up the value from the list and doesn’t need to remember the details of the term definition.

Click “Update” button to close the dialog, and we can now check the app/annotations.cds:

SAP Business Application Studio, SAP Business Technology Platform, SAP Cloud Application Programming Model

You will see that this complex annotation “@Aggregation.ApplySupported” has been created successfully in the CDS file.

Now let’s reopen the annotation editor and choose “@Capabilities.ChangeTracking” for this entity:

SAP Business Application Studio, SAP Business Technology Platform, SAP Cloud Application Programming Model
SAP Business Application Studio, SAP Business Technology Platform, SAP Cloud Application Programming Model

Now provide values for this term:

SAP Business Application Studio, SAP Business Technology Platform, SAP Cloud Application Programming Model

until we get below:

SAP Business Application Studio, SAP Business Technology Platform, SAP Cloud Application Programming Model

and the app/annotations.cds:

SAP Business Application Studio, SAP Business Technology Platform, SAP Cloud Application Programming Model

You can see we can generate very complex OData annotations very easily in the annotations.cds file.

In addition to annotating the entity, we can also annotate its properties using either OData annotations or CAP annotations:

SAP Business Application Studio, SAP Business Technology Platform, SAP Cloud Application Programming Model

and app/annotations.cds has:

SAP Business Application Studio, SAP Business Technology Platform, SAP Cloud Application Programming Model
Rating: 0 / 5 (0 votes)