Skip to Content

Create Custom Logic Using Key User Extensibility and Perform Trace

Create custom logic for an existing custom field in S/4HANA Cloud ABAP Environment, then check its parameters using the Custom Logic Tracing app
You will learn
  • How to create custom logic for an existing custom field in the app Custom Fields
  • How to run a trace for the Fiori app Create Purchase Order in the app Custom Logic Tracing
  • How to check the output value of this custom field using Custom Logic Tracing
  • How to check the custom logic of this custom field, in Custom Fields
julieplummer20Julie PlummerNovember 24, 2022
Created by
julieplummer20
May 24, 2022
Contributors
julieplummer20
dermats
maximilianone

Prerequisites

  • You have a license for SAP S/4HANA Cloud
  • You are familiar with Key User extensibility in SAP S/4HANA Cloud. If not, see the More Information section
  • You are familiar with the app Custom Logic Tracing. If not, see the More Information section
  • In SAP Fiori launchpad, you have the following authorizations:
    • SAP_BR_PURCHASER for the app Create Purchase Order - Advanced
    • SAP_BR_ADMINISTRATOR for Custom Logic Tracing and Custom Logic
  • You have created a custom field using Key User extensibility yy1_zhdrprnt2_pdh_000
  • In Custom Logic, you have created a BAdI implementation YY1_FILLHEADERCUSTOMFIELDS_000 in the business context and BAdI definition Modify Purchase Order Header (MM_PUR_S4_PO_MODIFY_HEADER)

The administrator receives an welcome e-mail after provisioning. This e-mail includes the system URL. By removing /ui you can log into the SAP S/4HANA Cloud ABAP Environment system. Further information can be found Developer Extensibility: Connect to the ABAP System.

Throughout this tutorial, the placeholder ### or 000 is used. Always replace this with your initials or group number.

  • Step 1
    1. Open the app Custom Fields.

      step1a-open-custom-fields
    2. Change to the Custom Logic tab, search for the BAdI implementation YY1_FILLHEADERCUSTOMFIELD_000.

      Link text e.g., Destination screen
    3. Open the Details screen (by choosing the arrow on the right).

      step6b-badi-implementation-overview

    You can now see the Published Logic and Draft Logic, if they exist, relevant to the custom field.

    step1c-custom-logic-empty
  • Step 2
    1. Comment out any existing code.

    2. In the custom logic for the field yy1_zhdrprnt2_pdh_000, copy the following code.
      This code will copy the content from a standard field, purchaseorder-supplyingplant into the custom field, yy1_zhdrprnt2_pdh_000, where supplyingplant is filled.

      ABAP
      Copy
      IF purchaseorder-supplyingplant is not initial.
      purchaseorderchange-yy1_zhdrprnt2_pdh_000 = purchaseorder-supplyingplant.
      endif.
      
      
      step2a-add-custom-logic
    3. Save and publish your custom code.

    You are now ready to trace the effects of your custom code when a purchase order is created.

  • Step 3
    1. Open the app Custom Logic Tracing and choose Start Trace.

      step1a-start-trace
    2. Enter the following information, remembering to change the placeholder to your group number or initials:

      Field Name Value
      Name Test Create PO Custom Fields 000
      Trace User Your user
      Stored until future date in the format dd.mm.yyyy
      Lifetime 15
      step1b-start-trace-details
  • Step 4

    IMPORTANT: While Trace is running, create a purchase order as follows.

    1. Open Create Purchase Order - Advanced.

      step4a-create-po
    2. In the top header, change the Order Type to Stock Transport Order and the Supplying Plant to 1010.

      step4b-change-to-stock-transport-order
    3. Enter the Supplying Plant, 1010

      step4c-supplying-plant
    4. In the header section, go to the Custom Fields tab, check that the custom field ZPOHDRPRINT2 now contains the value 1010.

      step4a-create-po-custom-field
    5. On the Org Data tab, enter the following:

      Field Name Value
      Purchase Organization 1010
      Group 001
      Company code 1010

      If you check the custom field YY1_ZHDRPRNT2_PDH_000, it is now filled with the same value as Supplying Plant, 1010.

      step2c-fill-org-data
    6. In the Item Overview section, enter the following. Ignore any warnings.

      Field Name Value
      Material Tg0501
      PO Quantity 1
      Delivery Date future date in the format dd.mm.yyyy
      Plant 1010
      step4d-fill-item-overview-material

      The other fields - Material Group, Plant Storage Location - should be filled automatically.

      step2d-fill-item-overview
    7. Choose Save.

      step4e-note-stock-transport-number
  • Step 5
    1. Choose Finish trace.

      step5a-finish-trace
    2. Open the trace. In Trace Hierarchy, choose the last call of BAdI implementation YY1_FILLHEADERCUSTOMFIELD_000.
      (This is necessary because the BAdI implementation is called several times.)
      Then choose the parameter Purchase Order.

      step5b-choose-purchase-order
    3. Scroll right down to the field YY1_ZHDRPRNT2_PDH_000. Check that its value = 1010.

      step5c-choose-custom-field
  • Step 6

    In which Fiori app do you find all custom implementations that are called during a process?

  • Step 7

Back to top