Create all ABAP artifacts with namespace Z...
for local development.
Always replace XXX
with your initials or group number.
Step 1: Download service metadata
-
Copy the service URL from communication arrangement on S/4 HANA Cloud system in a browser.
-
Remove -api
from your URL an add /$metadata
at the end of the link and press enter. Login with your communication user and password.

-
Right click the page and save the Metadata as a .edmx
file.

Step 2: Create your own ABAP package
Mark the steps 2 as completed by pressing Done
if you have already created the package Z_Package_XXX
(where XXX is your group number) in the previous tutorials.
-
Open Eclipse and connect to your system.
-
Right click the main package ZLOCAL and choose New > ABAP Package.
-
Create your own ABAP development package Z_PACKAGE_XXX
as a sub package of ZLOCAL.
- Name:
Z_PACKAGE_XXX
- Description:
my new package
-
Click on Next.

-
Select package properties and press Next.
- Software Component:
ZLOCAL
-
Select a transport request and create your ABAP package with Finish.

You can add your package to Favorite Packages.
Step 3: Add service consumption model
-
Mark your package under ZLOCAL or in Favorite Packages and click on File and choose New > Other… > Service Consumption Model.

-
Click on Next.

Step 4: Create service consumption model
-
Enter a name for your service consumption model, a service definition will be generated as part of the service consumption model with this name.
-
Enter a description and upload the .edmx
file, which you saved before, in the Service Metadata File field.
-
Click Next.

Step 5: Change ABAP artifact names
-
Add the XXX
at the end of each name.
-
Click on Next.

Step 6: ABAP artifact generation list
-
Click on Next by artifact generation list.

-
Select a transport request.
-
Click on Finish.

Step 7: Check created service definition
Open service definitions in your package and make sure if your new service definition is created successfully.
Step 8: Add HTTP service
-
Right click your package and choose New > Other ABAP Repository Object > HTTP Service.

-
Click Next.

Step 9: Create HTTP service
-
Enter a name and a description.
- Name:
ZS4_BUPA_XXX
- Description:
call S/4 Business Partner
-
Click Next.

-
Select a transport request and click on Finish.

Step 10: Create handler class
-
Go to the HTTP Service that you created in the last step.
-
Open Handler Class.

-
Copy the code in the class and change it with your data.
i_service_instance_name |
the value of the service instance name property of the communication arrangement |
i_name |
the name of the destination |
i_authn_mode |
if_a4c_cp_service =>user_propagation |
iv_service_definition_name |
Data definition created as part of client proxy |
Retrieve Name of ZA_BusinessPartner_XXX
Data Definition.
CLASS zcl_s4_bupa_xxx DEFINITION PUBLIC CREATE PUBLIC .
PUBLIC SECTION.
INTERFACES if_http_service_extension .
ENDCLASS.
CLASS zcl_s4_bupa_xxx IMPLEMENTATION.
METHOD if_http_service_extension~handle_request.
TRY.
DATA(lo_destination) = cl_http_destination_provider=>create_by_cloud_destination(
i_name = 'S4BusinessPartnerOAuth2'
i_service_instance_name = 'OutboundCommunication'
i_authn_mode = if_a4c_cp_service=>user_propagation
).
cl_web_http_client_manager=>create_by_http_destination(
EXPORTING
i_destination = lo_destination
RECEIVING
r_client = DATA(lo_http_client)
).
**Relative service path**
lo_http_client->get_http_request( )->set_uri_path( '/sap/opu/odata/sap/API_BUSINESS_PARTNER' ).
lo_http_client->set_csrf_token( ).
DATA(lo_client_proxy) = cl_web_odata_client_factory=>create_v2_remote_proxy(
iv_service_definition_name = 'ZS4_API_BUSINESS_PARTNER_XXX'
io_http_client = lo_http_client
iv_relative_service_root = '/sap/opu/odata/sap/API_BUSINESS_PARTNER' ).
**Entity set A_BUSINESSPARTNER in business partner integration service**
DATA(lo_create_request) = lo_client_proxy->create_resource_for_entity_set('A_BUSINESSPARTNER')->create_request_for_create( ).
DATA(lv_userid) = cl_abap_context_info=>get_user_technical_name( ).
SELECT SINGLE *
FROM i_businessuser
WITH PRIVILEGED ACCESS
WHERE userid = @lv_userid INTO
@DATA(ls_businessuser).
IF sy-subrc <> 0.
response->set_text( |Error retrieving business user { lv_userid }| ).
RETURN.
ENDIF.
DATA(ls_bupa) = VALUE za_businesspartner_XXX(
businesspartnercategory = '1'
firstname = ls_businessuser-firstname
lastname = ls_businessuser-lastname
).
lo_create_request->set_business_data( ls_bupa ).
DATA(lo_create_response) = lo_create_request->execute( ).
lo_create_response->get_business_data( IMPORTING es_business_data = ls_bupa ).
response->set_text( |Business parter { ls_bupa-businesspartner } was created| ).
CATCH cx_root INTO DATA(lx_exception).
response->set_text( lx_exception->get_text( ) ).
ENDTRY.
ENDMETHOD.
ENDCLASS.
Step 11: Test service with business user
-
Navigate to HTTP service and click On URL.

-
Enter business user email and password and click Log on.
business user requires the SAP_BR_BUPA_MASTER_SPECIALIST
business role.
This User has the same email-address for both S/4 HANA and SAP BTP ABAP Environment.

You see that a Business Partner is created.
- Copy the Business Partner number.

Step 12: Open maintain business partner in SAP S/4 HANA
-
Open SAP Fiori Launchpad and login with the business user.

-
Navigate to Business Partner Master > Maintain Business Partner.

Step 13: Verify business partner in SAP S/4 HANA
Enter created Business Partner number in the related field and press enter.
Check data of the created business service.