+ All Categories
Home > Documents > Extensibility Guide | PUBLIC

Extensibility Guide | PUBLIC

Date post: 15-Apr-2022
Category:
Upload: others
View: 16 times
Download: 0 times
Share this document with a friend
40
Extensibility Guide | PUBLIC Custom Logic Samples © 2021 SAP SE or an SAP affiliate company. All rights reserved. THE BEST RUN
Transcript
Page 1: Extensibility Guide | PUBLIC

Extensibility Guide | PUBLIC

Custom Logic Samples

© 2

021 S

AP S

E or

an

SAP affi

liate

com

pany

. All r

ight

s re

serv

ed.

THE BEST RUN

Page 2: Extensibility Guide | PUBLIC

Content

1 Overview. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3

1.1 Business Scenario. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3

Process Flow – Sample 1: UI Field Control Using Custom Logic. . . . . . . . . . . . . . . . . . . . . . . . . . .4

Process Flow – Sample 2: External HTTP Call in Custom Logic for Validation. . . . . . . . . . . . . . . . . 6

2 Preparation. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9

2.1 Prerequisites. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9

3 Sample 1: UI Field Control Using Custom Logic. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10

3.1 Implementation Steps in the SAP S/4HANA Cloud System. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10

Create Project ID Custom Field. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10

Create Customer Project SO Custom Field . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11

Find Extension Fields in Sales Order Header (Web GUI for HTML). . . . . . . . . . . . . . . . . . . . . . . . 13

Create Business Logic for UI Control. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14

Prepopulate a Custom Field Using Custom Logic. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .15

3.2 Testing the Extension Scenario. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17

Test: Create a New Customer Project. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17

Test: Use an Existing Customer Project. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .19

4 Sample 2: External HTTP Call in Custom Logic for Validation. . . . . . . . . . . . . . . . . . . . . . . . . . 21

4.1 Implementation Steps in the SAP S/4HANA Cloud System. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21

VAT Number Field Extensions. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21

Maintain Communication Settings . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26

Implement BAdI to Call the External VAT Service. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 33

4.2 Testing the Extension Scenario. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .35

Maintain a Valid VAT Number. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 35

Maintain an Invalid VAT Number. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 36

5 Appendix. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 38

5.1 Issues. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 38

5.2 Document History. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 38

2 PUBLICCustom Logic Samples

Content

Page 3: Extensibility Guide | PUBLIC

1 Overview

1.1 Business Scenario

NoteThis sample scenario is for learning purposes only. It is intended to give you an understanding of the various technical aspects related to extending SAP S/4HANA Cloud. The sample scenario may not always be available in a readily consumable state due to the continuous improvements being made in the underlying products or services. If this is the case, appropriate adaptations based on the latest documentation of the respective products or services are required.

This scenario covers the steps that key users need to follow to create a custom logic. UI extensibility makes it possible to adapt the appearance of an application and field or table extensibility allows you to enhance the data structure of applications. However, another extensibility capability is required for this scenario: enhancing the behavior applications and processes. Prominent use cases for this capability include data validation, data calculation (for example, supplying default values), and mapping of standard and extension fields within applications and processes. The purpose is to implement lightweight Business Add-Ins (BAdIs) such as checks, mappings, and calculations, released for cloud usage, but not for application development.

There is a restricted ABAP syntax:

● Any database operation except selects from released views● Tweaking new tasks● Dynamic programming● Obsolete ABAP statements● Code generation

NoteOnly whitelisted (released) APIs can be used.

Sample Implementations in this Scenario

Sample 1The Customer Project Management functionality in SAP S/4HANA Cloud is used to manage project-based customer services. Once a customer project has been set up in the SAP S/4HANA Cloud system, a sales order is automatically created in the background. This sales order is used to bill the project-based services to the customer. However, during the project execution, it might be required to sell additional products to the customer, which are related to this project. For that purpose, additional sales orders (for product sales) are captured in the SAP S/4HANA system for this particular customer. With respect to transparency and further reporting capabilities, a link between the sales order for product sales and the customer project is established.

Custom Logic SamplesOverview PUBLIC 3

Page 4: Extensibility Guide | PUBLIC

The sales orders (for product sales) are extended so that the project ID can be assigned here as well. The system automatically determines the sales order that is assigned to the customer project.

On sales order header level, two custom fields are created:

● Project ID: Project ID of the customer project● Cust Project SO: sales order of the customer project (to bill the project-based services)

The following behavior for the custom fields is implemented (BAdI implementation):

● The Cust Project SO field is read-only.● The Cust Project SO field is automatically determined using the information of the Project ID field.

NoteFind additional information in the Customer Project Management - Project-Based Services (J11) .

Sample 2An external HTTP service call can be made from custom logic. This enables the solution to use existing external services. In this sample, you add a validation to check if the VAT number maintained for a customer is valid (the sample is restricted for the countries United Kingdom (GB) and Germany (DE)). The service https://www.isvat.eu is called for validation.

