Skip to Content
Product Information
Author's profile photo Christoph Zeh

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. For details about SAP Product Footprint Management, the blog post Product Deep Dive: Welcome to Product Footprint Management from SAP is a good entry point.

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.

Sustainability%20Integration%20Component%20in%20SAP%20S/4HANA

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:

List%20report%20of%20the%20Manage%20Purchase%20Order%20App%20with%20CO2e%20Footprint

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:

Purchase%20Order%20with%20CO2e%20Footprint

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:

Apps%20for%20Custom%20Fields%20and%20Custom%20Logic

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:

Create%20custom%20fields

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.

Create%20custom%20logic

Create Custom Logic

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

Custom%20logic%20BAdI%20Implementation

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:

Add%20CO2e%20Footprint%20via%20View%20Settings%20of%20the%20table

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:

Adapt%20UI

Adapt UI

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

Add%20CO2e%20Footprint%20of%20Purchase%20Order%20under%20a%20new%20Group

Add CO2e Footprint of Purchase Order under a new Group

Summary

In this blog post, I show you how CO2e Footprints can be embedded into the operational purchasing process. Of course, based on customer requirements, there are a lot more possibilities to embed sustainability metrics into the business processes, which can be implemented on a project basis by leveraging the Key User Extensibility accessing the Sustainability Integration Component’s released APIs.

With S/4HANA Cloud 2202 and S/4HANA 2022, the following C1 released CDS API are available for consumption through Key User Extensibility:

In addition, the footprint calculation API as outlined in above code example is available with S/4HANA Cloud 2208 and S/4HANA 2022.

Of course, the same APIs can also be used outside the Key User Extensibility in classic enhancements concepts in the S/4HANA on-premise versions and even via Developer Extensibility in a SAP S/4HANA Cloud system.

Assigned Tags

      9 Comments
      You must be Logged on to comment or reply to a post.
      Author's profile photo Olaf Steinrücken
      Olaf Steinrücken

      Hi Christoph Zeh ,
      this is a great blog demonstrating the strengths of key user extensibility!
      Thanks a lot.
      Do we interpret it right, that the relevant API is part of on premise Rel. 2022 (and Cloud 2208) only and as of Rel. 2021 this extension option is no yet available?
      Thanks for a short confirmation
      Kind regards, Olaf

      Author's profile photo Christoph Zeh
      Christoph Zeh
      Blog Post Author

      Hi Olaf,

      indeed the released ABAP API as used in the code sample above, is only available with on premise 2022 and cloud 2208.

      But as part of on premise 2021 FPS1, we already shipped a CDS view, from which you can retrieve the CO2e Footprints.

      Simply replace the loop in the BAdI implementation above by the following:

      DATA: footprint type ty_s_masterdatafootprint.
      
      LOOP AT purchaseorderitem_table REFERENCE INTO DATA (purchaseorderitem).
      "       select from released CDS view i_co2eqfprntavgrltvbaseuom
                  select
                      _co2eq~product,
                      _co2eq~plant,
                      _co2eq~pfmfootprintquantity,
                      _co2eq~pfmfootprintunit
                  from i_co2eqfprntavgrltvbaseuom as _co2eq
                  where _co2eq~product = purchaseorderitem->material
                      and _co2eq~plant = purchaseorderitem->plant
                  INTO CORRESPONDING FIELDS OF @footprint .
                  endselect.
      
              total_quantity = total_quantity + footprint-pfmfootprintquantity * purchaseorderitem->orderquantity.
              total_quantity_unit = footprint-pfmfootprintunit.
      ENDLOOP.

      Important to mention: The CDS view provides the CO2e Footprints per Base Unit of Measure of the product, as defined in the material master. In case the purchase order item quantity is in different UoM, you would need to handle this in the coding. This is something what the ABAP API on the later release takes care of.

      Best regards,

      Christoph

       

      Author's profile photo Naveen Kumar Jain
      Naveen Kumar Jain

      Thanks Christoph Zeh

      This is realy nice blog.

      I am getting Type cl_supfm_tdfp_calc_api_factory unknow error. This code i added in Header level.

      I checked this class does not exist in Our S/4Hana 2021 system.

      As per your blog we have to install SUS-PFM app component right in S/4Hana system? do we need any license for this?

       

       

      In Se24 i am able to see only below classes.

       

      Regards

      Naveen Jain

      Author's profile photo Christoph Zeh
      Christoph Zeh
      Blog Post Author

      Hi Naveen Jain,

      right, as stated in the blog, this ABAP API will be available with S/4HANA Cloud 2208 and S/4HANA  2022.

      Please have a look in into my previous comment for a solution on S/4HANA 2021.

      Best regards,

      Christoph

      Author's profile photo Naveen Kumar Jain
      Naveen Kumar Jain

      Dear Christoph

      Yes did the same, see attached screen shot.

      If you think something missing the code can you please paste here.

      I have doubt on ype cl_supfm_tdfp_calc_api_factory  class.

       

      Regards

      Naveen Jain

      Author's profile photo Christoph Zeh
      Christoph Zeh
      Blog Post Author

      Hi Naveen Jain,

      you can remove the instantiation of the calculation API including the whole try-catch block (line 7 to 19).

      Best regards,

      Christoph

      Author's profile photo Naveen Jain
      Naveen Jain

      Dear Christoph,

      That accessing the CDS-view is not releases for key user extensibility but only for standard ABAP-development? Am i right.

      Because we are getting below error when trying to read given CDS. CDS Entity not permitted.

       

      Regards

      Naveen

      Author's profile photo Christoph Zeh
      Christoph Zeh
      Blog Post Author

      Hi Naveen,

      in case you are on S/4HANA 2021 FPS0, you are unfortunately right. I missed that the CDS view has been released for key user extensibility with 2021 FPS1 (see SAP Note 3110989).

      As the view already exists on FPS0, you could potentially apply a manual correction, adding a release contract (C1) with the option "Use in Key User Apps" selected:

      C1%20Release%20Contract

      C1 Release Contract

      Best regards,

      Christoph

      Author's profile photo Kiran Shankar
      Kiran Shankar

      Hello Christoph Zeh,

      Great Functionality addition to Footprint data.  Looking forward to explore this functionality.

       

      Regards,

      Kiran Shankar