Saturday 28 May 2022

Extending business processes with product footprints using the Key User Extensibility in SAP S/4HANA

With SAP Product Footprint Management, SAP provides a solution, giving customers transparency on their product footprints, as well as visibility into the end-to-end business processes and supply chains. 

SAP S/4HANA comes with the Key User Extensibility concept, which is available both in the cloud and on-premise versions.

Key User Extensibility, together with product footprints calculated in SAP Product Footprint Management, enables customers to enrich end-to-end business processes with sustainability information, helping to implement the “green line” in the sustainable enterprise. With Key User Extensibility, this can be achieved immediately, as the extension of the business processes can be introduced right away, by customers and partners, during an implementation project.

In this blog post, I will walk you through an example, how sustainability can be embedded into the operational purchasing process, by extending the Purchase Order with CO2-equivalent (CO2e) information, enabling the Operational Purchaser to bring the CO2e Footprint of purchased goods into the decision process, when processing Purchase Orders.

Integration Component for Product Footprints in SAP S/4HANA

SAP Product Footprint Management is a cloud application, running on SAP Business Technology Platform, enabling the calculation of product footprints across the entire product lifecycle.

Since S/4HANA Cloud 2108 and S/4HANA 2021, SAP provides a Sustainability Integration Component (Scope Item: 5IM – Product Footprint Management), as part of SAP S/4HANA, that enables the integration of product footprints, calculated in SAP Product Footprint Management on SAP Business Technology Platform, into the business processes in SAP S/4HANA.

Based on the scope of the footprint calculation, defined in SAP Product Footprint Management, the Integration Component stores a CO2e Footprint for each scoped product, which has a successfully executed footprint calculation and has a footprint which has been published to S/4HANA. This footprint is always a quantity per product and plant, as CO2e in kg per Base Unit of Measure of the product. For raw materials, a footprint can also be per product, plant and supplier.

The Sustainability Integration Component in SAP S/4HANA contains well defined and stable APIs that are released for Key User Extensibility and herewith enable access to product footprints stored in the Integration Component, through this simple but powerful extensibility concept.

SAP S/4HANA, SAP HANA Career, SAP HANA Jobs, SAP HANA Skills, SAP ABAP News, SAP HANA Preparation
Sustainability Integration Component in SAP S/4HANA

Extending the Purchase Order with Custom Fields and Logic


In the following example, I will show you how to extend the Purchase Order with footprint information on header, as well as on item level. The whole extension will be implemented in in three basic steps:

1. Create custom fields
2. Create custom logic
3. Adapt the UI “Manage Purchase Orders” to add the footprint information.

As a result of this extensibility implementation, we will make footprint information available in multiple areas of the Manage Purchase Order app. The most prominent extension is making the CO2e Footprint in kg available for each line item in the list report for the purchase orders:

SAP S/4HANA, SAP HANA Career, SAP HANA Jobs, SAP HANA Skills, SAP ABAP News, SAP HANA Preparation
List Report of the Manage Purchase Order App with CO2e Footprint

But also having the footprint directly on the Purchase Order on Item, as well as Header level is adding tremendous value and is supporting the Operational Purchaser in purchasing more sustainable products while creating and reviewing Purchase Orders:

SAP S/4HANA, SAP HANA Career, SAP HANA Jobs, SAP HANA Skills, SAP ABAP News, SAP HANA Preparation
Purchase Order with CO2e Footprint

Create Custom Fields


To create custom fields, that store the CO2e Footprint data, we use the Fiori app Custom Fields:

SAP S/4HANA, SAP HANA Career, SAP HANA Jobs, SAP HANA Skills, SAP ABAP News, SAP HANA Preparation
Apps for Custom Fields and Custom Logic

In the app, we create one field Item CO2e Footprint in kg, extending the Purchase Order Item and another field CO2e Footprint in kg, extending the Purchase Order Header:

SAP S/4HANA, SAP HANA Career, SAP HANA Jobs, SAP HANA Skills, SAP ABAP News, SAP HANA Preparation
Create Custom Fields

Both custom fields need to be created in the appropriate Business Context for the Purchasing Document or Purchasing Document Item. For the CO2e Footprint we create fields of type Quantity with Unit. It is important to enable the usage of the field for the App Manage Purchase Order. For this, we open each of the two custom fields, by selecting the line item, go to UIs and Reports and select Enable Usage for the UI Manage Purchase Orders. After the two custom fields are created and configured, they can be published.

Create Custom Logic


