Skip to Content
Technical Articles
Author's profile photo Shilpi Sen

How to Extend SAP S/4HANA Business Address Services (or any other SAP S/4HANA application) with Serverless Functions on Kyma Part-III

Introduction

This blog post explains how a Serverless Function developed in Kyma Runtime can be consumed in the SAP S/4HANA system for the extensibility of SAP S/4HANA applications. Specifically, this blog post covers the extensibility of Business Address Services and is in continuation of Blog Series of the same title(mentioned under Prerequisites).

Prerequisites/Skills

  1. ABAP
  2. Kyma Environment Setup explained in Part-I of this Blog Series
  3. Kyma Serverless Function Implementation explained in Part-II of this Blog Series

 

In our example, we will be implementing the geocode functionality with the Business Partner (BP) transaction. Once our serverless function returns the geocodes, we will be updating a Custom Z table.

  • Since it is a customer modification, we can make use of the BADIs available. ADDRESS_UPDATE is the BADI that is used to trigger updates on Address Changes. We have implemented this BADI in SE18 as ZADDRESS_UPD_SRV_POC. The implementing class name is given as ZCL_IM_ADDRESS_UPD_SRV_POC

 

  • BADi%20for%20Update
  • Based on the type of address created i.e. Organization, Person, or Workplace, add the logic in methods ADDRESS1_SAVED, ADDRESS2_SAVED, and ADDRESS3_SAVED                    respectively. Next, we must compile the complete URL which will be a combination of:
    • URL generated by Kyma runtime
    • Search parameters from BP transaction which will be components of address based on which Geocode will be found. For our PoC, we have considered House Number, Street, City, Region, Postal Code, and Country

 

 DATA(url) = 'https://get-geocodes.fdc4fe9.kyma.shoot.live.k8s-hana.ondemand.com/?address='.
    LOOP AT im_t_xadrc ASSIGNING FIELD-SYMBOL(<fs_xadrc>).

      IF <fs_xadrc>-house_num1 IS NOT INITIAL.
        full_address = <fs_xadrc>-house_num1.
      ENDIF.
      IF <fs_xadrc>-street IS NOT INITIAL.
        CONCATENATE full_address <fs_xadrc>-street INTO full_address SEPARATED BY space.
      ENDIF.
      IF <fs_xadrc>-city1 IS NOT INITIAL.
        CONCATENATE full_address <fs_xadrc>-city1 INTO full_address SEPARATED BY space.
      ENDIF.
      IF <fs_xadrc>-region IS NOT INITIAL.
        CONCATENATE full_address <fs_xadrc>-region INTO full_address SEPARATED BY space.
      ENDIF.
      IF <fs_xadrc>-post_code1 IS NOT INITIAL.
        CONCATENATE full_address <fs_xadrc>-post_code1 INTO full_address SEPARATED BY space.
      ENDIF.
      IF <fs_xadrc>-country IS NOT INITIAL.
        CONCATENATE full_address <fs_xadrc>-country INTO full_address SEPARATED BY space.
      ENDIF.
      REPLACE '#' WITH space INTO full_address.
      SHIFT full_address LEFT DELETING LEADING space.
      CONDENSE full_address.
      CONCATENATE url full_address INTO DATA(final_url).
    ENDLOOP.

 

  • Next, an HTTP client for the generated URL must be created. This is done by calling the method CREATE_FROM_URL of class CL_HTTP_CLIENT. This HTTP client is used to send the request to Kyma Serverless Runtime and receive in response the Geocodes of the provided search parameters.

 

"create HTTP client by url
    CALL METHOD cl_http_client=>create_by_url
      EXPORTING
        url                = final_url
      IMPORTING
        client             = lo_http_client
      EXCEPTIONS
        argument_not_found = 1
        plugin_not_active  = 2
        internal_error     = 3
        OTHERS             = 4.

    IF sy-subrc <> 0.
      "error handling
    ENDIF.

*** Send the request
    lo_http_client->send(
      EXCEPTIONS
        http_communication_failure = 1
        http_invalid_state         = 2 ).

*** Receive the respose
    lo_http_client->receive(
       EXCEPTIONS
         http_communication_failure = 1
         http_invalid_state         = 2
         http_processing_failed     = 3 ).

 

  • Finally, we read the result from the HTTP response and update our custom table with the        Geocode.
*** Read the result
      lv_result = lo_http_client->response->get_cdata( ).
      IF lv_result NP 'Internal Server Error'.
        ls_geocode-mandt = sy-mandt.
        ls_geocode-addrnumber = im_address_number.
        SPLIT lv_result AT ',' INTO ls_geocode-latitude ls_geocode-longitude.

        MODIFY zaddress_geocode FROM ls_geocode.
      ENDIF.

 

  • The Custom table structure is as below:

Custom%20Table

 

  • Next, in BP transaction we must create an Organization BP with the values below for address fields which in turn will be considered for the final URL generation:

BP%20Transaction

 

  • The address number of the BP above is:

Address%20Number%20of%20BP

 

  • On Save of the Business Partner, the custom table ZADDRESS_GEOCODE is updated:

Table%20Entry%20Updated

 

Note: We did not enhance the BP transaction to display these coordinates, but such enhancements can be taken up if required for the project.

Summary

In this blog post, we have seen how a Serverless Function developed in Kyma Runtime can be consumed in the SAP S/4HANA system for the extensibility of Business Address Services or any other SAP S/4HANA applications.

Assigned tags

      Be the first to leave a comment
      You must be Logged on to comment or reply to a post.