cancel
Showing results for 
Search instead for 
Did you mean: 

S4 HANA Public Cloud Extensibility

0 Kudos
896

Hi,

Can I use a S4 HANA Public Cloud remote API within S4 HANA Cloud ABAP environment itself instead of SAP BTP ABAP environment, If I don't have any local api available. How to set up the communication scenario if the use of remote api is possible within S4 HANA Cloud itself?

Thanks,

Siva

View Entire Topic
vhardzeyenka
Product and Topic Expert
Product and Topic Expert

Hi Siva.

Sure, in S4HANA Public Cloud system you can call both internal/remote API.

Please go through below steps to call any remove API you need. 

Prerequisites
For accessing applications, you need business user with assigned role SAP_BR_ADMINISTRATOR and SAP_BR_CONF_EXPERT_BUS_NET_INT roles. You can set up required authorization in Maintain Business Users application.
You can check what authorization you need to any application in SAP Fiori Apps Reference Library https://fioriappslibrary.hana.ondemand.com/sap/fix/externalViewer/#/homePage.

Searching for API
Open SAP Business Accelerator Hub https://api.sap.com/ , choose S4HANA Cloud Public Edition -> APIs -> All -> type Pricing Condition in Search field.

vhardzeyenka_0-1711467150167.png

Open web page with API, see Communication Scenario on main page: Pricing Data Integration (SAP_COM_0294).

vhardzeyenka_1-1711467190023.png

Creating Communication User
Open Fiori Launchpad for system. Open system Properties -> ABAP Development -> System URL -> paste into web-browser removing -api part:
https://myXXX-api.lab.s4hana.cloud.sap/ui#Shell-home_ turns into
https://myXXX.lab.s4hana.cloud.sap/ui#Shell-home_ <- paste this one into browser.

vhardzeyenka_2-1711467213726.png

Open application Maintain Communication Users, push New.

vhardzeyenka_5-1711467319181.png

Type User Name, Description. Push Propose Password button, copy proposed pswd, you will us it for current user.

vhardzeyenka_6-1711467348252.png

Create Communication System
Open application Communication Systems, push New, type System Id and System Name.

vhardzeyenka_7-1711467399991.png

Get system Host in system properties in ADT

vhardzeyenka_8-1711467421987.png

Set up Host Name by System URL.

vhardzeyenka_9-1711467443955.png

Set up Users for Inbound Communication and Users for Outbound Communications. Use communication user you created in previous chapter.

vhardzeyenka_10-1711467468608.png

Press Save.


Creating Custom Communication Scenario + Communication Arrangement
As this part belongs to Key User Extensibility, it should be done in CUSTOMIZING tenant (not in DEV one). Open Custom Communication Scenarios application, push New.

vhardzeyenka_11-1711467513495.png

Type Scenario ID and Scenario Description.

vhardzeyenka_12-1711467535929.png

Lets set up Outbound Services to call API outside this system, push Add.
Set up Description, Service Id and URI:

vhardzeyenka_13-1711467560867.png

Push Create Arrangement button (you need to create arrangements in all tenants distinctly).

vhardzeyenka_14-1711467586466.png

vhardzeyenka_15-1711467610578.png

As result we have Custom Communication Scenario with Outbound Service.

vhardzeyenka_16-1711467632720.png

Call API from ABAP Code
Prepare request:

DATA(lo_factory) = cl_com_arrangement_factory=>create_instance( ).

lo_factory->query_ca(
  EXPORTING
	is_query = VALUE #( cscn_id_range = VALUE #( ( sign = 'I' option = 'EQ' low = 'YY1_XXX_SAP_COM_0294' ) ) ) " Custom Communication Scenario
  IMPORTING
	et_com_arrangement = DATA(lt_comm_arrang) ).

DATA(lo_comm_arrang) = lt_comm_arrang[ 1 ].

TRY.
	DATA(lo_destination) = cl_http_destination_provider=>create_by_comm_arrangement(
	  comm_scenario  = CONV #( 'YY1_XXX_SAP_COM_0294' )" Use Custom Communicaiton Scenario, Not standard!
	  comm_system_id = lo_comm_arrang->get_comm_system_id( )
	  service_id     = CONV #( 'YY1_SLSPRICINGCONDITIONREC_REST' )" Outbound Service ID
	).
  CATCH cx_http_dest_provider_error INTO DATA(lo_error).
	DATA(lv_message) = lo_error->get_longtext( ).
ENDTRY.

TRY.
	eo_client = cl_web_http_client_manager=>create_by_http_destination( i_destination = lo_destination ).
  CATCH cx_web_http_client_error.
ENDTRY.

eo_request = eo_client->get_http_request( ).

eo_request->set_uri_path( i_uri_path = |{ iv_entity }{ iv_request_params }| ). // A_SlsPrcgConditionRecord('000001245')

Call GET method:

    TRY.
        DATA(lo_response) = io_client->execute( i_method = if_web_http_client=>get ).
      CATCH cx_web_http_client_error.
    ENDTRY.

    lv_resp_satus = lo_response->get_status( ).
    lv_resp_text = lo_response->get_text( ).

    /ui2/cl_json=>generate(
      EXPORTING
        json    = lv_resp_text
      RECEIVING
        rr_data = DATA(lt_cr_data)
    ).

 Hope it was helpful.

Best regards

Vitali

NAVI
Explorer
0 Kudos

Hello,

It works before but now give 401 - Authorization error.

NAVI_0-1730651667791.png

Sorry, solved, my mistake 🙂