S/4HANA Manage Customer Line Items App – Advanced Custom Fields Extension

SAP documentation explains how to extend S/4HANA Manage Customer Line Items App with custom fields. SAP approach works for custom characteristics, but may or may not work for custom quantity / amount fields. If custom quantity / amount field total can not be calculated on total level (must be a sum of detail level calculations), then SAP approach is not going to work. My blog explains to overcome this limitation.

I my example, there are 3 custom amount fields that need be calculated at line item level and added up to get totals right. Here are business rules for the fields:

  • Credit equal to negative line item amount
  • Deduction is equal to positive line item amount with document type not DR, RV or ZB
  • Invoice is equal to positive line item amount with document type DR, RV or ZB

Prior to getting into custom field extension implementation details you need to understand how app is using OData Service. Once the app is refreshed it calls the OData Service twice once for details (1) and second time for totals (2).

In Chrome developer tools Network tab you can see what data is requested by Fiori from OData service first for details (1) and second for totals (2)

As you can at the time when totals are requested (2) only amounts and currency fields are requested. It means that we are loosing line item details that we need to calculate custom field totals correctly.

Here is how I approach to calculation of customer amount field totals (2):

Here is step by step process of Manage Customer Line Items app custom field extension:

 Add Append Structure with Custom Fields to FAR_IFIARLINEITEM_EX Structure

Create SEGW Project and Redefine FAR_CUSTOMER_LINE_ITEMS OData Service

Select all entities to be included from base service

Activate the project checking Overwrite Base / Extended Service checkbox

Add Custom Fields Properties to Item Entity Type

Enhance /IWBEP/CL_MGW_REQUEST Class Adding GET_MODEL Method

This method is later used in data provide class to created modified copy IO_TECH_REQUEST_CONTEXT parameter in order to read Item entity set with additional fields

Redefine DEFINE Method in Metadata Provider Extension Class

Custom fields are annotated to be either dimensions or measures

Add Service Methods to ZCL_ZFAR_CUSTOMER_LINE_DPC_EXT Class

Service methods help to structure ITEMSET_GET_ENTITYSET method code better.

IS_TOTAL method determines if OData Service is called for details (1) or totals (2).

ADD_SELECT_PROPERTIES method adds additional properties that need to be read

 Remaining 3 methods contain business logic and specific to my example

Redefine ITEMSET_GET_ENTITYSET method in data provider extension class

Below portion of code calculates custom amount fields totals separately reading data at line item level

Below portion of code plugs in custom amount fields totals into totals entity set

Manage Customer Line Item advanced customer field extension source code can be downloaded from GitHub:

P.S. The described example is tested for S/4HANA release 1709