Skip to Content
Product Information

Custom CDS Views: Using a Field as a Value Help

If you’re trying to add an SAP view as an association element to your custom CDS view with an external API scenario, this is the blog post for you. Does this sound familiar: an error pops up on your screen telling you that you are not allowed to use SAP views as an association field in an external API scenario? However, depending on your business scenario, you may have special requirements such as a attaching the Value Help functionality to a field which requires its corresponding association data source to be addressed in the view. The reason you are seeing this error message is the following: in case of an update to the SAP view in question, your CDS view with the external API can run into compatibility issues. For this reason, it is not possible to expose the SAP view as an association field to our custom CDS view which has an external API scenario. In this blog post, I will demonstrate how to assign the Value Help functionality to a field from a custom CDS view with an external API scenario.

Before we dive into the core of the matter, let us first get an overall understanding of what an external API usage is intended for and what are its limitations. The external API scenario of Custom CDS Views enables your CDS data to be consumed externally in different platforms such as SAP Cloud Platform or SAP Analytics Cloud, depending on your business needs. Accessing the CDS data externally is possible through an OData API which is managed via Custom Communication Scenarios and Communication Arrangements. There are several content rules (SAP Note: 2540696) to which we need to pay attention during the creation of a custom CDS view for this scenario. According to the content rules of the external API scenario, the following rules are enforced in order to be able to publish a custom CDS view:

  • The view must be in the highest level of the views stack. In other words, the view cannot already be in use by other CDS views or custom queries;
  • It is not possible to expose SAP views in the element list as an association field due to compatibility reasons. In case of an update to an SAP view, your view can have compatibility issues;
  • Inheritance of the element properties from the primary data source and association data source does not happen due to compatibility reasons. Instead relevant annotations are copied. Therefore, the created views are being decoupled and stable.

Publishing your custom CDS view is not enough for a successful OData call. There are several other steps you must perform such as creating a communication scenario on the top of the view with a communication arrangement. These processes are done on the SAP S/4HANA side and they suffice for a simple OData call in your browser. How about making a call to another platform, for example, a web application built in SAP Cloud Platform Web IDE Full-Stack? Well, in that case, you’ll have to additionally set a successful connection between SAP S/4HANA and SAP Cloud Platform, which amounts to setting up a trust configuration via SAP Cloud Platform Identity Authentication Provider (See the Appendix).

Let’s assume you that you’ve published your custom CDS view successfully and now you want to use it, e.g., in a web application which is built in SAP Cloud Platform Web IDE Full-Stack. When an external API of custom CDS view is intended to be consumed by the UI, the following points apply (taken from the following wiki page on integration: Web IDE Integration with SAP S/4HANA Cloud – Frequently Asked Questions):

  • The OAuth2SAMLBearer authentication method does not work with Custom CDS Views. Custom CDS Views supports the Basic Authentication method. While setting the destination connection for the SAP S/4HANA system in the SAP Cloud Platform, the Basic Authentication method should be selected;
  • Custom CDS Views application does not appear in the service catalog of the SAP Cloud Platform Web IDE Full-Stack because the custom CDS views with an external API scenario are not intended to be used in UI development tools;
  • The scenario SAP_COM_0013 which serves to build Custom UIs for SAP S/4HANA Cloud Custom Business Object services in SAP Cloud Platform Web IDE Full-Stack does not work with Custom CDS Views application.

In line with the above points, there are two possible implementations from the above link:

  1. Create a web application in the Neo Environment of SAP Cloud Platform and deploy it. Then create a custom tile in the SAP S/4HANA system which is targeting the SAP Cloud Platform web application via URL (for more details, see the following blog post: SAP S/4HANA Cloud – Side-by-Side Extensibility);
  2. SAP S/4HANA SDK implementation (for more details, see the following blog post: SAP Cloud SDK).

Now that we’ve obtained sufficient information on external API scenario and its possible usage in other platforms (e.g., SAP Cloud Platform), it’s time to get to our main task: setting a Value Help function for a field from a custom CDS view with an external API scenario. In the below implementation part, I will create a custom CDS view containing a field with the Value Help functionality and prepare it for a service call from SAP Cloud Platform Web IDE Full-Stack.

Implementation

 

Creation of a Custom CDS View for External API Consumption in SAP S/4HANA System

The screenshot process below depicts how to prepare a custom CDS view for the external API consumption.

You can find more information about this process here: How to create an external API custom CDS view

Here we focus on the first tile above process (“Custom CDS Views”). One must relate the association data source to the custom CDS view containing the field to be used as the Value Help. It is not allowed to consume SAP views directly as an association field in a custom CDS view which has an external API scenario due to stability reasons as I explained to you in the beginning. If you try to add an SAP view to the CDS view, an error message stating “Exposure of non-customer CDS view: Not allowed for an External API” will appear. In the following example (screenshot), we will use the field “EngagementProject” to serve as the Value Help; to that effect, we first need to add the association data source “I_EngagementProject”.

