Skip to Content

In this blog post, we discuss how to set up a connection to SAP S/4HANA from your cloud application running on SAP Cloud Platform, Cloud Foundry.

Good news: your application source code is really simplified, when you use the SAP S/4HANA Cloud SDK components, which take care of a lot of technical details for setting up a connection for you. Due to several abstractions, it does not matter whether your S/4HANA runs on-premise or in the cloud – a single version of the source code works in both cases.

Feel free to check out the source code demonstrating the S/4HANA Edition abstraction in our S4-Connectivity example on GitHub.

Note: This post is part of a series. For a complete overview visit the SAP S/4HANA Cloud SDK Overview.

In case you have questions or suggestions, reach out to us on Stackoverflow with the s4sdk tag. Our development team is actively monitoring this tag and is making sure that the questions and requests are addressed properly. You can use this opportunity to share your experiences and to get advice from a broader Stackoverflow community. Of course, we are happy to receive your questions and suggestions in the comments to our blog posts, as well.

Goal of This Blog Post

This blog post guides you through setting up a connection from your application, developed with the S/4HANA Cloud SDK and running on SAP Cloud Platform, Cloud Foundry, to SAP S/4HANA systems. Although this blog post mainly focuses on the S/4HANA On-Premise connectivity, we also discuss how you can customize your application to access SAP S/4HANA Cloud.

You will see how the SDK abstracts SAP S/4HANA Editions and enables the communication with various S/4HANA editions using the same lines of code. This allows developers to focus on the business logic of their applications, rather than taking care of the infrastructure-related general problems.

In this blog post, I mainly focus on the connectivity from the developer perspective. Nevertheless, I also briefly touch on how to customize the Cloud Platform account. For a deep dive on this topic, please refer to the blog post Part 1: How to use SAP Cloud Platform Connectivity and Cloud Connector in the Cloud Foundry environment with a detailed step by step explanation on how to set up the infrastructure.

Out of Scope

In this blog post, I reference related Cloud Platform services, such as authorization & trust management, the connectivity service, and the destination service. For more information on these topics, please, consult the official SAP documentation. I also give references to related resources in the part Further Information and Related Reading.

For simplicity of the account setup, I cover only the basic authentication between a cloud platform application and SAP S/4HANA. In productive solutions, you would use principle propagation instead. However, this will affect only the configuration part, as the authentication approach is abstracted by the SDK.


To demonstrate the connectivity, we will retrieve data from S/4HANA using OData services. Therefore, it is recommended to work through the following tutorial steps of our series to be able to experiment with S/4HANA On-Premise connectivity, as described in the sections below.

As On-Premise connectivity from SAP Cloud Platform, Cloud Foundry is supported starting from the SDK version 1.7.1, please, make sure that you use this or later version, when executing these steps.

Step 1 with SAP S/4HANA Cloud SDK: Set up

Step 3 with SAP S/4HANA Cloud SDK: HelloWorld on SCP CloudFoundry

Step 4 with SAP S/4HANA Cloud SDK: Calling an OData Service with the Virtual Data Model (Cloud Foundry part only)

Step 7 with SAP S/4HANA Cloud SDK: Secure your Application on SAP Cloud Platform, CloudFoundry (execute till the part Use OAuth scope to authorize users).

Make sure that you have access to On-Premise SAP S/4HANA. You may also check that business partner service is activated in your system using the transaction code SICF.

Beware that the destination service is currently Beta in SAP Cloud Platform, Cloud Foundry. Therefore, it is available only in a Trial landscape.

Quick Look at the S/4HANA Query with the SDK Virtual Data Model

After executing Step 3, 4, and 7 of SDK tutorials, you have created two projects: business partner application accessing OData service and approuter that secures your application.

Now, let us consider business partner query in BusinessPartnerServlet that we have created in the first application and that is explained in details in the Step 4 of our tutorial series:

final List<BusinessPartner> businessPartners =
    new DefaultBusinessPartnerService()
         .orderBy(BusinessPartner.LAST_NAME, Order.ASC)

