Friday 30 September 2022

Add a validation to a Custom Field via Developer Extensibility in SAP S/4HANA Cloud

Introduction


With the introduction of Three System Landscape(3SL) in SAP S/4HANA Cloud, developers will now be able to create development projects via Eclipse IDE with the help of ABAP Development Tools (ADT)

In this blog, I will take you through a simple example of how to add a screen validation to a Custom field created via Key-User Extensibility in the Development 100 client using Developer Extensibility in the Development 080 client

Implementation


Let’s take the example of the custom field ‘Enhancement Field 1’ which was created via Key-User Extensibility in the Development 100 system

SAP S/4HANA Cloud, SAP ABAP Development, SAP ABAP Extensibility, SAP S/4HANA Cloud Extensibility, SAP ABAP Career, SAP ABAP Skills, SAP ABAP Jobs, SAP ABAP Tutorial and Materials, SAP ABAP Prep, SAP ABAP Preparation

Now, create a BAdI implementation in the Development 080 client to add a validation such that the Sales Order should not be saved if this field is empty.

As shown in the following screenshot, after logging into the Development 080 Client, I have derived a new tree for Application Components.

SAP S/4HANA Cloud, SAP ABAP Development, SAP ABAP Extensibility, SAP S/4HANA Cloud Extensibility, SAP ABAP Career, SAP ABAP Skills, SAP ABAP Jobs, SAP ABAP Tutorial and Materials, SAP ABAP Prep, SAP ABAP Preparation

By deriving this tree, it will be easier for me to search and identify the enhancement spot I am looking for.

Now that the enhancement spot, ES_SD_SLS_EXTEND, is identified, right click on the enhancement spot and click on ‘New BAdI Enhancement Implementation’ to create a new Enhancement Implementation.

SAP S/4HANA Cloud, SAP ABAP Development, SAP ABAP Extensibility, SAP S/4HANA Cloud Extensibility, SAP ABAP Career, SAP ABAP Skills, SAP ABAP Jobs, SAP ABAP Tutorial and Materials, SAP ABAP Prep, SAP ABAP Preparation

Provide a Package name, Enhancement Implementation Name and Description and click on Next. The field ‘Enhancement Spot’ is automatically filled as the implementation is created by directly clicking on the Enhancement Spot

SAP S/4HANA Cloud, SAP ABAP Development, SAP ABAP Extensibility, SAP S/4HANA Cloud Extensibility, SAP ABAP Career, SAP ABAP Skills, SAP ABAP Jobs, SAP ABAP Tutorial and Materials, SAP ABAP Prep, SAP ABAP Preparation

Provide an existing transport request or create a new transport request and click on Finish

SAP S/4HANA Cloud, SAP ABAP Development, SAP ABAP Extensibility, SAP S/4HANA Cloud Extensibility, SAP ABAP Career, SAP ABAP Skills, SAP ABAP Jobs, SAP ABAP Tutorial and Materials, SAP ABAP Prep, SAP ABAP Preparation

This will create an Enhancement Implementation. Now add a BAdI implementation by clicking on ‘Add BAdI Implementation’ as shown below

SAP S/4HANA Cloud, SAP ABAP Development, SAP ABAP Extensibility, SAP S/4HANA Cloud Extensibility, SAP ABAP Career, SAP ABAP Skills, SAP ABAP Jobs, SAP ABAP Tutorial and Materials, SAP ABAP Prep, SAP ABAP Preparation

Provide the BAdI definition name by clicking on the browse button and provide an implementation name and click on Add

SAP S/4HANA Cloud, SAP ABAP Development, SAP ABAP Extensibility, SAP S/4HANA Cloud Extensibility, SAP ABAP Career, SAP ABAP Skills, SAP ABAP Jobs, SAP ABAP Tutorial and Materials, SAP ABAP Prep, SAP ABAP Preparation

Provide a class name and click on Implementing Class. This will create a new class dialog

SAP S/4HANA Cloud, SAP ABAP Development, SAP ABAP Extensibility, SAP S/4HANA Cloud Extensibility, SAP ABAP Career, SAP ABAP Skills, SAP ABAP Jobs, SAP ABAP Tutorial and Materials, SAP ABAP Prep, SAP ABAP Preparation

Provide the package name and description and click on Next. Provide an existing transport request or create a new transport request and click on Finish

SAP S/4HANA Cloud, SAP ABAP Development, SAP ABAP Extensibility, SAP S/4HANA Cloud Extensibility, SAP ABAP Career, SAP ABAP Skills, SAP ABAP Jobs, SAP ABAP Tutorial and Materials, SAP ABAP Prep, SAP ABAP Preparation

Save and Activate the class. Save and Activate the BAdI implementation once the class is activated

SAP S/4HANA Cloud, SAP ABAP Development, SAP ABAP Extensibility, SAP S/4HANA Cloud Extensibility, SAP ABAP Career, SAP ABAP Skills, SAP ABAP Jobs, SAP ABAP Tutorial and Materials, SAP ABAP Prep, SAP ABAP Preparation

Add the following logic in the method check document

if salesdocument_extension-yy1_enhancementfield1_sdh IS INITIAL.
  append value #(  messagetype = 'E' messagetext = `This custom field 'Enhancement Field' is empty` ) to 
  messages.
endif.

Save and activate the class ZCL_FIELD_VALID.

As you can see, creating a BAdI implementation is much simpler now using Developer Extensibility.

Now, when I try to save the Sales Order back in my Key User system(Development 100) with the Field ‘Enhancement Field’ as empty, I will get the following message.

SAP S/4HANA Cloud, SAP ABAP Development, SAP ABAP Extensibility, SAP S/4HANA Cloud Extensibility, SAP ABAP Career, SAP ABAP Skills, SAP ABAP Jobs, SAP ABAP Tutorial and Materials, SAP ABAP Prep, SAP ABAP Preparation

SAP S/4HANA Cloud, SAP ABAP Development, SAP ABAP Extensibility, SAP S/4HANA Cloud Extensibility, SAP ABAP Career, SAP ABAP Skills, SAP ABAP Jobs, SAP ABAP Tutorial and Materials, SAP ABAP Prep, SAP ABAP Preparation

The error message will be added to the log and can be seen as shown below

SAP S/4HANA Cloud, SAP ABAP Development, SAP ABAP Extensibility, SAP S/4HANA Cloud Extensibility, SAP ABAP Career, SAP ABAP Skills, SAP ABAP Jobs, SAP ABAP Tutorial and Materials, SAP ABAP Prep, SAP ABAP Preparation

No comments:

Post a Comment