The following steps summarize the creation of the CDS view, which will prevent the error message shown above from appearing:

  • Besides the external API CDS View, create also a new custom CDS view (in the screenshot below named “YY1_CDS_EngagementProject”) on the top of the SAP view (in this concrete case, it is the “I_EngagementProject” view) to be used as an associated data source;
  • Select the field (“EngagementProject”) which you want to use as Value Help and publish the view (in the screenshot below named “YY1_CDS_EngagementProject”);

  • Add this newly created view (“YY1_CDS_EngagementProject”) as an associated data source to the external API custom CDS view (“YY1_CDS_External_API”);
  • Select the field related to this association data source that you want to consume as the Value Help (in the example below this is the field “YY1_Timesheet_Utilization.EngagementProject”) and add the associated data source (“YY1_CDS_EngagementProject”) as the association field to the view (“YY1_CDS_External_API”).

  • In the tab “Element Properties”, select the associated data source (“YY1_CDS_EngagementProject”) as both the “Master Data View” property and the “Value Help View” property of the field which you want to consume as Value Help (“EngegamentProject”);
  • As the final step, publish the view (“YY1_CDS_External_API”).

You can find a summary of creation process which I drew below.

Although the field is ready to be consumed with the Value Help functionality, we need to complete the process by creating: (1) a custom communication scenario and (2) a communication arrangement.

Custom Communication Scenarios: after publishing the view, you need to create a custom communication scenario by adding the published custom CDS view as an inbound service and publish it.

Communication Arrangements: because the custom CDS view will be consumed in a web application in SAP Cloud Platform Web IDE Full-Stack, you need to introduce the SAP Cloud Platform Web IDE Full-Stack as a communication partner in the SAP S/4HANA system. In order to achieve this, use the previously created custom communication scenario and create the corresponding communication arrangement as follows:

  • Create a communication system.
    • In the communication system: set the host name to the URL of your SAP Cloud Platform Web IDE Full-Stack (without https://).
    • In the communication system: in “Users for Inbound Communication” create a new communication user.
  • Add the communication system to the arrangement and save the communication arrangement.

If you want to transport this process results to the productive system, you need to repeat the communication arrangement process in the production system by creating a new one again.

The screenshot below, taken from Postman, shows the metadata of the OData call where you can see a custom CDS view definition with its all properties, entities, and entity set relations. The service URL can be found in “Inbound Services” of your communication arrangement. You can either test your OData call via Postman or simply make a call in your browser. In order to retrieve the data, you need to enter your communication user and the corresponding password. As a result of applying the steps in the CDS view creation described above, the part of the metadata encompassed with the green rectangle in the screenshot below displays the previously set Value Help functionality of the field “EngagementProject”.

Calling External API of a Custom CDS View in a Web Application of SAP Cloud Platform Web IDE Full-Stack

The destination system must be set in order to consume external API of custom CDS view in an application. As a reminder – Custom CDS Views application supports Basic Authentication. Accordingly, when setting the destination system, the “Authentication” property needs to be set to Basic Authentication. Furthermore, the “User” property must be set to the communication user which was previously created for the communication system in SAP S/4HANA. The following example (screenshot) demonstrates how the destination is set in the SAP Cloud Platform Cockpit:

After creating the destination system, you can go to the SAP Cloud Platform Web IDE Full-Stack and create an application using the wizard. In order to set the data connection, carry out the following steps: (1) click “Service URL” and select the destination system, (2) write the service URL of the custom CDS view and click “Test”. As a result, the service call will be executed, and the results will be available in the service list. Moreover, you can bind your CDS view to a smart table together with using the smart filter of the specified Value Help field and run the application to preview the table. In the “Filters” tab the field will be visible as the Value Help field.

To summarize, we first provided context for general understanding of external API scenario creation in the Custom CDS Views application: we checked and reiterated the content rules for an external scenario; we then analyzed some integration scenario rules for situations in which you need to call your custom CDS view for UI consumption from a different platform such as SAP Cloud Platform. In the central implementation part, I explained how to create a Value Help field in a custom CDS view which has an external API scenario, for the situations in which we cannot use an SAP view directly as an association field due to compatibility reasons. We finished by summarizing how to make a service call to the custom CDS view from an SAP Cloud Platform Web IDE Full-Stack web application.

Appendix:

Trust Configuration between SAP S/4HANA and SAP Cloud Platform via SAP Cloud Platform Identity Authentication Provider

The focus of this blog post is on the consumption of the Value Help field and providing detailed account on how to set up the trust configuration is out of scope. Instead, I point the reader to the relevant guide: Custom UI Trust Settings.

Here I only quickly summarize the process for setting the trust configuration:

  • Download metadata from the Local Service Provider in the Trust settings of the SAP Cloud Platform;
  • Create a new application in the Identity Authentication Provider Administration Console and upload the metadata to SAML 2.0 Configuration (https://<YOUR_TENANTS_ID>.accounts.ondemand.com/admin);
  • Download the metadata from the Identity Authentication Provider Administration Console (https://<YOUR_TENANTS_ID>. ondemand.com/saml2/metadata);
  • Upload the metadata to the Application Identity Provider in the Trust settings of the SAP Cloud Platform.

Additional Sources:

Be the first to leave a comment
You must be Logged on to comment or reply to a post.