The execute() method is exactly the method that hides details related to connectivity to SAP S/4HANA from the application developer.

It is does not matter whether you are talking to S/4HANA Cloud or S/4HANA On-Premise edition. You can still use exactly the same query and the SDK will handle all the connectivity magic for you behind the scenes.

This enables separation of concerns: developers write source code and cloud platform account administrators take care of the customizing of corresponding S/4HANA instances.

Running Business Partner Calls Against S/4HANA On-Premise

Now, let us see, what customizing is required to run the application against SAP S/4HANA On-Premise.

Set up Connectivity in Cloud Platform Account and Cloud Connector

Step 1. Setting up Cloud Connector

The blog post Part 1: How to use SAP Cloud Platform Connectivity and Cloud Connector in the Cloud Foundry environment gives a step by step guidance for setting up of Cloud Connector, including the required prerequisites. In a nutshell:

1) You will create a connection from your cloud connector instance to your Cloud Foundry account, where you deploy business partner application. Here is the example of my configuration:


2) You will enable cloud to on-premise access for the given account to your on-premise system. Here is the example of my configuration:


Beware that the virtual host that you configure in the Cloud Connector will be referenced in the destination configuration, as shown below.

Step 2. Create service instances in Cloud Foundry Account

To be able to connect SAP S/4HANA On-Premise edition, you need to create an instance of the connectivity service that we will later bind to our business partner java application.

To create your instance of the connectivity service, you can use Cloud Foundry CLI and execute the command:

cf create-service connectivity lite my-connectivity

If you have executed the tutorial steps, mentioned in the prerequisites to this deep dive, you have already created the following service instances:

  • Instance my-xsuaa of the service Authorization & Trust Management
  • Instance my-destination of the destination service

You can check your service instances in your Cloud Foundry cockpit, as shown in the screenshot below:

Step 3. Configure S/4HANA destination

Destinations can be configured via Cloud Foundry cockpit. Configuration of destinations can be done in a subaccount level, when you select the menu Connectivity -> Destinations (Beta).

In the Business Partner query in our application, we use the method execute(), which runs the query against the destination with the default name ERPQueryEndpoint.

The screenshoot below demonstrates my configuration that corresponds to the previously described configuration of the Cloud Connector and default destination name:

This default destination name is defined by the SDK. You can use another name, however, as it is demonstrated in our GitHub example S4-Connectivity. It can be useful in case you have several destinations. You can then explicitly reference the destination by name when creating ErpConfigContext, as follows (for example, for the endpoint with the name “S4HANA”):

execute(new ErpConfigContext("S4HANA"))

After the service instances are created and customized, we will need to bind them to our application.

Bind Cloud Platform Services in manifest.yml of Your Business Partner Application

Modify already existing manifest.yml file in your business partner application by adding a binding to the new connectivity service instance. manifest.yml looks as follows in my case:


- name: firstapp
  memory: 768M
  host: firstapp-i042557trial
  path: application/target/firstapp-application.war
  buildpack: sap_java_buildpack
    JBP_CONFIG_SAPJVM_MEMORY_SIZES: 'metaspace:96m..'
    SAP_JWT_TRUST_ACL: '[{"clientid" : "*", "identityzone" : "*"}]'
  - my-destination
  - my-xsuaa
  - my-connectivity

Deploy and Test

Now, you can redeploy your business partner application in SAP Cloud Platform, Cloud Foundry and call the endpoint /businesspartners of your approuter to get a response from your On-Premise SAP S/4HANA system, as depicted below.

Let us take a look at the concepts of the inner working of the On-Premise connectivity and the SDK role in this scenario.

S/4HANA On-Premise Connectivity with the SDK: Under the Hood

What is actually going on behind the scenes, when you call the execute() method of the business partner query? Actually, several steps are executed that you even do not have to be aware of, as the SDK takes care of them for you.

The detailed explanation of the inner working of the On-Premise connectivity from SAP Cloud Platform, Cloud Foundry with basic authentication is provided in this blog post: Part 2: How to use SAP Cloud Platform Connectivity and Cloud Connector in the Cloud Foundry environment

