SAP S/4HANA Cloud, Cloud Integration

How to create External API using custom CDS view on S/4 Hana Cloud

Introduction: This document describes that if the standard API is not available to fulfil any integration requirement, then how to create an external API using standard or custom CDS view in S/4HANA cloud so that we can get the required data via created external API

Here I will take one example where i want to fetch the address details of a supplier, the standard CDS view of supplier does not provide the address details of the supplier, it only provides the AddressID of the supplier and another CDS view can provide the address details using that AddressID as a filter in join condition.

For creating external API from custom CDS view, Let’s create custom CDS view and then create a custom communication scenario.

Consider a scenario where we need supplier address via custom CDS view.

**Standard API is available to full fill this requirement
but here I am taking this example for explaining purpose.

So, let’s start.

Login to S/4 Hana public cloud and go to Extensibility->Custom CDS View(Figure 1)

Figure 1

Click on create for a new CDS view.(Figure 2)

Figure 2

Now, give any label, name would be created automatically.

Select scenario as External API (Figure 3)

Figure 3

Now here we need to add data source, data source can be standard or custom.

First let’s add primary data source.

Here, I have added “I_Supplier” which gives the supplier details including supplier AddressID.(Figure 4)

Figure 4

Now add associated data source, lets add I_Address_2 here to get address details of Supplier based on AddressID field in primary data source.

After adding associated data source, set the join condition.(Figure 5)

Figure 5

Here we can choose any field on associated data source and then select operator like equals, set value type as parameter, field(from primary data source) or constant(Figure 6)

Figure 6

Here I am adding AddressID field from associated data source, condition equals to AddressID field of primary data source (Figure 7)

Figure 7

After adding data sources, next step is to add parameters, but we can’t add parameters when Scenario is “External API”.

So, let’s move to the next step which is adding elements from both or all data sources.(Figure 8)

Figure 8

After adding elements, just click on publish and wait until status changes to “Publishing Successful”.(Figure 9)

Figure 9

After Successful Publishing, now we can check the result in terms of data.(Figure 10)

Figure 10

Now, we need to create Custom Communication Scenario for the created Custom CDS View so that same CDS view can be used as an External API

Go to Extensibility-> Custom Communication Scenarios(Figure 11)

Figure 11

Click on new(Figure 12)

Figure 12

Put any name for scenario ID.(Figure 13)

Figure 13

Now add CDS view (Figure 14 and 15)

Figure 14
Figure 15

Publish it (Figure 16)

Figure 16

After successful publishing on custom communication scenario, we can add it to Communication Arrangement.(Figure 17)

Figure 17