Using the Service Adaption Definition Language (SADL)

Objectives
After completing this lesson, you will be able to:

After completing this lesson, you will be able to:

  • Explain the usage of SADL for publishing CDS views to an Odata service

Service Adaptation Definition Language (SADL)

This video provides an overview of the relationship between CDS View and OData Service.

All SAP Fiori elements related annotations are translated to OData annotations. In this way, you can combine your business logic, OData service development, and annotation into one CDS view.

CDS as an OData Service

If a CDS view has the annotation "@Odata.Publish:true", an OData service is generated automatically in your back end system. The only thing you need to do is to activate it in your front end system.

Each OData service, no matter how it was developed, must be activated in transaction/IWFND/MAINT_SERVICE so that it can be queried externally.

The CDS view you are working on is transformed to an EntitySet with a name identical to the generated OData service.

All CDS views associated to this view are also transformed to an EntitySet. The association relationship is transformed to the Association and Navigation Property in the OData service.

Creating an OData Service by Referencing a CDS

In SAP Gateway Service Builder, you can reference an existing CDS view. Then, you can add associated CDS views selectively. Even associations of associated views can be added to your OData Service.

You can then override MPC or DPC standard implementation to add write support and advanced OData features for the OData Service.

Relationship Between CDS Annotation and OData Annotation

In the figure below, we see on the left side the CDS UI annotations @Ui.lineItem to create columns. @UI.identification represents an ordered collection of specific data fields that together with headerInfo identifies an entity to an end user. @UI.selectionField annotation allows filtering a list of data. This annotation is usually used in an initial page floorplan as filter bar. On the right side we see the transformation of the CDS annotations into OData annotations.

Like OData Annotations, CDS Annotations can apply on an EntitySet or a data field.

In most cases, there is a 1:1 relationship between an OData annotation term and a CDS annotation with a similar name.

CDS Annotations are grouped by target. Annotations with the same target stay together.

OData Annotations do not have a fixed position. It is usually grouped by terms.

When translated to an OData annotation, the sequence of CDS annotations belonging to one term is determined by a position property.

Create a List Report using CDS with Annotation

Business Example

In this exercise, you will create a new Fiori List Report application using the SAP Business Application Studio. This time, you will create an OData service with external annotations by creating a CDS view with annotations and publishing it as an OData service. The purpose of this exercise is to help you become familiar with the process. You do not need to dive deep into the details about all the annotations we will use.

In this exercise, replace every instance of ## with the group number your trainer assigned to you.

Task 1: Log in to the S4D SAP System using ABAP Development Tools for Eclipse (ADT)

Steps

  1. If your Eclipse is not open, open it from the taskbar.

  2. Navigate to the package ZTRAIN_## from the favorite packages of your ABAP project.

    1. Select the small triangle on the left of your ABAP project, enter your password to the SAP system when prompted, and then choose OK.

    2. Expand the Favorite Packages folder by selecting the small triangle. Find your package ZTRAIN_##.

Task 2: Create and Activate a CDS View

Steps

  1. Create a blank CDS view using the following information:

    CDS View Information

    FieldValue
    NameZCDS_UX403_SADL_##
    DescriptionUX403 Generate OData Service by SADL
    1. Right-click your package, and from the context menu choose NewOther ABAP Repository Object.

    2. In the ABAP Repository Object step, enter data into the search field, choose Data Definition under the Core Data Services folder, and then choose Next.

    3. In the Data Definition step, complete the Name and Description fields according to the task description, and then choose Next.

    4. In the Selection of Transport Request step, select the Choose from requests in which I am involved button. Select an available transport request from the table with the owner TRAIN-## and choose Next.

    5. In the Templates step, deselect the Use the selected template option, and choose Finish.

    6. A blank CDS view has been created.

  2. Copy the source code of the text file N:\UX403\Templates\UX403_Exercise05_Template.txt into the code editor of the CDS view. Also add the annotation @EndUserText.label: 'UX403 Generate OData Service by SADL'.

    You must replace all ## in the source code before you activate it. There are two ## in the source code. The first is after @AbapCatalog.sqlViewName and the second is after define view.

    1. Open the File Explorer from the taskbar.

    2. Double-click Application (N:).

    3. Double-click UX403.

    4. Double-click Templates.

    5. To open the template file, double-click the file mentioned in the task description.

    6. Select all the content of the text file and, on your keyboard, press Ctrl + C to copy the content to the clipboard.

    7. Switch back to ADT in your blank CDS view, and, on your keyboard, press Ctrl + V to paste the content.

    8. Replace all ## in the CDS view with your group number.

    9. Add @EndUserText.label: 'UX403 Generate OData Service by SADL' after @UI.headerInfo.title.value:’SalesOrderID’.

    10. Your implementation should look like the following figure:

    11. Save your changes.

  3. Activate your CDS view.

    1. To activate your CDS view, choose the Activate button in the toolbar.

Task 3: Examine your CDS View

Steps

  1. Display the data of your current CDS view by pressing F8 within your CDS view.

    1. Keep your CDS view open. Select the small triangle on the right-hand side of the Run button on the toolbar, and choose Run As1 ABAP Application, or press F8.

    2. Examine the data in the table.

    3. Close the data preview window.

  2. Open the CDS view where the source data came from and answer the following questions:

    1. Keep your CDS view open. Place your cursor on SEPM_I_SalesOrder in the source code, right-click the context menu, and choose Navigate To, or press F3.

    2. A new tab appears and displays the source code of SEPM_I_SalesOrder. Answer the questions by looking over the source code.

    3. Close the Data Definition tab of SEPM_I_SalesOrder.