When using the SDK, the steps, such as retrieving a Json Web Tocken (JWT) to connect to the destination service, retrieving a configuration of the destination, obtaining a JWT for accessing the connectivity service, sending a request to the connectivity instance are handled by the SDK.

Looking at the high level architecture depicted in the referenced blog post, the steps 4a, 4b, 5, and 6 are performed when you are calling the execute() method of your business partner query.

Abstracting SAP S/4HANA Edition with the SDK: S/4HANA Cloud Connectivity

So far, we have looked at what needs to be done to set up SAP S/4HANA On-Premise connectivity from your application running in SAP Cloud Platform, Cloud Foundry.

One of the nice features of the SAP S/4HANA Cloud SDK is the abstraction of S/4HANA editions. What does it mean from the development perspective? You can write your code for S/4HANA On-Premise and you can be sure that you will be able to run your application against S/4HANA Cloud edition without any changes in code. You just need to adapt the configuration of the S/4HANA endpoint.

Let us see that in action.

Set up Cloud Platform

All you need to do to read data from SAP S/4HANA Cloud is to adapt the default destination, changing it to the corresponding S/4HANA Cloud instance. This is how the destination for the Cloud system would look like:

Note: For S/4HANA Cloud communication, you can remove the binding of your application to the instance of the connectivity service in manifest.yml. It is only required in case of On-Premise connectivity.

Deploy and Test

Now, you can redeploy your business partner application in SAP Cloud Platform, Cloud Foundry and call the endpoint /businesspartners of approuter to get a response from SAP S/4HANA Cloud system, as depicted below.

We have just switched the S/4HANA edition that our application is talking to without changing a single line of code. As a developer, I like that! 🙂

Further Information and Related Reading

First of all, I recommend you to check out S4-Connectivity example on GitHub that demonstrates the usage of the same code line for various S/4HANA editions. Beware that you will need to configure two destinations in your account to run this example: ErpQueryEndpointCloud (S/4HANA Cloud endpoint) and ErpQueryEndpointOP (S/4HANA On-Premise). Also, do not forget to secure your application with an approuter before testing it.

As written in sections above, we highly recommend to check out the blog post, provided by SAP Cloud Platform colleagues: How to use SAP Cloud Platform Connectivity and Cloud Connector in the Cloud Foundry environment. You do not need to implement these steps when building an app with the SDK, but it is always helpful to get an insight on an inner working.

In addition to that, here are some link to the related official SAP documentation, in case you are interested to research on this topic more and to get insight on the corresponding Cloud Foundry services:

To report this post you need to login first.


