[SAP S/4HANA CLOUD] – KEY USER EXTENSIBILITY WITH CUSTOM LOGIC & FIELD

As we known, S/4 HANA cloud public edition support extensions like Key User, Developer and Side by side extensibility. In this article I want to share my understanding for Key User Extensibility by using Custom filed, Custom logic and User interface adaptation.

BUSINESS SCENARIO

Master data specialist go to app Manage Customer Master to maitain customer. Business requirement in this persective is add custom field into this app called VAT_COUNTRY and VAT_NUMBER. When he input VAT_COUNTRY and VAT_NUMBER, App will call to external service to check VAT number valid or not. If VAT number valid, customer will be saved, else customer can not save.

BUSINESS DIAGRAM

SOLUTION APPROACH

Create custom filed VAT_COUNTRY and VAT_NUMBER (Custom field)

Add Custom field into Manage Customer Master App ( User Interface Adaptation – Adapt UI)

Configuration communication system for service external (Communication System)

Configuration custom communication scenario and create outbound service (Custom Communication Scenario)

Configuration communication arrangement

Create custom logic with BAdI Validate Customer Master (Custom Logic)

Write Code ABAP call to external service.

STEP BY STEP CONFIGURATION

CREATE CUSTOM FIELD

Default this custom field will be not display anywhere untill we enable it.

If we want to use this custom filed in CDS view I_Customer, we need to active it

Check on CDS view again

OK, come back our scenario, we need to enable it on UI of Manage Customer Master App. So we need to enable it

USER INTERFACE ADAPTATION (ADAPT UI)

Because of we created custom field with business context is Customer Core View so we need to select section accordingly

The same way we will create more custom field is VAT_Number and add them into UI

CREATE CUSTOM LOGIC

Implement BAdI to Call the External VAT Service

in this section, we will add code ABAP call to external service API to validate VAT number. Assumption that we configured communication system, communication user, custom scenario, communication arrangement successful.

Reference Code


* Declaration of required parameters
  DATA ls_cust_gen LIKE LINE OF it_customer_gen.
  DATA ls_validationmessage LIKE LINE OF ct_validationmessage.

"read the Customer General Data
  READ TABLE it_customer_gen INTO ls_cust_gen WITH KEY businesspartner = i_cmd_bp_object_key-businesspartner businesspartneruuid = i_cmd_bp_object_key-businesspartneruuid.

* check if the custom fields are filled
  CHECK ls_cust_gen-include-yy1_vat_country_cus IS NOT INITIAL.
  CHECK ls_cust_gen-include-yy1_vat_number_cus IS NOT INITIAL.

* Check if outbound service exists in the communication scenario
* Replace the values for communication_scenario and outbound_service as required.
  CHECK cl_ble_http_client=>is_service_available(
    communication_scenario = 'YY1_COMM_SCENARIO'
    outbound_service       = 'YY1_COMM_OUTBOUND_REST'
    ) = abap_true.

* Creation of the HTTP client to access the outbound service
* Replace the values for communication_scenario and outbound_service as required.
  DATA(lo_client) = cl_ble_http_client=>create(
    communication_scenario = 'YY1_VALIDATE_VAT'
    outbound_service       = 'YY1_YY1_VALIDATE_VAT_REST_REST'
    ).
  DATA lv_vatnumber type string.

* convert number field to string
  lv_vatnumber = ls_cust_gen-include-yy1_vat_number_cus.
  CONCATENATE '/' ls_cust_gen-include-yy1_vat_country_cus '/' lv_vatnumber INTO DATA(lv_vat).

* Call service
  DATA(request) = cl_ble_http_request=>create( ).
  request->set_method( 'GET' )->set_resource_extension( lv_vat ).
  TRY .
  DATA(response) = lo_client->send( request ).

* Get the body of the response if required.
    DATA(lv_body) = response->get_body( ).
	CATCH cx_ble_http_exception INTO DATA(lx).

* The http status code can be checked.
	CASE lx->status_code.
	WHEN 404.
	ls_validationmessage-msgty = 'E'.
        ls_validationmessage-msgid = 'CVI_API'.
        ls_validationmessage-msgno = '001'.
        ls_validationmessage-MSGV1 = '404'.
        APPEND ls_validationmessage TO ct_validationmessage.
  
        WHEN 500.
       ls_validationmessage-msgty = 'E'.
        ls_validationmessage-msgid = 'CVI_API'.
        ls_validationmessage-msgno = '001'.
        ls_validationmessage-MSGV1 = '500'.
        APPEND ls_validationmessage TO ct_validationmessage.
	WHEN OTHERS.
	ls_validationmessage-msgty = 'E'.
        ls_validationmessage-msgid = 'CVI_API'.
        ls_validationmessage-msgno = '001'.
        ls_validationmessage-MSGV1 = 'OTHERS'.
        APPEND ls_validationmessage TO ct_validationmessage.

	ENDCASE.

ENDTRY.

Test custom logic code

Test on Manage Customer Master App

CONCLUSION

In this article I shared a way how to add more custom field into user interface and implement BAdI with custom logic. In the same way we can implement key user extensibility for some business requirement like Validate fields, Prepopulate a custom field ,etc. Thanks for your reading and adny advise kindly leave your comment on this.

Thanks.

Joseph

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.