cancel
Showing results for 
Search instead for 
Did you mean: 

How to call a BAPI / RFC from BTP Java Application

Animatron56
Participant
0 Kudos

Currently I have the use case, where I need to call a BAPI / RFC in an onpremise system to adapt a users master data (like first name and SNC).

I have read in the cloud SDK Docu that this can be achieved with Java via the cloud connector. I know that the cloud sdk collegues will remove this feature in the future as they have written in the official documentation, but I still wanted to try that out (official docu: https://sap.github.io/cloud-sdk/docs/java/features/bapi-and-rfc/overview) Since it is written, that this feature will still be available for Cloud SDK version 5, I believe that it should still be available and working at the moment.

Therefore I have read how this setup can be achieved and setup a java application like the one from fukuhara here: https://blogs.sap.com/2020/05/08/how-to-call-function-modules-using-sap-cloud-sdk-for-java/comment-p...

Unfortunately this did not work for me. I always get the following error:

jakarta.servlet.ServletException: Handler dispatch failed: java.lang.NoClassDefFoundError: com/sap/conn/jco/JCoException

Becasue of this error I was wondering, if this feature is still available and can be used or if it has been removed now.?Additionally I wanted to know if there is another option to access RFC / BAPIs from a CAP application?

I have also tested a bit with node-rfc (see here: https://github.com/SAP/node-rfc), but since for Java this feature is / was built-in, I tried my luck with the first method.

Thank you very much and best regards!

Accepted Solutions (0)

Answers (1)

Answers (1)

Ulrich_Schmidt
Product and Topic Expert
Product and Topic Expert

The JCo classes should already be pre-installed in any SAP Cloud VM (Neo and CloudFoundry), so you are probably only missing a reference in the deployment descriptor of your app.

Please check the following documentation, it describes the necessary prerequisites and also contains a sample app calling a function module via JCo:

Invoking ABAP Function Modules via RFC | SAP Help Portal

Ivan-Mirisola
Product and Topic Expert
Product and Topic Expert

Hi beniseeger_98,

As you mentioned, the RFC and BAPI assessor classes that are present on v4 of Cloud SDK for Java were deprecated in favor of more modern and standardized means to interact with SAP systems. If you think about cloud SaaS solutions such as S/4HANA, there is no direct access to BAPIs or FMs via RFC protocol (RFMs). Hence, this is a major reason why SAP isn't going to support the type of access via Cloud SDK. So, developers should avoid it as much as possible.

Just to add to what ulrich.schmidt mentioned here.

You could potentially leverage the Cloud SDK's ability to make calls to an on-premise system via SOAP services like "/sap/bc/soap/wsdl11" which would allow you to make generic calls to any BAPI in your system via SOAP protocol - as long as the service is activated and you have to the proper authorizations. Here is a blog that will show you how the service's payload should be constructed so you can make it work:

https://blogs.sap.com/2022/11/03/cloud-integration-creating-xml-structure-for-remote-function-call-r.../

Even if you aren't using Cloud Integration, you can easily adapt the information from the blog it to your needs (i.e.: to call the SOAP service in Java or NodeJS using Cloud SDK's Assessor Classes for SOAP calls).

Or, if your company doesn't allow the above service to be enabled for security reasons, you could still leverage Cloud SDK's capabilities by generating a SOAP service individually for each BAPI you need to call on BTP. Here is another blog:

https://blogs.sap.com/2023/05/17/generate-soap-services-for-your-legacy-rfcs-to-simplify-integration.../

Now, if you absolutely cannot avoid making direct calls via JCo, then here are a few things to consider:

3) The example provided on the help documentation linked by my colleague Ulrich refers to the creation of a very simple servlet using Eclipse and old school web development. This approach is not as modern as using Spring Boot framework (which simplifies development - specially in terms of how it integrates with XSUAA and App Router to provide JWT forwarding, etc.

Once you opt to use Spring as framework for your development, you must import the JCo libraries manually into your development system for compilation purposes. Without it in place you won't be able to produce a compiled package on your machine for deployment.

You can follow the steps on the below documentation for maven projects:

https://sap.github.io/cloud-sdk/docs/java/features/bapi-and-rfc/overview#download-and-install-jco-li...

Just to clarify: SAP cannot freely distribute SAP JCo libraires via Maven Repositories due to licensing restrictions. Only SAP customers that have access to download and SAP software while on countries that are under unrestricted export regulations.

2) The Java Buildpack must enable the usage of the JCo jar libraries so your CF Cell is able to load it on your application (remember, you aren't allowed to freely distribute the library, so you cannot embed it on your deployable package).

In order to enable it, you must add the following to your manifest.yml:

https://help.sap.com/docs/btp/sap-business-technology-platform/sap-java-connector

This ensures that only SAP customers (licensed BTP users that are on unrestricted export license regulations) can run software created with the JCo libraries.

3) You are not prohibited to use the deprecated classes on SAP Cloud SDK for Java to make calls to BAPIs and FMs via RFC protocol (RFMs). However, you will be stuck on version 4. The newest version (v5) doesn't have the required jar file that contains the assessor classes. Therefore, in order to create a maven project using v4, you must follow the steps from this documentation:

https://sap.github.io/cloud-sdk/docs/java/v4/getting-started

Keep in mind that you will be stuck on this version of Cloud SDK - which is not recommended since you won't benefit from updates, patches, fixes, etc.

4) When everything else fails, check the following documentation as well:

https://sap.github.io/cloud-sdk/docs/java/features/bapi-and-rfc/overview#boundary-conditions-and-edg...

Here you will find some deprecated examples and fixes to common errors.

Hope this helps.

Best regards,
Ivan

Ulrich_Schmidt
Product and Topic Expert
Product and Topic Expert

Great additional content and thoughts ivan.mirisola thanks! But nevertheless I would like to point out two "inaccuracies" in the used technical terms/nomenclature:

  • Java Connector should be abbreviated with "JCo", not "JCO".
  • And there is no such thing as "RFCs". "RFC" is the name of a network communication protocol just like "HTTP". No one would say "access to HTTPs" or "calls to HTTPs", but instead one would use the name for the "things that can be called via HTTP protocol", which are for example REST APIs, WebServices or OData Services. So one would say e.g. "calls to REST APIs".

    And similarly one would use the name for the "things that can be called via RFC protocol", which are "remote-enabled function modules" or abbreviated "RFMs". So instead of "calls to BAPIs and RFCs" it should correctly be "calls to BAPIs and RFMs"...

Best Regards, Ulrich

Ivan-Mirisola
Product and Topic Expert
Product and Topic Expert

Thanks ulrich.schmidt for pointing these things. I've known this for years. However, it is still hard to avoid such inaccuracies in nomenclature when people out there still refer to them in such a way.

Anyway, I've made corrections to the text in my answer.

Best regards,
Ivan