Execute an Outbound Service from Custom Business Object Logic
- How to get needed service data from SAP Business Accelerator Hub Sandbox
- How to configure outbound service connection in SAP S/4HANA Cloud system
- How to call and process an outbound service in custom business object logic
Prerequisites
- Authorizations: Your user needs business role(s) with business catalogs Extensibility - Custom Business Objects (ID:
SAP_CORE_BC_EXT_CBO), Communication Management (ID:SAP_CORE_BC_COM) and Extensibility - Custom Communication Scenarios (ID:SAP_CORE_BC_EXT_CCS) in your SAP S/4HANA Cloud system - Your user needs access to SAP Business Accelerator Hub.
- Example Objects: Existence of custom business object
Bonus Entitlementas described in Part IV: Associated Business Objects (Bonus Entitlement with - Plan & Sales Order) → Steps 1-4 without release status functionality - Knowledge: (optional) Tutorial: Tour the SAP Business Accelerator Hub
Additional Info
- The example application of
Bonus Entitlementwill be enhanced by a feedback functionality. The manager’s feedback will be translated automatically into English by calling the externally available service SAP Translation Hub of SAP. - Be aware that the example is done with the SAP Business Accelerator Hub Sandbox system only. This shall only give an idea on how it works and cannot be used productively.
- Tutorial feasibility last checked with SAP S/4HANA Cloud Release 2508
- Step 1
To get to know the SAP Translation Hub service first, you can try it out in SAP Business Accelerator Hub.

-
Go to Try out of SAP Translation Hub on SAP Business Accelerator Hub
-
Expand the Translate operations section .
-
Choose the POST operation /translate.
-
Switch to Body section of REQUEST.
-
Exchange the default body with this simplified example.
jsonCopy{ "sourceLanguage": "en", "targetLanguages": [ "es" ], "units": [ { "value": "Your text to be translated" } ] } -
Hit the Run button.
-
The RESPONSE to the service call will appear.
-
- Step 2
To configure the connection to the system and the outbound scenario you will need the service’s end point.
After trying out the service in SAP Business Accelerator Hub, the response appears. Copy the Request URL - which is the end point - from the response section and paste it into a text editor for later use.

To authenticate during a service call later, you will need an API key from the SAP Business Accelerator Hub.
-
Still in SAP Business Accelerator Hub, scroll to top and press Show API Key

A pop up opens.
-
Press Copy Key and Close to save the key to your clipboard.

-
Paste the application key into a text editor for later use.
-
- Step 3
In order to allow communication with the SAP Business Accelerator Hub Sandbox you have to create a communication system for it in your SAP S/4HANA Cloud System.
-
Enter your SAP S/4HANA Cloud system’s Fiori Launchpad.
-
Start typing Communication Systems in the Launchpad search and open the App from the results.

-
Execute the action to create a New Communication System.
-
Enter following Data into the input fields.
Field Label Field Value System ID SANDBOX_API_SAP_COMSystem Name SANDBOX_API_SAP_COM
-
Press Create
The Details screen of the new Communication System opens.
-
Enter as Host Name
sandbox.api.sap.com, which is the domain part of the service’s end point that you got in the previous step. -
Scroll down to the Outbound Users section and press the + button to add an outbound user.
Select the Authentication Method option
Noneas authentication will be done via the API Key directly in coding.
-
Press Create to finish the outbound user creation. The pop up closes.
-
Press Save to finish the communication system creation.
-
- Step 4
Define the external SAP Business Accelerator Hub service as an available Communication Scenario.
-
Start typing Custom Communication Scenario in the Launchpad search and open the App from the results.

-
Execute the action to create a New Custom Communication Scenario.
A pop up opens.
-
Enter following data into the input fields and press the New button
Field Label Field Value Communication Scenario ID SAP_TRANSLATION_HUB(prefixYY1_is added automatically)Description Scenario for SAP Translation Hub
The details UI for the scenario opens.
-
Switch to the Outbound Service section

-
Press Add to start outbound service creation. A pop up opens.

Enter following data into the input fields
Field Label Field Value Description Outbound Service for SAP Translation HubOutbound Service ID OS_SAP_TRANSLATION_HUB(prefixYY1_and suffix_RESTare added automatically)URL Path /sth/translate(service-specific path of the previously obtained request URL) -
Press Create to finish the outbound service creation.
-
Another pop up opens and tells that only one instance of this communication scenario per client will be supported. Confirm with OK.
Both pop ups close. -
Press Save.
-
Press Publish to finish the custom communication scenario creation.
-
- Step 5
Create a Communication Arrangement for the scenario you created, using the designated Communication System.
-
Start typing Communication Arrangements in the Launchpad search and open the App from the results.

-
Execute the action to create a New Custom Communication Arrangement.
A pop up opens.
-
Select or Enter following data.
Field Label Field Value Scenario YY1_SAP_TRANSLATION_HUBArrangement Name YY1_SAP_TRANSLATION_HUB_SANDBOX_API_SAP_COM -
Press Create.

The pop up closes and the Arrangement’s Detail Page opens.
-
Select Communication System
SANDBOX_API_SAP_COM
-
Save the Arrangement.
-
- Step 6
Add fields to persists feedback at the custom business object
Bonus Entitlement.-
Start typing Custom Business Objects in the Launchpad search and open the App from the results.

-
Open the business object
Bonus Entitlement. -
Start Edit Mode by executing the Edit Draft action.
-
Switch to Fields section.
-
Add following New fields
Field Label Field Identifier Field Type Field Properties FeedbackFeedbackTextLength: 255Feedback's languageFeedbacksLanguageTextLength: 2Feedback in englishFeedbackInEnglishTextLength: 255 -
Publish the business object.
-
- Step 7
Now as the business object has just been published, the logic can be enhanced by the translation functionality. ABAP for key users was enhanced by the classes
CL_BLE_HTTP_CLIENT,CL_BLE_HTTP_REQUESTandCX_BLE_HTTP_EXCEPTIONto enable you to work with HTTP requests.-
Switch to Logic section.
-
Enter the After Modification Event Logic and Edit the code .

