Enterprise Resource Planning Blogs by SAP
Get insights and updates about cloud ERP and RISE with SAP, SAP S/4HANA and SAP S/4HANA Cloud, and more enterprise management capabilities with SAP blog posts.
cancel
Showing results for 
Search instead for 
Did you mean: 
MartyMcCormick
Product and Topic Expert
Product and Topic Expert

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


image1.png


2. Click on Create icon to add a new field


image2.png


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


image3.png


4. On the UIs and Reports tab, click the enable usage button for the following (or according to your requirements)


image4.png



5. Click on Save & then click publish


image5.png


6. Before proceeding to the next step, wait for the field to successfully be published


image6.png


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


image7.png


8. Enter the details as follows and click the create button


image8.png


9. Implement the code to populate the field


image9.png


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


image10.png


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


image11.png


12. In this example, I change the line item quantity on the PO and some others at the header level


image12.png


13. Now, if you first look at the metadata on the API, you will see the custom field


image13.png


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'


image14.png



15. Then if I put the timestamp even later I filter down the results to 2


image15.png



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


Thanks,
Marty

3 Comments