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
The example application of Bonus Entitlement will 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 2602
Step 1Excursus - Try out the service in SAP Business Accelerator Hub
—
To get to know the SAP Translation Hub service first, you can try it out in SAP Business Accelerator Hub.
Try out of SAP Translation Hub on SAP Business Accelerator Hub
Exchange the default body with this simplified example.
JSON
{"sourceLanguage":"en","targetLanguages":["es"],"units":[{"value":"Your text to be translated"}]}
Hit the Run button.
The RESPONSE to the service call will appear.
Step 2Get service end point and API Key
+
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.
Service End Point: Request URL in response section
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
Button to show API Key of in SAP Business Accelerator HubA pop up opens.
Press Copy Key and Close to save the key to your clipboard.
Pop Up to Copy API Key
Paste the application key into a text editor for later use.
Step 3Create Communication System for Sandbox
+
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.
Communication Systems application from search 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_COM
System Name
SANDBOX_API_SAP_COM
Pop Up to create New Communication System
Press Create
The Details screen of the new Communication System opens.
Enter as Host Namesandbox.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 None as authentication will be done via the API Key directly in coding.
Pop Up to create New Outbound
Press Create to finish the outbound user creation. The pop up closes.
Press Save to finish the communication system creation.
Step 4Create custom communication scenario for outbound service
+
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.
Custom Communication Scenario application from search 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 (prefix YY1_ is added automatically)
Description
Scenario for SAP Translation Hub
Scenario creation pop up
The details UI for the scenario opens.
Switch to the Outbound Service section
Switch to outbound services in scenario maintenance
Press Add to start outbound service creation. A pop up opens.
Pop Up to create outbound service
Enter following data into the input fields
Field Label
Field Value
Description
Outbound Service for SAP Translation Hub
Outbound Service ID
OS_SAP_TRANSLATION_HUB (prefix YY1_ and suffix _REST are 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 5Create communication arrangement for outbound service
+
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.
Custom Communication Arrangements application from search 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_HUB
Arrangement Name
YY1_SAP_TRANSLATION_HUB_SANDBOX_API_SAP_COM
Press Create.
Communication Creation Pop Up
The pop up closes and the Arrangement’s Detail Page opens.
Select Communication System SANDBOX_API_SAP_COM
Communication System Selection in Communication Arrangement
Make sure the outbound service for SAP Translation Hub is active and Save the Arrangement.
Step 6Extend custom business object data structure
+
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.
Custom Business Objects application from search 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
Feedback
Feedback
Text
Length: 255
Feedback's language
FeedbacksLanguage
Text
Length: 2
Feedback in english
FeedbackInEnglish
Text
Length: 255
Publish the business object.
Step 7Enhance custom business object logic
+
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_REQUEST and CX_BLE_HTTP_EXCEPTION to enable you to work with HTTP requests.
Switch to Logic section.
Enter the After Modification Event Logic and Edit the code .
Enter After Modification logic
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
ABAP
* Check if the outbound service is availableCHECKcl_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
ABAP
* Create HTTP client to access the outbound serviceDATA(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:
JSON
{"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 sourceLanguage and value fields 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.
ABAP
* Create request body json stringDATA(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
ABAP
* Creation of the HTTP requestDATA(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.
ABAP
* Send a request and receive a response.DATA(response)=lo_client->send(request).
Implement getting the response body from the response.
ABAP
* Get the body of the response.DATA(lv_response_body)=response->get_body().
The response body in JSON format will look like this:
JSON
{"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 the XCO JSON module.
ABAP
* Get translation from responseTYPES:BEGIN OFts_translation,languageTYPE cLENGTH2,valueTYPE string,translation_providerTYPE i,quality_indexTYPE i,END OFts_translation,BEGIN OFts_unit,valueTYPE string,translationsTYPE STANDARD TABLE OFts_translationWITHNON-UNIQUEDEFAULTKEY,END OFts_unit,BEGIN OFts_response,unitsTYPE STANDARD TABLE OFts_unitWITHNON-UNIQUEDEFAULTKEY,END OFts_response.DATAls_responseTYPE 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.
ABAP
TRY." < CODING PARTS OF THIS STEP FROM BEFORE TO BE PLACED HERE >
CATCHcx_ble_http_exceptionINTODATA(lx).* The http status code can be checked.CASElx->status_code.WHEN404.* Error handlingWHENOTHERS.* Error handlingENDCASE.ENDTRY.
Save and Publish the After Modification logic.
Step 8Test the application
+
Start typing Bonus Entitlement in the Launchpad search and open the App from the results.
Bonus Entitlements application from search results
Open a Bonus Entitlement in Edit mode.
Enter following data
Field Label
Field Value
Feedback
Su texto a traducir
Feedback’s Language
es
Please 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.
Share feedback on this tutorial or join the conversation in SAP Community.
Submit detailed feedbackDiscuss in Community
Steps
Step 1 of 9
1. Excursus - Try out the service in SAP Business Accelerator Hub2. Get service end point and API Key3. Create Communication System for Sandbox4. Create custom communication scenario for outbound service5. Create communication arrangement for outbound service6. Extend custom business object data structure7. Enhance custom business object logic8. Test the application9. Test yourself
Joule
AI Notice
Joule is an AI assistant. Generative AI may produce inaccurate, incomplete, or biased information. Always verify important details before acting on them.
Conversations are sent to SAP-hosted large language models for processing. Do not include personal data, credentials, or confidential information in your messages.
Joule's responses are based on the SAP tutorial catalog and may not reflect the latest product changes. For authoritative guidance, consult the linked tutorials and official SAP documentation.