1.1.1 Process Flow – Sample 1: UI Field Control Using Custom Logic

The flow diagram below describes the business process of this scenario.

Note

This is an excerpt of the Customer Project Management - Project-Based Services (J11) scope item. The focus of this scenario is to showcase the technical example implementation to achieve field control. That's why the steps in this document are kept to the minimum required to test this sample.

4 PUBLICCustom Logic Samples

Overview

Page 5: Extensibility Guide | PUBLIC

The following table provides you with a brief overview of the steps in this scenario:

Step Details

1 Create Customer Project

Open the Create Customer Projects app in the Project Management – Customer Projects catalog and create a new customer project.

Custom Logic SamplesOverview PUBLIC 5

Page 6: Extensibility Guide | PUBLIC

Step Details

2 Optional: Maintain Work Packages

Optional: Maintain additional information for the work packages.

3 Optional: Maintain Work Package Staffing

Optional: Maintain additional information for the work packages staffing on the Team tab.

4 Maintain Customer Project Billing

Change the stage of the customer project on the Information tab.

Maintain the billing details.

5 System Creates a Sales Order for Billing

Once the previous step has been carried out, the system creates a sales order for this customer project in the background.

6 Create Customer-Project-Related Sales Order

Create a sales order and assign the project ID in the custom field on sales order header level.

Once the sales order is saved, the sales order ID of the customer project (created automatically in the previous step) is determined via the BAdI implementation and stored in the Customer Project SO custom field.

1.1.2 Process Flow – Sample 2: External HTTP Call in Custom Logic for Validation

The flow diagram below describes the business process of this scenario.

6 PUBLICCustom Logic Samples

Overview

Page 7: Extensibility Guide | PUBLIC

Custom Logic SamplesOverview PUBLIC 7

Page 8: Extensibility Guide | PUBLIC

The following table provides you with a brief overview of the steps in this scenario:

Step Details

1 Maintain Customer Open the Manage Customer Master Data app, maintain the VAT Country and VAT Number fields, and save your changes. If the VAT Number field isn't maintained, the VAT Validation service is not called and the changes can be saved.

2 VAT Validation Service Checks Validity

VAT Validation service checks if the VAT number is either valid or invalid. If it's inva­lid, the user needs to go back to the previous step and either maintain a valid VAT or leave the VAT Number field empty.

3 Changes Saved for Cus­tomer

The customer master data has been saved either with a valid VAT number or with­out any VAT number.

8 PUBLICCustom Logic Samples

Overview

Page 9: Extensibility Guide | PUBLIC

2 Preparation

2.1 Prerequisites

To be able to perform the steps in this document, you need to make sure that the following prerequisites have been met:

Prerequisites Details

SAP S/4HANA Cloud system You have access to an SAP S/4HANA Cloud system with all the necessary users and authorizations (see below).

You must be assigned to the following roles. They are provided as example roles from SAP (Business Role Template). You can use these as a template to create your own roles.

Business Role Business Role ID as Delivered by SAP

Administrator SAP_BR_ADMINISTRATOR

Internal Sales Representative SAP_BR_ INTERNAL _ SALES_REP

Project Manager – Commercial Services SAP_BR_PROJ_MANAGE_COMM

Master Data Specialist - Business Partner Data SAP_BR_BUPA_MASTER_SPECIALIST

RememberWhen you implement the samples, make sure that you create the custom fields and communication settings using the properties exactly as they are described in this guide. Otherwise, the sample code won't work out of the box and requires manual adaptation.

Custom Logic SamplesPreparation PUBLIC 9

Page 10: Extensibility Guide | PUBLIC

3 Sample 1: UI Field Control Using Custom Logic

3.1 Implementation Steps in the SAP S/4HANA Cloud System

3.1.1 Create Project ID Custom Field

Purpose

You're creating the Project ID custom field. This custom field is added to the UI of the Sales Order screen on header level.

Prerequisites

You need to use an SAP S/4HANA Cloud system user that is authorized for the Administrator role as described in section Prerequisites [page 9].

Procedure

1. Access the SAP Fiori launchpad.2. Open the Custom Fields and Logic app in the Extensibility catalog.3. Choose Add on the Custom Fields tab to create a new custom field with details.4. In the New Fields dialog box, maintain the values using the following details:

Field Value

Business Context Sales: Sales Document

Label ProjectID

Identifier YY1_ProjectID

10 PUBLICCustom Logic Samples

Sample 1: UI Field Control Using Custom Logic

Page 11: Extensibility Guide | PUBLIC

Field Value

Type Text

Length 24

