cancel
Showing results for 
Search instead for 
Did you mean: 

How to consume S/4HANA Cloud API using ABAP program from the same S/4HANA Cloud system

yongkc
Explorer
1,043

Hi,

We're building a Fiori app prototype in S/4HANA Cloud on stack ABAP environment which can be used to post supplier invoice via API below:

Overview | Supplier Invoice | SAP Business Accelerator Hub

The prototype is to demonstrate Fiori app capability to consume API services from the same S/4HANA Cloud system.

In our program we are using class cl_web_http_client_manager to instantiate the HTTP client in ABAP environment as shown below:

The problem with this code is that we need to put in the username and password in the program as shown in the code from line 107 - 108. Without this the program will not be able to call the API from the same system.

Is there better alternative which we can opt for to consume the API without having the need of putting in the logon credential in the program? Otherwise, is it possible to obtain the user id and password by reading the communication user data in S/4HANA Cloud via CDS view or other class/method approach?

We've configured the corresponding communication arrangement in the system as shown below:

We've also tried using Business Object Interface but it does not work either.

In the behaviour definition, we implemented an action as shown below:

Code below is the implementation:

The app fails right away when it executes the MODIFY ENTITIES statement. Below is the error message we captured from S/4HANA Cloud:

Is there any prerequisite that we need to be aware of for using Business Object Interface in S/4HANA Cloud?

Thanks.

TamasFodor
Product and Topic Expert
Product and Topic Expert
0 Kudos

Hi,

We helped you to accept the answer, since there were no updates after a few days. You can unaccept it anytime if you have further questions.

Kind regards,

Tamas

SAP Community Topic Expert

View Entire Topic
kaidehmann
Product and Topic Expert
Product and Topic Expert

Hi Kah Choon Simon Yong,

please follow Developing External Service Consumption (Outbound Communication): create a communication scenario in ADT, and then configure a communication system and arrangement for the scenario.

DATA(lo_destination) = cl_http_destination_provider=>create_by_comm_arrangement(
	comm_scenario        = '<SCENARIO ID>'
	service_id           = '<OUTBOUND SERVICE ID>'
	comm_system_id       = system_id ).

The credentials will be stored safely in the communication system.

The concept is explained here: Communication Management

Best regards
Kai

Gheorghe-Valer
Explorer
0 Kudos
Hi Kaidehmann,
Gheorghe-Valer
Explorer
0 Kudos
Hi Kaidehmann, It doesn´t make any sense to go out with a communication arrangement to consume a service that is defined on the same instance. SAP doesn't offer any alternative to consume the business object directly from my own server? Or to invoke the CRUD operations on those objects?
kaidehmann
Product and Topic Expert
Product and Topic Expert

Hi @Gheorghe-Valer,

I apologize: I was too fast and did not read the entire question thoroughly enough, and I was caught by the question "Is there better alternative ... without having the need of putting in the logon credential in the program." So I was focusing on the question where to store user name and password in case of remote connectivity. I did not realize that the actual requirement is to call an API within the same system. In that case, the recommended approach is using the corresponding business object interface, of course. I will add another answer.

Best regards
Kai