Enterprise Resource Planning Blogs by SAP
Get insights and updates about cloud ERP and RISE with SAP, SAP S/4HANA and SAP S/4HANA Cloud, and more enterprise management capabilities with SAP blog posts.
Showing results for 
Search instead for 
Did you mean: 
This blog is part of a blog series focusing on SAP S/4HANA Extensibility. It is one of 5 blog posts taking care of the technical setup of extensibility with a focus on In-App Extensibility. Navigate to the header blog SAP S/4HANA Cloud Extensibility -  Engraving sample scenario

Create Custom Business Logic

Also, in the cloud I have the option to write additional custom coding in order to adapt the business logic of my system.

I have mainly two options to add custom code.

  1. Custom Reusable Elements: where I can implement custom code that can be reused in the custom logic. I would do that to clean up the coding or to reduce the efforts as I would reuse the same coding in different implementations.

  2. Custom Business Logic: this are so called cloud BAdIs. In the custom logic you can do custom coding and add your own logic. Main use cases that are offered are validation BAdIs and modification BAdI. The different BAdIs will allow you to change different things.

Important: In all custom implementations in S4HC you can only use restricted ABAP. This restricted has reduced functionality and you have only access to released ABAP objects like released classes, released interfaces, released structures or released (custom) CDS views. Background is that SAP needs to insure lifecycle stability so upgrades can be performed without disruption.

I our sample I want to create a reusable element to read the font size. This would not be required but just should show that its possible to use it.

Custom Reusable Element

I would like to provide a method that can be used to retrieve the font size for a given style ID. This method could be used in different implementations.

Goto app: Custom Reusable Elements

Press: “+”


  • Get_FontSize

Press: Create

Goto tab: Methods

Press: “+”


  • Method ID = GET_FONTSIZE

  • Description = get fontsize


Maintain Importing and Returning parameters like in the screenshot

Goto Method implementation

Enter Code in Implementation section:
select single fontsize from yy1_style where style_id eq @style_id into @Data(lv_fontsize).
fontsize = lv_fontsize.

Press “Save”

Go Back and press “Publish”

Custom Fields and Logic

As metioned above I would like to use the Custom Logic to fill the fields font and font size and derive that values based on the Style ID that is part of the Sales Order API.

For the font I do that directly by accessing the CDS View that has been generated for the Style CBO. For the font size I use the reusable element that I created above.

Goto app: Custom Fields and Logic

Goto tab: Custom Logic

Press “+”


  • Business Context = Sales: Sales Document Item

  • BAdI Description = Sales Item Modifiction

  • Implementation Description = Set_Font

Press: “Create Draft”

Enter Coding below:
salesdocumentitem_extension_o = salesdocumentitem_extension_i.
If salesdocumentitem_extension_i-yy1_engraving_sdi is not initial.
data lv_style_id type yy1_style-style_id.
lv_style_id = salesdocumentitem_extension_i-yy1_style_id_sdi.
if lv_style_id is not initial.
select single font from yy1_style where style_id eq @lv_style_id into @data(font).
salesdocumentitem_extension_O-yy1_font_sdi = font.
salesdocumentitem_extension_O-yy1_font_sdi = 'style initial + Style ID' && salesdocumentitem_extension_i-yy1_style_id_sdi.
endif.else.salesdocumentitem_extension_O-yy1_font_sdi = 'engraving initial'.

Press: “Save”

Press: “Publish”

Highlights and Conclusion: 

This blog shows that it is also in a SAP S/4HANA Cloud system it is possible to add custum business logic that should be executed while the business process is executed. It shows we can use Custom Logic in order to derive custom data based on a custom business objects and assign it to the custom fields that have been created earlier.

The blog outlines that the In-App Extensibility tools are powerful, easy to consume and life cycle stable.

This is a subchapter of the blog SAP S/4HANA Cloud Extensibility -  Engraving sample scenario