You must be Logged on to comment or reply to a post.

    1. Ekaterina Kruse Post author

      Hello Kalfen,

      could you please describe, how do you create an instance, via CLI or via CF cockpit? Could you please add more details regarding the error that you are getting.

      Best regards,


      1. Jonas Matthias Zeitzem

        I seem to have the same problem with my trial account. Tried to create an instance with the CLI. Used the Command:

        cf create-service destination lite my-destination

        Responds was:

        Creating service instance my-destination in org Jonas_trial / space dev as […]…
        Server error, status code: 502, error code: 10001, message: Service broker error: Org with guid [ … ] is not registered in tenant-onboarding service. Instance creation not allowed.


        Best regards,



        1. Ekaterina Kruse Post author

          Hello Jonas,


          thanks for the detailed information. Could you please also provide the following details: 1) on which landscape do you have this issue 2) how the corresponding account was created, did you use public trial process?



  1. Vikas Lamba


    Is it possible to connect to S4HANA OP edition with deployment on Neo. I followed the blog post 4 but in the Neo section it only discusses local deployment. I am specifically facing the issue where I get an error  – Failed to execute OData Metadata request.

    I could see that in the troubleshooting section the workaround of adding TrustAll=TRUE was also only provided for local deployment but not for Neo.

    Can you please confirm if Neo is supported for S4HANA OP OData consumption and if so can you point me to some example on how to achieve it.


    1. Dennis Hempfing

      Hi Vikas,

      thank you for question! Connecting from Neo (or Cloud Foundry, for that matter) to an S/4HANA On-Premise system requires a Cloud Connector. Do you have a Cloud Connector set up? You can find more information here.

      I hope this helps you, please don’t hesitate to get back to us if you have further questions!

      Best regards


      1. Vikas Lamba

        Hi Dennis,

        Yes I have configured a Cloud Connector and a destination to the S4HANA OP system. I was able to use this destination to consume the same API in Web IDE by building a UI5 application.

        I was also able to consume the same API using lcal deployment options for oth CF and NEO but had to manually set TrustAll = True in the destination configurations.

        Unfortunately this parameter cannot be setup on real destination either in CF/Neo (I assume some security standard). Thus in absence of this parameter the SDK fails to communicate to the API when the app is deployed on SCP.


        1. Dennis Hempfing

          Hi Vikas,

          the TrustAll parameter should not be needed on SCP.

          Going back to your original comment, you said the error coming up was “Failed to execute OData Metadata request”. This error can have different sources, thus it’s hard to determine the root cause.

          Have you deployed and tested your app locally?

          Also can you provide a stack trace?

          Best regards


          1. Guoquan Xing

            I suffer the same error message, and please see log here:


            2018-09-07T05:08:31.785+0000 [APP/PROC/WEB/0] OUT 05:08:31.785 [http-nio-8080-exec-8] INFO – Falling back to locale “en_US”. To specify the locale, set the property on destination “ErpQueryEndpoint” or provide the locale as explicit argument. (END OF LOG ENTRY)

            2018-09-07T05:08:32.031+0000 [APP/PROC/WEB/0] OUT 05:08:32.031 [http-nio-8080-exec-8] ERROR – Error occurred during populating metadata :$ErpODataException:

            2018-09-07T05:08:32.351+0000 [APP/PROC/WEB/0] OUT 05:08:32.351 [http-nio-8080-exec-8] ERROR – Error occurred during populating metadata :$ErpODataException:

            2018-09-07T05:08:32.352+0000 [APP/PROC/WEB/0] OUT at org.springframework.web.filter.DelegatingFilterProxy.invokeDelegate(

            2018-09-07T05:08:32.352+0000 [APP/PROC/WEB/0] OUT at org.springframework.web.filter.DelegatingFilterProxy.doFilter(

            2018-09-07T05:08:32.352+0000 [APP/PROC/WEB/0] OUT at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(

            2018-09-07T05:08:32.352+0000 [APP/PROC/WEB/0] OUT at org.apache.catalina.core.ApplicationFilterChain.doFilter(

            2018-09-07T05:08:32.352+0000 [APP/PROC/WEB/0] OUT at org.cloudfoundry.router.ClientCertificateMapper.doFilter(

            2018-09-07T05:08:32.352+0000 [APP/PROC/WEB/0] OUT at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(

            2018-09-07T05:08:32.352+0000 [APP/PROC/WEB/0] OUT at org.apache.catalina.core.ApplicationFilterChain.doFilter(

            2018-09-07T05:08:32.352+0000 [APP/PROC/WEB/0] OUT at org.apache.catalina.core.StandardWrapperValve.invoke(

            2018-09-07T05:08:32.352+0000 [APP/PROC/WEB/0] OUT at org.apache.catalina.core.StandardContextValve.invoke(

            2018-09-07T05:08:32.352+0000 [APP/PROC/WEB/0] OUT at org.apache.catalina.authenticator.AuthenticatorBase.invoke(

            2018-09-07T05:08:32.352+0000 [APP/PROC/WEB/0] OUT at org.apache.catalina.core.StandardHostValve.invoke(

            2018-09-07T05:08:32.352+0000 [APP/PROC/WEB/0] OUT at org.apache.catalina.valves.ErrorReportValve.invoke(

            2018-09-07T05:08:32.352+0000 [APP/PROC/WEB/0] OUT at org.apache.catalina.core.StandardEngineValve.invoke(

            2018-09-07T05:08:32.352+0000 [APP/PROC/WEB/0] OUT at org.apache.catalina.valves.AbstractAccessLogValve.invoke(

            2018-09-07T05:08:32.352+0000 [APP/PROC/WEB/0] OUT at org.apache.catalina.valves.RemoteIpValve.invoke(

            2018-09-07T05:08:32.352+0000 [APP/PROC/WEB/0] OUT at org.apache.catalina.connector.CoyoteAdapter.service(

            2018-09-07T05:08:32.352+0000 [APP/PROC/WEB/0] OUT at org.apache.coyote.http11.Http11Processor.service(

            2018-09-07T05:08:32.352+0000 [APP/PROC/WEB/0] OUT at org.apache.coyote.AbstractProcessorLight.process(

            2018-09-07T05:08:32.352+0000 [APP/PROC/WEB/0] OUT at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(

            2018-09-07T05:08:32.352+0000 [APP/PROC/WEB/0] OUT at$SocketProcessor.doRun(

            2018-09-07T05:08:32.352+0000 [APP/PROC/WEB/0] OUT at

            2018-09-07T05:08:32.352+0000 [APP/PROC/WEB/0] OUT at java.util.concurrent.ThreadPoolExecutor.runWorker(

            2018-09-07T05:08:32.352+0000 [APP/PROC/WEB/0] OUT at java.util.concurrent.ThreadPoolExecutor$

            2018-09-07T05:08:32.352+0000 [APP/PROC/WEB/0] OUT at org.apache.tomcat.util.threads.TaskThread$

            2018-09-07T05:08:32.352+0000 [APP/PROC/WEB/0] OUT at

            2018-09-07T05:08:32.352+0000 [APP/PROC/WEB/0] OUT Caused by:$ErpODataException:

            2018-09-07T05:08:32.352+0000 [APP/PROC/WEB/0] OUT at

            2018-09-07T05:08:32.352+0000 [APP/PROC/WEB/0] OUT at

            2018-09-07T05:08:32.352+0000 [APP/PROC/WEB/0] OUT at

            2018-09-07T05:08:32.352+0000 [APP/PROC/WEB/0] OUT at

            2018-09-07T05:08:32.352+0000 [APP/PROC/WEB/0] OUT at

            2018-09-07T05:08:32.352+0000 [APP/PROC/WEB/0] OUT at

            2018-09-07T05:08:32.352+0000 [APP/PROC/WEB/0] OUT at

            2018-09-07T05:08:32.352+0000 [APP/PROC/WEB/0] OUT at

            2018-09-07T05:08:32.352+0000 [APP/PROC/WEB/0] OUT … 76 common frames omitted

            1. Dennis Hempfing

              The stack trace doesn’t tell much, unfortunately.

              Are you on Neo or on CF? How have you configured your destination and what kind of authentication do you use?

              1. Guoquan Xing

                I am on CF account and the destination is configured as suggested in this blog using on-premise proxy type and basic authentication, as I am an internal SAP employee, I configured to SAP Internal development system with my Internal ID and password, also sap client is also provided. Do you have any hints?

              2. Guoquan Xing

                Hi Dennis,

                I got an error “Unable to fetch the metadata: Failed to execute OData Metadata request.” when requesting /businesspartners resources,  and the log shows an internal 500 error as raised:

                Caused by:$ErpODataException: The endpoint responded with HTTP error code 500.

                based on the log it seems to be an endpoint internal server error, however, when I check the destination connection test the result is positive:

                the virtual host is mapped to an internal host via cloud connector, which also tells the service is reachable:

                According to this information do you have any hints on why I still suffer this issue?



                1. Dennis Hempfing

                  Hi Guoquan,

                  some more questions:

                  1. Which buildpack are you using to deploy your application?
                  2. Do you use our VDM to build your OData query?
                  3. If not, can you share the URL for your OData request?

                  Best regards



Leave a Reply