Friday 26 April 2019

SAP S/4HANA Cloud Extensibility – Engraving sample scenario – Technical Setup – Custom Business Logic Part - 3

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.

SAP ABAP Certifications, SAP HANA Tutorials and Materials, SAP HANA Learning

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: “+”

Enter:

◈ Get_FontSize

Press: Create

SAP ABAP Certifications, SAP HANA Tutorials and Materials, SAP HANA Learning

Goto tab: Methods

Press: “+”

Enter:

◈ Method ID = GET_FONTSIZE
◈ Description = get fontsize

Maintain Importing and Returning parameters like in the screenshot

SAP ABAP Certifications, SAP HANA Tutorials and Materials, SAP HANA Learning

Goto Method implementation

SAP ABAP Certifications, SAP HANA Tutorials and Materials, SAP HANA Learning

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”

SAP ABAP Certifications, SAP HANA Tutorials and Materials, SAP HANA Learning

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 “+”

Select:

◈ Business Context = Sales: Sales Document Item
◈ BAdI Description = Sales Item Modifiction
◈ Implementation Description = Set_Font

SAP ABAP Certifications, SAP HANA Tutorials and Materials, SAP HANA Learning

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.
else.
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'.
Endif.

Press: “Save”

Press: “Publish”

No comments:

Post a Comment