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: 
surbhi_bansal
Participant

The Purchase Requisition OData API is provided to the end user in order to consume the functionality of an SAP S/4 HANA system for integration scenarios.


The OData API can be consumed by configuring the relevant Communication Arrangement and is supported for communication scenario: Purchase Requisition Integration (SAP_COM_0102)


Please refer the blog post for setting up a communication arrangement.


I would like to cover the below create and read operations for Purchase Requisition and its associated entities using ODATA API, in this blog post to ease the life of developers.


Reading a Purchase Requisition


The Purchase Requisition has the following embedded entity setup –



  • Header data


    • Item data


      • Account Assignment

      • Delivery Address

      • Notes






      • Note: – As per the entity structure it is clear that Account assignment, delivery address and Notes data cannot be accessed without an Item reference. Similarly, Purchase Requisition Item data cannot be reference without Purchase Requisition header reference.


        Thus, reading a Purchase Requisition can depend on what all data the end user seeks w.r.t the requisition in system. A user can read one or more entity data based on the request URL. For example –


        Read only Purchase Requisition Header https:// myXXXXXX-api. s4hana.ondemand.com/sap/opu/odata/SAP/ API_PURCHASEREQ_PROCESS_SRV/A_Purchase... (GET)


        Read Purchase Requisition Header along with item
        https:// myXXXXXX-api. s4hana.ondemand.com/sap/opu/odata/SAP/ API_PURCHASEREQ_PROCESS_SRV/A_Purchase... (GET)


        Read Purchase Requisition Header along with item(s), account assignment, Delivery Address and Notes https:// myXXXXXX-api. s4hana.ondemand.com/sap/opu/odata/SAP/ API_PURCHASEREQ_PROCESS_SRV/A_Purchase... (GET)


        Creating a Purchase Requisition


        You can create a new Requisition in Simulation mode when you don’t want the data to be posted but only validated for any errors and/warnings. End user can use ‘PurReqnDoOnlyValidation’ flag in Purchase Requisition header as ‘true‘ in POST request.


        https:// myXXXXXX-api. s4hana.ondemand.com/sap/opu/odata/SAP/ API_PURCHASEREQ_PROCESS_SRV/A_Purchase... (POST)


        Sample request payload :
        {
        “PurchaseRequisition”:””,
        “PurchaseRequisitionType”:”NB”,
        “PurReqnDescription”:”Test PR
        “SourceDetermination”:false,
        “PurReqnDoOnlyValidation”:true
        }


        Points to note:
        1. Your requisition will be created in Logon language, else it shall generate an error.
        2. You can trigger creation of multiple Requisitions in batch using multiple changesets.


        Reading a Purchase Requisition Item


        Follow the sample URLs to fetch Purchase Requisition Item details along with its associated entities.


        Read for a single Purchase Requisition Item https:// myXXXXXX-api. s4hana.ondemand.com/sap/opu/odata/SAP/ API_PURCHASEREQ_PROCESS_SRV/A_Purchase... (GET)


        Read for a single Purchase Requisition Item with its associated entities https:// myXXXXXX-api. s4hana.ondemand.com/sap/opu/odata/SAP/ API_PURCHASEREQ_PROCESS_SRV/A_Purchase... (GET)


        Creating a Purchase Requisition Item


        The API supports creating a new requisition with one or more items, as well as adding items in existing purchase requisition (bulk create).
        We can add a new item in a Purchase Requisition (Minimum data set) as follows –


        {
        “PurchaseRequisition”:”10011683″,
        “PurchaseRequisitionItem”:”10”,
        “PurchaseRequisitionItemText”:”Item1″,
        “AccountAssignmentCategory”:”U”
        “MaterialGroup”:”MatGrp1”,
        “RequestedQuantity”:”10”,
        “BaseUnit “: “P “,
        “PurchaseRequisitionPrice “: “10”,
        “PurchasingGroup”: “PGrp1”
        “Plant”: “1010”
        “CompanyCode”: “1010”,
        “to_PurchaseReqnAcctAssgmt”: {
        },
        “to_PurchaseReqnDeliveryAddress”: {
        },
        “to_PurchaseReqnItemText”: {
        }
        }


        Points to note:
        1.While posting an item, post it along with its associated entities else your request shall fail.

        2.You can send a batch of create items (one changeset deals with single Purchase Requisition, for multiple requisitions, use multiple changesets)


        Item Account Assignment and Delivery Address
        Create request for accounting and delivery address shall fail as these are dependent for Purchase requisition item (entities with dependency on Item data).


        Purchase Requisition Item Text
        In context of Purchase requisition only Item notes are supported. A requisition does not have any header level note.


        Read an Item Text (Note)


        You can fetch an Item text(note) in various ways, refer to sample URLs below.


        You can fetch Notes for all Items in PR as follows https:// myXXXXXX-api. s4hana.ondemand.com/sap/opu/odata/SAP/API_PURCHASEREQ_PROCESS_SRV/A_PurchaseR... (GET)


        You can fetch all notes for an item in PR as follows https:// myXXXXXX-api. s4hana.ondemand.com/sap/opu/odata/SAP/API_PURCHASEREQ_PROCESS_SRV/A_PurchaseR... (GET)


        You can fetch an item note for a PR as follows https:// myXXXXXX-api. s4hana.ondemand.com/sap/opu/odata/SAP/ API_PURCHASEREQ_PROCESS_SRV/A_Purchase... (GET)


        Create an Item Text (Note)


        https:// myXXXXXX-api. s4hana.ondemand.com/sap/opu/odata/SAP/API_PURCHASEREQ_PROCESS_SRV/A_PurchaseR... (POST)
        {
        “PurchaseRequisition”: “4000084870”,
        “PurchaseRequisitionItem”: “10”,
        “DocumentText”: “B02”,
        “NoteDescription”: “note2”
        }


        Let us know your comments and/or suggestions with regards to Purchase Requisition in SAP S/4 HANA Cloud and OData APIs.


        Please follow the next blog for details regarding Edit & delete on Purchase Requisition and its entities.

        5 Comments