on 2024 Mar 01 2:54 PM
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
Request clarification before answering.
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.
Open web page with API, see Communication Scenario on main page: Pricing Data Integration (SAP_COM_0294).
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.
Open application Maintain Communication Users, push New.
Type User Name, Description. Push Propose Password button, copy proposed pswd, you will us it for current user.
Create Communication System
Open application Communication Systems, push New, type System Id and System Name.
Get system Host in system properties in ADT
Set up Host Name by System URL.
Set up Users for Inbound Communication and Users for Outbound Communications. Use communication user you created in previous chapter.
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.
Type Scenario ID and Scenario Description.
Lets set up Outbound Services to call API outside this system, push Add.
Set up Description, Service Id and URI:
Push Create Arrangement button (you need to create arrangements in all tenants distinctly).
As result we have Custom Communication Scenario with Outbound Service.
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
95 | |
39 | |
8 | |
6 | |
3 | |
3 | |
3 | |
2 | |
2 | |
2 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.