5. Choose Create and Edit.6. On the UIs and Reports tab of the Edit page, choose Enable Usage for the SD_SALESDOC_GUI (Create,

Change, or Display Sales Documents (Header) data source.

7. Choose Save.8. Choose Publish.

Result

You've now created a custom field with the label Project ID.

3.1.2 Create Customer Project SO Custom Field

Purpose

You're creating the Customer Project SO custom field. This custom field is added to the UI of the Sales Order screen on header level.

Custom Logic SamplesSample 1: UI Field Control Using Custom Logic PUBLIC 11

Page 12: Extensibility Guide | PUBLIC

Prerequisites

You need to use an SAP S/4HANA Cloud system user that is authorized for the Administrator role as described in section Prerequisites [page 9].

Procedure

1. Access the SAP Fiori launchpad.2. Open the Custom Fields and Logic app in the Extensibility catalog.3. Choose Add on the Custom Fields tab to create a new custom field with details.4. In the New Fields dialog box, maintain the values using the following details:

Field Value

Business Context Sales: Sales Document

Label Cust Project SO

Identifier YY1_CUSTPROJECTSO

Type Text

Length 10

5. Choose Create and Edit.6. On the UIs and Reports tab of the Edit page, choose Enable Usage for the SD_SALESDOC_GUI (Create,

Change, or Display Sales Documents (Header) data source.7. Choose Save.8. Choose Publish.

Result

You've now created a custom field with the label Cust Project SO.

12 PUBLICCustom Logic Samples

Sample 1: UI Field Control Using Custom Logic

Page 13: Extensibility Guide | PUBLIC

3.1.3 Find Extension Fields in Sales Order Header (Web GUI for HTML)

Purpose

The following procedure explains how you can access the custom fields created in the previous sections.

Prerequisites

You need to use an SAP S/4HANA Cloud system user that is authorized for the Internal Sales Representative role as described in section Prerequisites [page 9].

Procedure

1. Access the SAP Fiori launchpad.2. Open the List Sales Orders app in the Sales Orders catalog.3. Enter the required search parameters on the List of Sales Orders page and choose Execute.4. Select (double-click) a line item to display the contents of the sales order on the Change Standard Order

Overview page.5. Choose Display Header Details as shown here:

6. Go to the Custom Fields tab to gain access to the newly added custom field.

Custom Logic SamplesSample 1: UI Field Control Using Custom Logic PUBLIC 13

Page 14: Extensibility Guide | PUBLIC

Result

The custom fields are now available in the Sales Order app for usage.

3.1.4 Create Business Logic for UI Control

Purpose

You're implementing a logic to make the Cust Project SO custom field read-only on the Sales Order UI.

Prerequisites

You need to use an SAP S/4HANA Cloud system user that is authorized for the Administrator role as described in section Prerequisites [page 9].

Procedure

1. Access the SAP Fiori launchpad.2. Open the Custom Fields and Logic app in the Extensibility catalog.3. Go to the Custom Logic tab.4. Choose Add to create a new logic implementation.5. Create the following values:

Field Value

Business Context Sales: Sales Document

BAdI Description Sales Header Field Properties

Implementation Description FIELD CONTROL

6. Choose Create.7. Select the entire coding in the Draft Logic section and delete it.8. Paste the following coding section:

loop at field_properties assigning field-symbol(<fs_field_properties>). if <fs_field_properties>-field_name = 'YY1_CUSTPROJECTSO_SDH'. <fs_field_properties>-read_only = 'X'. endif.

14 PUBLICCustom Logic Samples

Sample 1: UI Field Control Using Custom Logic

Page 15: Extensibility Guide | PUBLIC

endloop.

9. Choose Save Draft.10. Choose Publish.

NoteOn the BAdI Documentation tab, choose View BAdi Documentation to see more information about Sales Header Field Properties.

For implementation of custom fields and logic, refer to the documentation on Statements of ABAP for Key Users.

For more information about mail and form templates, refer to the set-up instructions of the Output Management (1LQ) scope item.

Result

The Cust Project SO custom field is now read-only. You can check this by carrying out the steps described in section Find Extension Fields in Sales Order Header (Web GUI for HTML) [page 13].

CautionMake sure that you close the previous session. Otherwise, the newly implemented BAdI implementation doesn't load.

3.1.5 Prepopulate a Custom Field Using Custom Logic

Purpose

You're using custom logic to prepopulate fields.

Custom Logic SamplesSample 1: UI Field Control Using Custom Logic PUBLIC 15

Page 16: Extensibility Guide | PUBLIC

Prerequisites

You need to use an SAP S/4HANA Cloud system user that is authorized for the Administrator role as described in section Prerequisites [page 9].

Procedure

1. Access the SAP Fiori launchpad.2. Open the Custom Fields and Logic app in the Extensibility catalog.3. Go to the Custom Logic tab and choose Add to create a new logic implementation.4. Create the following values:

Field Value

Business Context Sales: Sales Document

Definition Description Sales Header Modification

Implementation Description HEADER_MODIFICATION

5. Choose Create.6. Select the entire coding in the Draft Logic area and delete it.7. Paste the following coding section:

SELECT SINGLE salesorder FROM i_salesorderitemcube( P_EXCHANGERATETYPE = 'M', P_DISPLAYCURRENCY = 'EUR' ) INTO @salesdocument_extension_out-yy1_custprojectso_sdh WHERE customerproject = @salesdocument_extension_in-yy1_projectid_sdh.

8. Choose Save Draft and Publish.

Result

You've created a BAdI implementation that fetches the sales order ID related to the custom project and populates the Cust Project SO custom field using the information entered in the Project ID field.

16 PUBLICCustom Logic Samples

Sample 1: UI Field Control Using Custom Logic

Page 17: Extensibility Guide | PUBLIC

3.2 Testing the Extension Scenario

Purpose

This section describes how to test business process.

NoteFind a detailed description of how to create customer projects in the test script of the Customer Project Management - Project-Based Services (J11) scope item.

If you're faced with the You are not authorized for this service org. issue when creating the customer project, check the assigned business catalog (Project Manager – Commercial Services). Under Maintain Restrictions, make sure that you have the Unrestricted Write permission.

3.2.1 Test: Create a New Customer Project

Prerequisites

You need to use an SAP S/4HANA Cloud system user that is authorized for the Project Manager – Commercial Services and Internal Sales Representative role as described in section Prerequisites [page 9].

Procedure

1. Access the SAP Fiori launchpad as a Project Manager – Commercial Services.2. Open the Create Customer Projects app in the Project Management – Customer Projects catalog.3. Maintain the mandatory fields on the Create Customer Project screen.4. Choose Save and Proceed.5. Optional: Maintain additional information for the work packages.6. Optional: Go to the Team tab and maintain additional information for the team.7. Go to the Information tab.8. Change the stage to Contract Preparation.9. Choose Save.10. Go to the Billing tab.

Custom Logic SamplesSample 1: UI Field Control Using Custom Logic PUBLIC 17

Page 18: Extensibility Guide | PUBLIC

11. Maintain at least one billing item. You can use the following sample data and keep the default values in the billing item:

Field Value

Contract Type Fixed Price

Amount to Be Billed <your billing amount>

12. Choose Save.13. The system creates a sales order related to this customer project in the background.

14. Note down the project ID of your selected customer project.15. Access the SAP Fiori launchpad as an Internal Sales Representative.16. Open the Create Sales Order app in the Sales Order catalog.

NoteIf you've already created a sales order for the customer that can be associated with the selected project, open the List Sales Order app in the Sales Order catalog. Search for your sales order and carry out the following steps accordingly.

17. Select an order type (OR – Standard Order). Maintain Sales Organisation, Distribution Channel, and Division and choose Continue.

18. Assign the customer that is used in the customer project as Sold-To Party.19. Add sales order items to your order and complete the sales order according to your needs.20.Choose Display Header Details.21. Go to the Custom Fields tab.22. In the Project ID field, enter the project ID that you noted down previously (see step 14).

NoteCust Proj SO is populated once you've saved the sales order.

23. Choose Save.24. Choose Display on the Create Standard Overview Order screen to see the newly created sales order.25. Choose Display header details.26. Go to the Custom Fields tab.27. Now the Cust Project SO field is populated with the sales order ID created in the project.

18 PUBLICCustom Logic Samples

Sample 1: UI Field Control Using Custom Logic

Page 19: Extensibility Guide | PUBLIC

Result

The customer project sales order from the customer project was automatically populated once a valid project ID was entered.

3.2.2 Test: Use an Existing Customer Project

Prerequisites

You need to use an SAP S/4HANA Cloud system user that is authorized for the Project Manager – Commercial Services and Internal Sales Representative role as described in section Prerequisites [page 9].

Procedure

1. Access the SAP Fiori launchpad as an Project Manager – Commercial Services.2. Open the Plan Customer Projects app in the Project Management – Customer Projects catalog.3. Select a project from the list that is (at least) in the Contract Preparation stage and for which a billing item

has already been created.4. If the criteria mentioned above have been fulfilled, a sales order has been created for this project, which is

displayed on the Billing tab.

Custom Logic SamplesSample 1: UI Field Control Using Custom Logic PUBLIC 19

Page 20: Extensibility Guide | PUBLIC

5. Note down the project ID of your customer project.6. Access the SAP Fiori launchpad as an Internal Sales Representative.7. Open the Create Sales Order app in the Sales Order catalog.

NoteIf you've already created a sales order for the customer that can be associated with the selected project, open the List Sales Order app in the Sales Order catalog. Search for your sales order and carry out the following steps accordingly.

8. Select an order type (OR – Standard Order), maintain Sales Organisation, Distribution Channel, and Division and choose Continue.

9. Assign the customer that is used in the customer project as Sold-To Party.10. Add sales order items to your order and complete the sales order according to your needs.11. Choose Display Header Details.12. Go to the Custom Fields tab.13. In the Project ID field, enter the project ID that you noted down previously (see step 5).

NoteCust Proj SO is populated once you've saved the sales order.

14. Choose Save.15. Choose Display to see the newly created sales order.16. Choose Display header details.17. Go to the Custom Fields tab.18. Now the Cust Project SO field is populated with the sales order ID created in the project.

Result

The customer project sales order from the customer project was automatically populated once a valid project ID was entered.

20 PUBLICCustom Logic Samples

Sample 1: UI Field Control Using Custom Logic

Page 21: Extensibility Guide | PUBLIC

4 Sample 2: External HTTP Call in Custom Logic for Validation

4.1 Implementation Steps in the SAP S/4HANA Cloud System

An external HTTP service call can be made from custom logic. This enables the solution to use existing external services. This section explains which steps are required to enable an external service call.

In this scenario, you add a validation to check if the VAT number is valid for the country codes (United Kingdom (GB) or Germany (DE)). The service https://www.isvat.eu is called for validation.

NoteThis service has been chosen for demonstration purposes only. There's a variety of other validation services publicly available you can use.

4.1.1 VAT Number Field Extensions

The following sections describe the steps you need to follow to create two custom fields that are required for this use case.

4.1.1.1 Create VAT Number Custom Field

Purpose

You're creating the VAT Number custom field. This custom field is added to the UI of the Manage Customer Master Data app.

Prerequisites

You need to use an SAP S/4HANA Cloud system user that is authorized for the Administrator and Master Data Specialist - Business Partner Data role as described in section Prerequisites [page 9].

Custom Logic SamplesSample 2: External HTTP Call in Custom Logic for Validation PUBLIC 21

Page 22: Extensibility Guide | PUBLIC

Procedure

1. Access the SAP Fiori launchpad.2. Open the Custom Fields and Logic app in the Extensibility catalog.3. Choose Add on the Custom Fields tab to create a new custom field with details.4. In the New Fields dialog box, maintain the values using the following details:

Field Value

Business Context Business Partner Core View

Label VAT Number

Identifier YY1_VATNumber

Type Number

Length 18

Decimal Places 0

5. Choose Create and Edit.6. On the UIs and Reports tab of the Edit page, choose Enable Usage for the MD_BUSINESSPARTNER_SRV

0001 and MD_CUSTOMER_MASTER_SRV01 0001 data sources

7. Choose Save.8. Choose Publish.

Result

You've now created a custom field with the label VAT Number.

22 PUBLICCustom Logic Samples

Sample 2: External HTTP Call in Custom Logic for Validation

Page 23: Extensibility Guide | PUBLIC

4.1.1.2 Create VAT Country Custom Field

Prerequisites

You need to use an SAP S/4HANA Cloud system user that is authorized for the Administrator and Master Data Specialist - Business Partner Data role as described in section Prerequisites [page 9].

Procedure

1. Access the SAP Fiori launchpad.2. Open the Custom Fields and Logic app in the Extensibility catalog.3. Choose Add on the Custom Fields tab to create a new custom field with details.4. In the New Fields dialog box, maintain the values using the following details:

Field Value

Business Context Business Partner Core View

Label VAT Country

Identifier YY1_VATNumber

Type Code List

Length 2

5. Maintain the following list values:

Field Value

Code Value DE

Description Germany

6. Choose + to add a second code value:

Field Value

Code Value GB

Description United Kingdom

Custom Logic SamplesSample 2: External HTTP Call in Custom Logic for Validation PUBLIC 23

Page 24: Extensibility Guide | PUBLIC

7. Choose Create and Edit.8. On the UIs and Reports tab of the Edit page, choose Enable Usage for the MD_BUSINESSPARTNER_SRV

0001 and MD_CUSTOMER_MASTER_SRV01 0001 data sources

9. Choose Save.10. Choose Publish.

Result

You've now created a custom field with the label VAT Country.

24 PUBLICCustom Logic Samples

Sample 2: External HTTP Call in Custom Logic for Validation

Page 25: Extensibility Guide | PUBLIC

4.1.1.3 Add Custom Fields to Manage Customer Master Data

Purpose

You're adding the VAT Number and VAT Country fields created in the previous steps to the UI for the Manage Customer Master data SAP Fiori app.

Prerequisites

You need to use an SAP S/4HANA Cloud system user that is authorized for the Administrator and Master Data Specialist - Business Partner Data role as described in section Prerequisites [page 9].

Procedure

1. Access the SAP Fiori launchpad.2. Open the Manage Customer Master Data app in the Customer Master catalog.3. Complete the customer search.4. On the Customer screen, choose the user icon in the upper left corner.

5. Choose Adapt UI.6. Select VAT Liability in the Customer Information section and right-click on it.

Custom Logic SamplesSample 2: External HTTP Call in Custom Logic for Validation PUBLIC 25

Page 26: Extensibility Guide | PUBLIC

7. Choose Add Field.8. Select the VAT Country and VAT Number fields from the list in the Available Fields dialog box.9. Choose OK.10. Choose Publish.11. Choose Save & Exit.

Result

You've now added the custom fields to the Manage Customer Master Data app.

4.1.2 Maintain Communication Settings

4.1.2.1 Create Trust Between SAP S/4HANA Cloud System and External Service

Purpose

To enable an external HTTP call from the SAP S/4HANA Cloud system, you need to maintain a trust with the external service.

26 PUBLICCustom Logic Samples

Sample 2: External HTTP Call in Custom Logic for Validation

Page 27: Extensibility Guide | PUBLIC

Prerequisites

You need to use an SAP S/4HANA Cloud system user that is authorized for the Administrator role as described in section Prerequisites [page 9].

Procedure

1. Open Google Chrome in the Administrator mode.2. Enter www.isvat.eu in the URL bar and choose Enter.3. Choose Secure to view the security report.4. Choose Valid under Certificate.

5. Go to the Details tab, export the certificate, and store it in a local file.

Custom Logic SamplesSample 2: External HTTP Call in Custom Logic for Validation PUBLIC 27

Page 28: Extensibility Guide | PUBLIC

6. Choose Next.7. Choose Browse and enter a file name of your choice and choose Save to store it locally.8. Complete the wizard.9. Log on to SAP S/4HANA Cloud system as an Administrator.10. Open the Maintain Certificate Trust List application in the Security catalog.11. To establish the trust connection between the SAP S/4HANA Cloud system and the external HTTP service,

choose Add. Upload the certificate you downloaded.

28 PUBLICCustom Logic Samples

Sample 2: External HTTP Call in Custom Logic for Validation

Page 29: Extensibility Guide | PUBLIC

Result

You've now established the trust.

4.1.2.2 Create Custom Communication Scenario

Purpose

Since the service to execute the VAT check is outside the SAP S/4HANA Cloud system (public internet), you need to configure a custom communication scenario to make use of this service.

Prerequisites

You need to use an SAP S/4HANA Cloud system user that is authorized for the Administrator role as described in section Prerequisites [page 9].

Procedure

1. Access the SAP Fiori launchpad.2. Open the Custom Communication Scenarios app in the Extensibility catalog.3. Choose New.4. Enter the following details:

Field Value

Communication Scenario ID YY1_VALIDATE_VAT

Description Validate VAT

5. Choose New in the dialog box.6. Go to the Outbound Services tab and choose + to create a new service ID.7. Enter the following details and choose Create.

Field Value

Description Validate VAT

Custom Logic SamplesSample 2: External HTTP Call in Custom Logic for Validation PUBLIC 29

Page 30: Extensibility Guide | PUBLIC

Field Value

Outbound Service ID YY1_VALIDATE_VAT_REST

URL Path /live

8. Select the outbound service created and choose Publish.

Result

You've now created a custom communication scenario.

4.1.2.3 Set Up Communication System

Prerequisites

You need to use an SAP S/4HANA Cloud system user that is authorized for the Administrator role as described in section Prerequisites [page 9].

Procedure

1. Access the SAP Fiori launchpad.2. Open the Communication Systems app in the Communication Management catalog.3. Choose New.

30 PUBLICCustom Logic Samples

Sample 2: External HTTP Call in Custom Logic for Validation

Page 31: Extensibility Guide | PUBLIC

4. Enter the following details:

Field Value

System ID VALIDATE_VAT

System Name VALIDATE_VAT

5. Choose Create.6. Enter the following information on the Details page and choose Save.

Field Value

Host Name www.isvat.eu

HTTPS Port 443

7. Scroll down to the User for Outbound Communication section and choose Add.8. Choose None in the New Outbound User dialog box and choose Create.

9. Choose Save.

Result

You've now created a communication system.

4.1.2.4 Set Up Communication Arrangement

Prerequisites

You need to use an SAP S/4HANA Cloud system user that is authorized for the Administrator role as described in section Prerequisites [page 9].

Custom Logic SamplesSample 2: External HTTP Call in Custom Logic for Validation PUBLIC 31

Page 32: Extensibility Guide | PUBLIC

Procedure

1. Access the SAP Fiori launchpad.2. Open the Communication Arrangement app in the Communication Management catalog.3. Choose New.4. Enter the following details.

Field Value

Scenario YY1_VALIDATE_VAT

Arrangement Name YY1_VALIDATE_VAT

5. Choose Create.6. Enter the following information on the Details page and choose Save.

Field Value

Communication System VALIDATE_VAT

32 PUBLICCustom Logic Samples

Sample 2: External HTTP Call in Custom Logic for Validation

Page 33: Extensibility Guide | PUBLIC

Result

You've now created a communication arrangement. The outbound service call is now technically enabled.

NoteAfter choosing Check Connections, a success message is displayed to inform you that the communication test of the outbound service was successful.

4.1.3 Implement BAdI to Call the External VAT Service

Purpose

You're creating the BAdI to call the external VAT service. The BAdI is executed once the end user maintains the custom fields and saves the changes in the Manage Customer Master Data app.

Prerequisites

You need to use an SAP S/4HANA Cloud system user that is authorized for the Administrator role as described in section Prerequisites [page 9].

Procedure

1. Access the SAP Fiori launchpad.2. Open the Custom Fields and Logic app in the Extensibility catalog.3. Go to the Custom Logic tab and choose + to create a new logic implementation.4. Enter the following values and choose Create.

Field Value

Business Context Business Partner Core View

Definition Description Validate BP BADI

Implementation Description Validate VAT

5. Enter the following code in Draft Logic:

Declaration of required parameters

Custom Logic SamplesSample 2: External HTTP Call in Custom Logic for Validation PUBLIC 33

Page 34: Extensibility Guide | PUBLIC

DATA LS_BP_ROOT LIKE LINE OF IT_BP_ROOT. DATA LS_VALIDATIONMESSAGE LIKE LINE OF CT_VALIDATIONMESSAGE.* For Accessing Customer General Data READ TABLE IT_BP_ROOT INTO LS_BP_ROOT 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_BP_ROOT-include-yy1_vatcountry_bus IS NOT INITIAL. CHECK ls_BP_ROOT-include-yy1_vatnumber_bus IS NOT INITIAL.*check if communication scenario is configured properly CHECK cl_ble_http_client=>is_service_available( communication_scenario = 'YY1_VALIDATE_VAT' outbound_service = 'YY1_VALIDATE_VAT_REST' ) = abap_true. DATA(lo_client) = cl_ble_http_client=>create( communication_scenario = 'YY1_VALIDATE_VAT' outbound_service = 'YY1_VALIDATE_VAT_REST' ).data lv_vatnumber type string.* convert number field to stringlv_vatnumber = ls_BP_ROOT-include-yy1_vatnumber_bus.CONCATENATE '/' ls_BP_ROOT-include-yy1_vatcountry_bus '/' lv_vatnumber INTO DATA(lv_vat). DATA(request) = cl_ble_http_request=>create( ). request->set_method( 'GET' )->set_resource_extension( lv_vat ).TRY . DATA(response) = lo_client->send( request ). DATA(lv_body) = response->get_body( ). " Response in fetched in String Format. " Do appropriate Split operations to fetch the relevant data SPLIT lv_body AT 'valid":' INTO lv_body DATA(lv_body2). SPLIT lv_body2 AT ',' INTO DATA(lv_valid) lv_body2. IF lv_valid CS 'false'. LS_VALIDATIONMESSAGE-MSGTY = 'E'. LS_VALIDATIONMESSAGE-MSGID = 'CVI_API'. LS_VALIDATIONMESSAGE-MSGNO = '010'. LS_VALIDATIONMESSAGE-MSGV1 = 'This is not a valid VAT number’. APPEND LS_VALIDATIONMESSAGE TO CT_VALIDATIONMESSAGE. ENDIF. CATCH cx_ble_http_exception INTO DATA(lx).ENDTRY.

NoteThe communication_scenario, outbound_service, and the field extensions should be filled with the values you created in the previous steps. If not, replace the values you have with these ones.

6. Choose Save.7. Choose Publish.

Result

You've now published the BAdI logic.

34 PUBLICCustom Logic Samples

Sample 2: External HTTP Call in Custom Logic for Validation

Page 35: Extensibility Guide | PUBLIC

4.2 Testing the Extension Scenario

4.2.1 Maintain a Valid VAT Number

Purpose

You're maintaining the VAT number for a business partner.

Prerequisites

You need to use an SAP S/4HANA Cloud system user that is authorized for the Master Data Specialist - Business Partner Data role as described in section Prerequisites [page 9].

Procedure

1. Access the SAP Fiori launchpad.2. Open the Manage Customer Master Data app in the Customer Master catalog.3. Complete the customer search.4. On the Customer screen, choose Edit.5. Choose VAT Country in the Customer Information section and click on the value help icon.6. Choose Go in the Select: VAT Country dialog box.7. Select GB.8. Enter a valid VAT number for the country code GB.

Note○ The following VAT numbers are valid examples for the country code GB: 274217603 and

927153228 ○ The following VAT number is a valid example for the country code DE: 811569869

9. Choose Save.

Result

Since you've entered a valid VAT number, the record has been saved.

Custom Logic SamplesSample 2: External HTTP Call in Custom Logic for Validation PUBLIC 35

Page 36: Extensibility Guide | PUBLIC

4.2.2 Maintain an Invalid VAT Number

Purpose

You're maintaining the VAT number for a business partner.

Prerequisites

YYou need to use an SAP S/4HANA Cloud system user that is authorized for the Master Data Specialist - Business Partner Data role as described in section Prerequisites [page 9].

Procedure

1. Access the SAP Fiori launchpad.2. Open the Manage Customer Master Data app in the Customer Master catalog.3. Complete the customer search.4. On the Customer screen, choose Edit.5. Choose VAT Country in the Customer Information section and click on the value help icon.6. Choose Go in the Select: VAT Country dialog box.7. Select GB.8. Enter an invalid VAT number for the country code GB.

○ The following VAT number is an invalid example for the country code GB: 12345465○ The following VAT number is an invalid example for the country code DE: 12345465

9. Choose Save.

36 PUBLICCustom Logic Samples

Sample 2: External HTTP Call in Custom Logic for Validation

Page 37: Extensibility Guide | PUBLIC

10. An error message is displayed to inform you that your changes couldn't be saved and to tell you to check the messages below:

11. Choose Close.12. Maintain either a valid VAT number as described in section Maintain a Valid VAT Number [page 35] or

delete the entry in the VAT Number field.13. Choose Save.

Result

The external VAT validation service validated the VAT numbers you entered. Since it's not possible to save an invalid VAT number, the end user must either maintain a valid VAT number or leave the VAT Number field empty.

Custom Logic SamplesSample 2: External HTTP Call in Custom Logic for Validation PUBLIC 37

Page 38: Extensibility Guide | PUBLIC

5 Appendix

5.1 Issues

Please note that SAP does not offer any official support for the sample code (see the SAP SAMPLE CODE LICENSE AGREEMENT on GitHub). However, feel free to use the Issues section on GitHub if you have any problems. We recommend that you browse through the known issues section before creating a new issue

.

5.2 Document History

Revision Date Change

1.0 2018-08-16 Document created.

1.1 2018-11-15 Formatting issue corrected in the Prepopulate a Custom Field Using Custom Logic [page 15] section.

1.2 2019-09-13 Issues [page 38] section added.

38 PUBLICCustom Logic Samples

Appendix

Page 39: Extensibility Guide | PUBLIC

Important Disclaimers and Legal Information

HyperlinksSome links are classified by an icon and/or a mouseover text. These links provide additional information.About the icons:

● Links with the icon : You are entering a Web site that is not hosted by SAP. By using such links, you agree (unless expressly stated otherwise in your agreements with SAP) to this:

● The content of the linked-to site is not SAP documentation. You may not infer any product claims against SAP based on this information.● SAP does not agree or disagree with the content on the linked-to site, nor does SAP warrant the availability and correctness. SAP shall not be liable for any

damages caused by the use of such content unless damages have been caused by SAP's gross negligence or willful misconduct.

● Links with the icon : You are leaving the documentation for that particular SAP product or service and are entering a SAP-hosted Web site. By using such links, you agree that (unless expressly stated otherwise in your agreements with SAP) you may not infer any product claims against SAP based on this information.

Videos Hosted on External PlatformsSome videos may point to third-party video hosting platforms. SAP cannot guarantee the future availability of videos stored on these platforms. Furthermore, any advertisements or other content hosted on these platforms (for example, suggested videos or by navigating to other videos hosted on the same site), are not within the control or responsibility of SAP.

Beta and Other Experimental FeaturesExperimental features are not part of the officially delivered scope that SAP guarantees for future releases. This means that experimental features may be changed by SAP at any time for any reason without notice. Experimental features are not for productive use. You may not demonstrate, test, examine, evaluate or otherwise use the experimental features in a live operating environment or with data that has not been sufficiently backed up.The purpose of experimental features is to get feedback early on, allowing customers and partners to influence the future product accordingly. By providing your feedback (e.g. in the SAP Community), you accept that intellectual property rights of the contributions or derivative works shall remain the exclusive property of SAP.

Example CodeAny software coding and/or code snippets are examples. They are not for productive use. The example code is only intended to better explain and visualize the syntax and phrasing rules. SAP does not warrant the correctness and completeness of the example code. SAP shall not be liable for errors or damages caused by the use of example code unless damages have been caused by SAP's gross negligence or willful misconduct.

Gender-Related LanguageWe try not to use gender-specific word forms and formulations. As appropriate for context and readability, SAP may use masculine word forms to refer to all genders.

Custom Logic SamplesImportant Disclaimers and Legal Information PUBLIC 39

Page 40: Extensibility Guide | PUBLIC

www.sap.com/contactsap

© 2021 SAP SE or an SAP affiliate company. All rights reserved.

No part of this publication may be reproduced or transmitted in any form or for any purpose without the express permission of SAP SE or an SAP affiliate company. The information contained herein may be changed without prior notice.

Some software products marketed by SAP SE and its distributors contain proprietary software components of other software vendors. National product specifications may vary.

These materials are provided by SAP SE or an SAP affiliate company for informational purposes only, without representation or warranty of any kind, and SAP or its affiliated companies shall not be liable for errors or omissions with respect to the materials. The only warranties for SAP or SAP affiliate company products and services are those that are set forth in the express warranty statements accompanying such products and services, if any. Nothing herein should be construed as constituting an additional warranty.

SAP and other SAP products and services mentioned herein as well as their respective logos are trademarks or registered trademarks of SAP SE (or an SAP affiliate company) in Germany and other countries. All other product and service names mentioned are the trademarks of their respective companies.

Please see https://www.sap.com/about/legal/trademark.html for additional trademark information and notices.

THE BEST RUN


Recommended