Adding a Custom Timestamp to the Purchase Order in S/4HC
Recently, I worked with a customer who had a requirement to notify an external system of Purchase Order (PO) changes. The real time SOAP based integration delivered for POs in scope item 2EJ didn’t work for them because they wanted the external system to call back to the S/4HC system for only a few fields on the PO (mainly line item details). However, the current PO API does not have a lastChanged timestamp like some of the other APIs (i.e. part master, sales order) so there was not a way to tell which POs had been created or changed since a certain date/time. If SAP adds a changed timestamp to the PO API in the future, this will not be necessary anymore.
In this blog, we’ll create a custom field to hold a date modified timestamp and populate the field by using Custom Logic enhancement Modify Header in PO BaDI available for the PO Business context –which would trigger on a PO creation or modification.
Let’s get started:
1. In the S/4HC system, navigate to Extensibility->Custom Fields and Logic app
2. Click on Create icon to add a new field
3. Enter the details for the custom field and click “Create and Edit”. Complete the details as follows for the new field, select Purchasing Document as the Business Context
4. On the UIs and Reports tab, click the enable usage button for the following (or according to your requirements)
5. Click on Save & then click publish
6. Before proceeding to the next step, wait for the field to successfully be published
Now, it’s time to create the custom logic
7. Go to the Custom Logic tab in Extensibility and click on the + icon to create a new enhancement
8. Enter the details as follows and click the create button
9. Implement the code to populate the field
DATA wa_time type timestamp.
get TIME STAMP FIELD wa_time.
purchaseorderchange-yy1_polastchangetimest_pdh = wa_time.
10. Save the Draft, then Publish the logic
Now it’s time to test out the logic! In this example, we’ll test by calling the API using the Postman tool
11. First, create or modify a few purchase orders
12. In this example, I change the line item quantity on the PO and some others at the header level
13. Now, if you first look at the metadata on the API, you will see the custom field
14. Next you can form your query to ask the system for all POs modified after a certain date. For example, all POs after April 5th 2018.
A_PurchaseOrder?$select=PurchaseOrder&$filter= YY1_POLastChangeTimeSt_PDH gt ‘20180405122517’
15. Then if I put the timestamp even later I filter down the results to 2
For information on extensibility options for the Purchase Order, refer to SAP S/4HANA Cloud help documentation under Product Assistance-><Language>->Home->Sourcing and Procurement->Operational Procurement->Manage Purchase Orders->App Extensibility: Manage Purchase Orders