To calculate the CO2e Footprint in kg for both, the Purchase Order on header, as well as on item level, some custom logic needs to be implemented, that we create via the Fiori App Custom Logic. In the app, we create one Enhancement Implementation to calculate the CO2e Footprint for the Purchase Order Item and one for the Purchase Order Header. Both Enhancement Implementations again need to be created in the correct Business Context for the Purchasing Documents and need to implement the proper BAdIs Modify Purchase Order Header and Modify Purchase Order Item.

SAP S/4HANA, SAP HANA Career, SAP HANA Jobs, SAP HANA Skills, SAP ABAP News, SAP HANA Preparation
Create Custom Logic

Select each of the Enhancement Implementations and implement the custom logic in ABAP for Key Users:

SAP S/4HANA, SAP HANA Career, SAP HANA Jobs, SAP HANA Skills, SAP ABAP News, SAP HANA Preparation
Custom Logic BAdI Implementation

The following ABAP code is an example Enhancement Implementation to calculate the CO2e Footprint on Purchase Order Header level (BAdI Modify Purchase Order Header in Business Context Procurement: Purchasing Document):

* purchaseorderchange-<your_field_name> = 'Your field content'.

DATA total_quantity      TYPE decfloat34 VALUE 0.
DATA total_quantity_unit TYPE meins.

" get footprint calculation API
TRY.
    DATA(lo_calculation_api) = cl_supfm_tdfp_calc_api_factory=>get_factory( )->get_calculation_api( ).

  CATCH cx_supfm_tdfp_calc_api_factory INTO DATA(lx_supfm_tdfp_calc_api_factory).
    INSERT VALUE #(
      messageid        = 'MEPO'
      messagetype      = 'E'
      messagenumber    = 250
      messagevariable1 = lx_supfm_tdfp_calc_api_factory->get_text( )
    ) INTO TABLE messages.
    RETURN.

ENDTRY.

LOOP AT purchaseorderitem_table REFERENCE INTO DATA(purchaseorderitem).

  TRY.
      " calculate the CO2e Footprint for the purchase order item
      DATA(ls_calculation_result_ghg) = lo_calculation_api->calculate_ghg( VALUE #( (
        product       = purchaseorderitem->material
        plant         = purchaseorderitem->plant
        quantity      = purchaseorderitem->orderquantity
        unitofmeasure = purchaseorderitem->purchaseorderquantityunit
      ) ) ).

      " in case a footprint for the item was successfully calculated, add the footprint value to the total quantity for the purchase order
      IF ls_calculation_result_ghg-has_result = abap_true.
        total_quantity      = total_quantity + ls_calculation_result_ghg-pfmfootprintquantity.
        total_quantity_unit = ls_calculation_result_ghg-pfmfootprintunit.
      ENDIF.

    CATCH cx_supfm_tdfp_calc_api INTO DATA(lx_supfm_tdfp_calc_api).
      INSERT VALUE #(
        messageid        = 'MEPO'
        messagetype      = 'E'
        messagenumber    = 250
        messagevariable1 = lx_supfm_tdfp_calc_api->get_text( )
      ) INTO TABLE messages.

  ENDTRY.

ENDLOOP.

" set quantity aggregated over all purchase order items into custom field of the purchase order
TRY.
    purchaseorderchange-yy1_co2efootprintinkg_pdh  = total_quantity.
    purchaseorderchange-yy1_co2efootprintinkg_pdhu = total_quantity_unit.
  CATCH cx_sy_conversion_overflow.
    INSERT VALUE #(
        messageid        = 'MEPO'
        messagetype      = 'E'
        messagenumber    = 250
        messagevariable1 = 'Aggregated CO2e Footprint exceeds size of quantity field.'
      ) INTO TABLE messages.
ENDTRY.

You can easily modify this example implementation to make it also fit for the BAdI Modify Purchase Order Item.

Adapt UI


As a last step, the new custom fields need to be made available in the Manage Purchase Orders Fiori app. On the list-based UIs, like the list report of the Manage Purchase Orders app or the items table of the Purchase Order object page, this is easily achievable via the View Settings of the table control:

SAP S/4HANA, SAP HANA Career, SAP HANA Jobs, SAP HANA Skills, SAP ABAP News, SAP HANA Preparation
Add CO2e Footprint via View Settings of the Table

To add the footprint to the Purchase Order Header, you need to adapt the UI via the user profile:

SAP S/4HANA, SAP HANA Career, SAP HANA Jobs, SAP HANA Skills, SAP ABAP News, SAP HANA Preparation
Adapt UI

By doing this, it is possible for example, to add the CO2e Footprint on the Purchase Item Header under a new Group:

SAP S/4HANA, SAP HANA Career, SAP HANA Jobs, SAP HANA Skills, SAP ABAP News, SAP HANA Preparation
Add CO2e Footprint of Purchase Order under a new Group

No comments:

Post a Comment