#saveThePlanet requires drilling into the details: Carbon Footprint Category Breakdown is released. Read my Blog article on how to extend your applications easily with Key User and Developer Extensibility for #SAPS4HANA
SAP S/4HANA provides features that allow to extend existing applications with carbon footprint data. Our team’s previous Blog post described how to extend existing applications with carbon footprints, on the example of Manage Purchase Order. This is meanwhile standard functionality of Purchase Requisition and Purchase Order in current SAP S/4HANA releases. Nevertheless, the Blog post is still relevant for on premises installations not yet on the newest release and furthermore also for applications not yet enabled with footprints.
Today we bring it to the next level with our latest SAP S/4HANA Cloud 2408 release which includes the latest Sustainability Integration Component. It is enabled by Scope Item 5IM “Product Footprint Management” since several years, specifically since SAP S/4HANA Cloud 2108 and SAP S/4HANA 2021. We introduced new CDS views as listed here including:
For an introduction into the topic of footprints, see the training Climate Action with SAP Sustainability Footprint Management. It starts with an overview of Climate Action offerings by SAP and then focuses on SAP Sustainability Footprint Management hands-on and explains master data, transactional data, footprint computation etc.
Before you continue with the content below, I recommend making yourself familiar with Key User Extensibility and Developer Extensibility if you are not familiar already. I recommend Learning Journey “Practicing Clean Core Extensibility For SAP S/4HANA Cloud”, especially the chapters
Make sure you have the following business roles assigned in your system:
Custom Fields is a tool for Key User Extensibility. Using this tool, a key user can create and edit custom fields for SAP tables, Core Data Service (CDS) views or OData services and expose them to the UI.
I now extend Purchase Requisition Item. It already shows the CO2e footprint, and I additionally insert GHG category breakdown by adding a Custom Field. The steps required are:
As you saw in step 3 in the screenshot above, the category breakdown is placed now in the UI, but it does not yet show any value. Now I add the logic to define the text value. Go to application Custom Logic, add a new implementation in the Business Context and Extension Point as shown in the screenshot below.
For the code, you can take the example below as a first draft. It composes the text for the GHG breakdown by calling our Calculation API, looping through the returned components, and doing basic error handling. It is good practice to limit the code to your user at first to try things out without interfering with others, adapt this in line 1 before you proceed.
IF purchaserequisitionitem-createdbyuser = 'CB9980004180'. "Martin Knechtel
" get footprint calculation API
TRY.
purchaserequisitionitemchange-yy1_mk_pr_co2category_pri = 'CO2e category breakdown coming from my Key User Extensibility'. "our custom field receives a first initial assignment, helps you debugging
CATCH cx_sy_conversion_overflow.
INSERT VALUE #(
messageid = 'MEPO'
messagetype = 'E'
messagenumber = 250
messagevariable1 = 'CO2e category breakdown exceeds size of Custom Field.'
) INTO TABLE messages.
ENDTRY.
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.
TRY.
" calculate the CO2e Footprint for the purchase requisition item
DATA(ls_calculation_result_ghg) = lo_calculation_api->calculate_ghg_with_log(
VALUE #( (
Product = purchaserequisitionitem-material "e.g. 'BUTTER100'
Plant = purchaserequisitionitem-plant "e.g. '1010'
Quantity = purchaserequisitionitem-orderedquantity "e.g. '3'
UnitOfMeasure = purchaserequisitionitem-purchaseorderquantityunit "e.g. 'KG'
) ) ).
" in case a footprint for the item was successfully calculated, loop over the components
DATA responseString TYPE string.
IF ls_calculation_result_ghg-has_result = abap_true.
LOOP AT ls_calculation_result_ghg-pfmfootprintcomponents REFERENCE INTO DATA(component).
DATA(quantityRounded) = round( val = component->pfmfootprintquantity
dec = 3 ).
responsestring = |{ responsestring }{ component->pfmfootprintqtycomponenttype }: { quantityRounded } { component->pfmfootprintunit } / |.
ENDLOOP.
ELSE.
responsestring = |No CO2e scope categories found. Log: { ls_calculation_result_ghg-calculation_log->get_calculation_log_json( ) } Input: | &&
|{ purchaserequisitionitem-material },{ purchaserequisitionitem-plant },{ purchaserequisitionitem-orderedquantity },{ purchaserequisitionitem-purchaseorderquantityunit }|.
ENDIF.
responsestring = |{ responsestring } at { cl_abap_context_info=>get_system_date( ) }{ cl_abap_context_info=>get_system_time( ) }|.
purchaserequisitionitemchange-yy1_mk_pr_co2category_pri = responsestring.
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.
ENDIF.
Returning to your Purchase Requisition Item you should now see the CO2e category breakdown similarly to the screenshot below.
Above I introduced Custom Logic for the ABAP code to prepare your text to be shown in the UI. This was done with Key User Extensibility tools. Now I switch into Developer Extensibilty. Preparing code with ADT is more comfortable if the Custom Logic above gets extensive. Debugging is possible. You can also encapsulate part of the logic and call it from the extension point Custom Logic above. An example is shown in the screenshot below. Similarly to the code example above, it calculates a transaction data footprint from a master data footprint and prepares the calculated GHG component breakdown to a string. Here it prints it to the console, but I could also assign it to some custom field, as shown above.
In case there is no master data footprint found for the given product “BUTTER100”, an error with message number 4 is returned. As shown in the screenshot, the CM_SUPFM_TDFP_LOGGER message class was opened to retrieve the message text from the message number. This might indicate to the developer that no test data was created yet on the system and afterwards he can proceed debugging and developing. With that, I walked you through an end to end example for extending your application with sustainability features with Key User Extensibility and Developer Extensibility.
Disclaimer: I describe the work of many here and I am only one of the contributors in a great and dedicated team. We keep on rocking to deliver you the latest and greatest sustainability integration into SAP S/4HANA.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
16 | |
5 | |
5 | |
5 | |
3 | |
3 | |
2 | |
2 | |
2 | |
2 |