-
Create the HTTP Client
To call an external service from within your custom business object logic, you need to create an HTTP client.
-
In the existing code, locate the IF block that checks whether
bonusentitlement-bonusplanid IS INITIAL, and insert your logic just before the final ENDIF -
Implement a check if the outbound service is available
abapCopy* Check if the outbound service is available CHECK cl_ble_http_client=>is_service_available( communication_scenario = 'YY1_SAP_TRANSLATION_HUB' outbound_service = 'YY1_OS_SAP_TRANSLATION_HUB_REST' ) = abap_true. -
Implement creation of HTTP client
abapCopy* Create HTTP client to access the outbound service DATA(lo_client) = cl_ble_http_client=>create( communication_scenario = 'YY1_SAP_TRANSLATION_HUB' outbound_service = 'YY1_OS_SAP_TRANSLATION_HUB_REST' ).
-
-
Build the Request Body String
Implement the creation of the Request Body.
Since the goal is to translate any language other than English into English, the target language is set to English. The source language and the feedback to be translated are retrieved from the relevant fields of the custom business object.
The request body in JSON format looks as follows:
jsonCopy{ "sourceLanguage": "es", "targetLanguages": [ "en" ], "units": [ { "value": "Su texto a traducir" } ] }Within the custom business object logic, the request must be provided as a string. Replace the
sourceLanguageandvaluefields with appropriate variables. To generate the JSON string in the required format for the request body, you can use the XCO JSON module, which is part of the Key User (KU) edition of the XCO library.abapCopy* Create request body json string DATA(lo_json_builder) = xco_ku_json=>data->builder( ). lo_json_builder->begin_object( )->add_member( 'sourceLanguage' )->add_string( bonusentitlement-feedbackslanguage )->add_member( 'targetLanguages' )->begin_array( )->add_string( 'en' )->end_array( )->add_member( 'units' )->begin_array( )->begin_object( )->add_member( 'value' )->add_string( bonusentitlement-feedback )->end_object( )->end_array( )->end_object( ). DATA(lv_request_body) = lo_json_builder->get_data( )->to_string( ). -
Create the HTTP Request
Create the HTTP request and set several properties
abapCopy* Creation of the HTTP request DATA(request) = cl_ble_http_request=>create( ). request->set_method( if_ble_http_request=>co_method-post )->set_body( lv_request_body )->set_header_parameter( name = 'APIKey' value = '< YOUR API KEY >' )->set_content_type( 'application/json; charset=utf-8' ). -
Send the Request and Process the Response
-
Implement sending the request by the use of the before created HTTP client and receive the response.
abapCopy* Send a request and receive a response. DATA(response) = lo_client->send( request ). -
Implement getting the response body from the response.
abapCopy* Get the body of the response. DATA(lv_response_body) = response->get_body( ). -
The response body in JSON format will look like this:
jsonCopy{ "units": [ { "value": "Su texto a traducir", "translations": [ { "language": "en", "value": "Your text to translate", "translationProvider": 1, "qualityIndex": 25 } ] } ] } -
Implement logic to extract the translation part from the JSON string using theXCO JSON module.
abapCopy* Get translation from response TYPES: BEGIN OF ts_translation, language TYPE c LENGTH 2, value TYPE string, translation_provider TYPE i, quality_index TYPE i, END OF ts_translation, BEGIN OF ts_unit, value TYPE string, translations TYPE STANDARD TABLE OF ts_translation WITH NON-UNIQUE DEFAULT KEY, END OF ts_unit, BEGIN OF ts_response, units TYPE STANDARD TABLE OF ts_unit WITH NON-UNIQUE DEFAULT KEY, END OF ts_response. DATA ls_response TYPE ts_response. xco_ku_json=>data->from_string( lv_response_body )->apply( VALUE #( ( xco_ku_json=>transformation->pascal_case_to_underscore ) ) )->write_to( REF #( ls_response ) ). bonusentitlement-feedbackinenglish = ls_response-units[ 1 ]-translations[ 1 ]-value.The response of the service call is translated into a corresponding ABAP structure. With help of the built-in Camel case/Pascal case to underscore transformation the JSON data is adjusted to ABAP requirements.
-
Implement error handling
Consider a proper error handling by putting a TRY and CATCH block around the service call logic.
abapCopyTRY . " < CODING PARTS OF THIS STEP FROM BEFORE TO BE PLACED HERE > CATCH cx_ble_http_exception INTO DATA(lx). * The http status code can be checked. CASE lx->status_code. WHEN 404. * Error handling WHEN OTHERS. * Error handling ENDCASE. ENDTRY.
-
-
Save and Publish the After Modification logic.
-
- Step 8
-
Start typing Bonus Entitlement in the Launchpad search and open the App from the results.

-
Open a
Bonus Entitlementin Edit mode. -
Enter following data
Field Label Field Value Feedback Su texto a traducirFeedback’s Language esPlease note that the language code must be entered in lower case to ensure that the service call is successful.
-
Save the Bonus Entitlement. The translation will get filled.
-
- Step 9
Which sequences are possible to execute an outbound service?
- Excursus - Try out the service in SAP Business Accelerator Hub
- Get service end point and API Key
- Create Communication System for Sandbox
- Create custom communication scenario for outbound service
- Create communication arrangement for outbound service
- Extend custom business object data structure
- Enhance custom business object logic
- Test the application
- Test yourself