Task 4: Expose your CDS View as an OData Service

Steps

  1. Add an @OData.publish annotation to your CDS view and reactivate it.

    1. To switch to the tab page of your CDS view, choose the tab with the title of your CDS view name.

    2. Add the annotation @OData.publish: true after @EndUserText.label: 'UX403 Generate OData Service by SADL'.

    3. Your implementation should look like the following figure:

    4. To activate your CDS view again, choose the Activate button in the toolbar.

    5. A warning appears on the left of @OData.publish: true to tell you that the OData service is generated but not activated. You can see it by hovering your mouse over the warning icon.

  2. Publish your new OData service on the S4D SAP system. Log on to the S4D SAP system over SAP Logon and open the transaction /N/IWFND/MAINT_SERVICE. Choose the Add Service icon in the application toolbar. In the Add Selected Service window, select LOCAL as the System Alias, enter your CDS view name ZCDS_UX403_SADL_##_CDS for Technical Service Name, and then choose Get Services. Select the line with your service and choose the Add Selected Services icon. Enter your package ZTRAIN_## and choose Continue (green checkmark). Make sure that your workbench request is selected and choose Continue (green checkmark) until a popup with a successful information appears.

Task 5: Create an SAP Fiori Elements Application from the OData Service Generated by the CDS View

Steps

  1. Open the SAP Business Application Studio.

  2. Create an SAP Fiori elements project using the following information:

    Note
    Make sure that you do not create the new project in the project folder from the previous exercises.  In the Project Attributes in the Business Application Studio there is a field Project folder path and there it should look like this: /home/user/projects/.

    SAP Fiori Elements Project Information

    FieldValue
    TemplateList Report Page
    SAP SystemS4D_100
    OData serviceZCDS_UX403_SADL_##_CDS
    Main entityZCDS_UX403_SADL_##
    Module namefirstcds.student##
    Application titleList Report from CDS view
    DescriptionList Report from CDS view
    1. Choose FileNew Project from Template in the SAP Business Application Studio.

    2. Choose SAP Fiori application and choose Start.

    3. Choose SAP Fiori application as Application Type, choose List Report Page as Floorplan, and then select Next.

    4. Choose Connect to an SAP System at Data source.

    5. Choose S4D_100 for System.

    6. Enter SADL_##_CDS into the input field of Service and select your service ZCDS_UX403_SADL_##_CDS. Choose Next.

    7. In the Entity Selection screen, select ZCDS_UX403_SADL_## for Main entity. Choose Next.

    8. In the Project Attributes screen, enter firstcds.student## as the Module name, List Report from CDS view as Application title, and List Report from CDS view as Description. Make sure that your previous folder is not selected in the Project Folder Path. Select the Project folder. It should look like this /home/user/projects/. Choose Finish.

    9. The dependencies will be installed. Wait until you can see a notification that the Project has been generated.

    10. Open the Workspace with your new Project. Select File and select Open Folder. Choose your new Project.

  3. Open the Service Modeler of SAP Fiori Tools over the command palette (ViewCommand Palette) and choose your project firstcds.student##. Explore the functionality by switching to different views (Expanded, Compact, and List) or by viewing the annotation hierarchy. Also overwrite the UI.LineItem annotation of your back end annotation file in your local annotation.xml file. To copy the UI.LineItem annotation to your local annotation.xml file, you can choose the Copy locally button on the right side of the UI.LineItem annotation of the back end annotation file within the Service Modeler. Add the Label property with a matching language-dependent String to the UI.DataField records. Do so by using the code completion and the quick fix to generate the text keys in the i18n.properties file. For values for the String of the Labels, use the values of the following table.

    String Values for the Labels

    AttributeValue
    StringSales Order ID
    StringBusiness Partner ID
    StringCompany
    StringGross Amount
    1. Open the Service Modeler of SAP Fiori Tools by following ViewCommand Palette.

    2. Choose firstcds.student## and press Enter.

    3. Now you can view your OData service in different views (Expanded, Compact, and List) by selecting the desired view in the View dropdown list.

    4. Switch back to the List view in the View dropdown list.

    5. Choose View Annotations (@ icon) on the right side of the only projection.

    6. Select Annotation Hierarchy. The Manifest Manager opens and you can see the annotation source hierarchy for a project. In this project you have one local annotation file annotation.xml and one back end annotation file ZCDS_UX403_SADL_##_CDS_VAN.xml. The local annotation file is higher ranked in the hierarchy than the back end annotation file. Therefore, the annotations in the local annotation file will be used if there is the same annotation in both files.

    7. Close the Manifest Manager tab.

    8. Now we will overwrite the UI.LineItem annotation of the back end annotation file, which was defined in your CDS view. To do this, choose the Copy locally button (symbol with two documents), which is located on the right side of UI.LineItem. If there would be several local annotation files, you could choose one, but since there is only one local annotation file in this project, the annotation file will be automatically selected. You can close the notification that the annotation was successfully copied.

    9. In the opened annotation.xml file, add the Label property with a matching language-dependent String to the UI.DataField records. Do so by using the code completion and the quick fix to generate the text keys in the i18n.properties file. As values for the Stringof the Labels, use the listed values in the table.

    10. Your implementation should look like the following figure:

    11. Save your changes.

  4. Test the application by selecting with a right click on your webapp Folder Preview Application. In the opened application, choose the Go button to display the Sales Orders in the List Report.

    1. Start the Preview Application function by right clicking on the webapp Folder.

    2. Select start-noflp.

    3. If you have popups allowed, a new window with the running application will open.

    4. In the opened application, choose the Go button to display the Sales Orders in the List Report.

Log in to track your progress & complete quizzes