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: 
murthy_v
Advisor
Advisor
4,312
SAP Business ByDesign (ByD) provides you with REST/OData access to Sales Order Price Components both header and item level components (Price, Discount, Surcharge, Freight ...). This blog post provides you with an sample round trip examples of price components (create – read – update - delete) using ByD OData services for sales order business object.

In the demo below you see how you can how to create custom OData service and use the service to perform CRUD operation on Sales Order price components.


Example Scenario


In the example we are creating reading updating deleting (CRUD) price components of sales order using SAP Business ByDesign Custom OData Services.

Sample sales order header level price components include:

  • Overall Discount

  • Freight

  • Restocking Fee

  • Surcharge

  • Additional Overall Discount (%)

  • Additional Overall Discount


Sample sales order item level price components include:

  • Product Discount

  • Price

  • Surcharge (Fixed Value)

  • Surcharge (%)

  • Quality Loss Fee

  • Goodwill (%)

  • Warranty (%)

  • Working Condition (%)


Note: the sales order document has pricing in set to Net or Gross pricing procedure, both options with samples are explained in detail.


Expose ByD Sales Order Price Components as OData Service


Open work center view Application and User Management – OData Services and create a Custom OData Service for business object Sales Order.

Make sure you expose header and item price component properties that enable you to create, filter, read, update and delete all relevant price components data incl. nodes Root, SalesOrderPriceAndTaxCalculation, SalesOrderOperationalPriceComponent, SalesOrderItem, SalesOrderOperationalItemPriceComponent. In my example I included the following elements to my Custom OData Service “salesorderpricecomponents“:

  • ID

  • SalesOrderPriceAndTaxCalculation (header level price components)

  • SalesOrderOperationalPriceComponent

    • TypeCode

    • DecimalValue

    • CurrencyCode

    • BaseMeasureUnitCode

    • BaseDecimalValue

    • MeasureUnitCode

    • RateBaseQuantityTypeCode



  • SalesOrderItem (created from the Item association from SalesOrderPriceAndTaxCalculation )

  • SalesOrderOperationalItemPriceComponent (created from the OperationalItemPriceComponent association from SalesOrderItem )

    • TypeCode

    • DecimalValue

    • CurrencyCode

    • BaseMeasureUnitCode

    • BaseDecimalValue

    • MeasureUnitCode

    • RateBaseQuantityTypeCode






Activate your custom OData service and note down the Service URL from the OData Editor. In my example the service URL is

https://{{TenantHostname}}/sap/byd/odata/cust/v1/salesorderpricecomponents

If needed you can retrieve the metadata using the metadata URL

https://{{TenantHostname}}/sap/byd/odata/cust/v1/salesorderpricecomponents/$metadata

Note: replace the {{TenantHostname}} with ByD tenant host name, example: my123456.sapbydesign.com

 


Document Level Price Components


The sales order document has pricing in set to Net or Gross pricing procedure, both options with samples are explained in detail.

User can create read update delete both header level price components using the following Type Codes for both Net pricing and Gross pricing procedure, following are the list of type codes you can use to handle different price components.

List of Document / Header level price components in Net Pricing Procedure are listed below.







































 
          Price Component    Type Code


          Overall Discount

Additional Overall Discount (%)

Additional Overall Discount


      0007

2007

3007
          Freight       7PR8
         Restocking Fee       7PRB
         Surcharge       0001
         Surcharge 2       0002
         Surcharge 3       0003
         Surcharge 4       0004
         Surcharge 5       0005

Note: for Additional Overall Discount to be available make sure you have scoped the business configuration option "Do you want additional discounts at document level?" under General Business Data -> Product and Service Pricing -> Sales Price Specifications

List of Document / Header level price components in Gross Pricing Procedure are listed below.

 



















 
          Price Component    Type Code


          Gross Overall Discount

Gross Additional Overall Discount (%)

Gross Additional Overall Discount


      1007

4007

5007
          Gross Freight       8PR8
          Gross Restocking Fee       8PRB


Create Update and Delete Overall Discount using the Custom OData Service


In the custom OData service select the header level price component relevant fields in co-relation with UI fields of Overall Discount in Total Pricing of Pricing and Invoicing tab of Sales Order.





 

Step 1: Create Overall Discount

Using the http-method POST and entity set SalesOrderOperationalPriceComponent you can create Overall Discount, make sure you pass the values for following elements ParentObjectID, TypeCode, DecimalValue and MeasureUnitCode:

https://{{TenantHostname}}/sap/byd/odata/cust/v1/salesorderpricecomponents/SalesOrderOperationalPric...

In my example I’m using the JSON body ( ParentObjectID is the Sales Order Object ID )
{		
"ParentObjectID": "00163E7306A31EE9A9F22559D802809B",
"TypeCode": "0007",
"DecimalValue": "10",
"MeasureUnitCode": "P1"
}

and the http-header parameter

  • x-csrf-token=fetch to get the CSRF-token to create the material via POST service call ( note: the x-csrf-token is fetched in the GET service call , for details refer to postman example collection ).

  • Note: Sales Order ID should be the valid and existing id in system.



As result ByD returns the following OData response body:



 

As you can see the Overall Discount is created with relevant information.



      Note:  Details about x-csrf-token:

  • SAP Business ByDesign System generates a CSRF token and sends it back in the HTTP response header field X-CSRF-Token.
    This happens in a non-modifying request (such as GET) if the header field X-CSRF-Token with the value Fetch is sent along with the non-modifying request.

  • Note: CSRF (Cross Site Request Forgery) token is a random, hard-to-guess string. the server would generate a random string and is stored in the session or by setting a cookie containing the value

  • For example Steps to Follow:

  • Step 1: call the Get service by setting the Header key field “x-csrf-token”  with value “fetch”

  • Step 2: in the HTTP response header of above GET service call you read the field value “x-csrf-token”

  • Step 3: in the subsequent POST calls use the x-csrf-token .


 

Step 2: Update Overall Discount

Using the http-method PUT and entity set SalesOrderOperationalPriceComponentCollection you can update the Overall Discount, make sure you pass the values for following elements ObjectID, ParentObjectID, TypeCode, DecimalValue and MeasureUnitCode:

https://{{TenantHostname}}/sap/byd/odata/cust/v1/salesorderpricecomponents/SalesOrderOperationalPriceComponentCollection('{{SalesOrderPriceComponentObjectID}}')

In my example I’m using the JSON body ( ParentObjectID is the Sales Order Object ID )
{
"ObjectID": "{{SalesOrderPriceComponentObjectID}}",
"ParentObjectID": "{{SalesOrderPriceComponentParentObjectID}}",
"TypeCode": "0007",
"DecimalValue": "30",
"MeasureUnitCode": "P1"
}



 

As result the sales order overall discount gets updated:



 

Step 3: Delete Overall Discount

Using the http-method DELETE and entity set SalesOrderOperationalPriceComponentCollection you can delete the Overall Discount, make sure you pass the value of the specific instance id of overall discount which just got updated.

https://{{TenantHostname}}/sap/byd/odata/cust/v1/salesorderpricecomponents/SalesOrderOperationalPriceComponentCollection('00163E7306A31EE9ADE807199DB301F600163E7306A31EE9ADEAFBDAE83436AB')

to delete an instance JSON body is required, you have to pass only the instance id of the price component to be deleted, as shown above.



Note: instance to be deleted can be fetched by performing the GET operation and getting the right instance of the overall all discount of sales order.

GET before delete is required since after the UPDATE operation the instance id of the overall discount is changed.



 

Create Update and Delete Freight using the Custom OData Service


User can create document level Freinght in Total Pricing of Pricing and Invoicing tab of Sales Order using the OData service by following the steps mentioned below.



 

Step 1: Create Freight 

Using the http-method POST and entity set SalesOrderOperationalPriceComponent you can create header level / document level Freight, and make sure you pass the values for following elements ParentObjectID, TypeCode, DecimalValue and CurrencyCode:

https://{{TenantHostname}}/sap/byd/odata/cust/v1/salesorderpricecomponents/SalesOrderOperationalPric...

In my example I’m using the JSON body ( ParentObjectID is the Sales Order Object ID )
{		
"ParentObjectID": "00163E7306A31EE9ADE807199DB301F6",
"TypeCode": "7PR8",
"DecimalValue": "10",
"CurrencyCode": "USD"
}

 

As result ByD returns the following OData response body:



 

As you can see the document level Freight is created with relevant information.



 

Note: for Update and Delete of header level Freight please follow same steps as mentioned above in step 2 and step 3 of Overall Discount.

 

Create Update and Delete Restocking Fee using the Custom OData Service


User can create Restocking Fee in Total Pricing of Pricing and Invoicing tab of Sales Order using the OData service by following the steps mentioned below.



 

Step 1: Create Restocking Fee

Using the http-method POST and entity set SalesOrderOperationalPriceComponent you can create Restocking Fee, and make sure you pass the values for following elements ParentObjectID, TypeCode, DecimalValue and CurrencyCode:

https://{{TenantHostname}}/sap/byd/odata/cust/v1/salesorderpricecomponents/SalesOrderOperationalPric...

In my example I’m using the JSON body ( ParentObjectID is the Sales Order Object ID )
{		
"ParentObjectID": "00163E7306A31EE9A9F22559D802809B",
"TypeCode": "7PRB",
"DecimalValue": "10",
"CurrencyCode": "USD"
}

 

As result ByD returns the following OData response body:



 

As you can see the Restocking Fee is created with relevant information.



 

Note: for Update and Delete of Restocking Fee please follow same steps as mentioned above in step 2 and step 3 of Overall Discount.


Create Update and Delete Surcharge using the Custom OData Service


User can create document level Surcharge in Total Pricing of Pricing and Invoicing tab of Sales Order using the OData service by following the steps mentioned below.



 

Step 1: Create Surcharge

Using the http-method POST and entity set SalesOrderOperationalPriceComponent you can create Surcharge, and make sure you pass the values for following elements ParentObjectID, TypeCode, DecimalValue and CurrencyCode:

https://{{TenantHostname}}/sap/byd/odata/cust/v1/salesorderpricecomponents/SalesOrderOperationalPric...

In my example I’m using the JSON body ( ParentObjectID is the Sales Order Object ID )
{		
"ParentObjectID": "00163E7306A31EE9ADE807199DB301F6",
"TypeCode": "0001",
"DecimalValue": "10",
"CurrencyCode": "USD"
}

 

As result ByD returns the following OData response body:



 

As you can see the Restocking Fee is created with relevant information.



 

Note: for Update and Delete of header level Surcharge please follow same steps as mentioned above in step 2 and step 3 of Overall Discount.

 

Note: you can create Five different Surcharge at sales order header level (in case you have scoped "Additional Surcharge" in business configuration )

you can create additional surcharges by passing the following TypeCode 0002, 0003, 0004 and 0005 in the OData request.









 

Item Level Price Components


The sales order document has pricing in set to Net or Gross pricing procedure, both options with samples are explained in detail.

User can create read update delete  item level price components using the following Type Codes for both Net pricing and Gross pricing procedure, following are the list of type codes you can use to handle different price components.

List of Item level price components in Net Pricing Procedure are listed below.







































 
          Price Component    Type Code
          Product Discount       7PR6
          List Price       7PR1
         Surcharge       7PR3
         Surcharge (%)       7PR2
         Quality Loss Fee       7PRA
         Goodwill (%)       7PRC
         Warranty (%)       7PR9
         Working Condition (%)       7PR7

 

List of Item level price components in Net Pricing Procedure are listed below.































 
          Price Component    Type Code
          Gross Product Discount       8PR6
          Gross List Price       8PR1
          Gross Surcharge       8PR3
          Gross Surcharge (%)       8PR2
          Gross Quality Loss Fee       8PRA
          Gross Working Condition (%)       8PR7


Create Update and Delete Product Discount using the Custom OData Service


In the custom OData service select the item level price component relevant fields in co-relation with UI fields of Product Discount in Item Pricing of Pricing and Invoicing tab of Sales Order.





 

Step 1: Create Product Discount

Using the http-method POST and entity set SalesOrderOperationalItemPriceComponentCollection you can create Product Discount, make sure you pass the values for following elements ParentObjectID, TypeCode, DecimalValue and MeasureUnitCode:

https://{{TenantHostname}}/sap/byd/odata/cust/v1/salesorderpricecomponents/SalesOrderOperationalItem...

In my example I’m using the JSON body ( ParentObjectID is the Sales Order Item Object ID )
{		
"ParentObjectID": "00163E7306A31EE9ADE807199DB321F6",
"TypeCode": "7PR6",
"DecimalValue": "10",
"MeasureUnitCode": "P1"
}

and the http-header parameter

  • x-csrf-token=fetch to get the CSRF-token to create the material via POST service call ( note: the x-csrf-token is fetched in the GET service call , for details refer to postman example collection ).

  • Note: Sales Order ID and Item ID (ObjectID) should be the valid and existing id in system.



As result ByD returns the following OData response body:



 

As you can see the Product Discount is created with relevant information.



     

Step 2: Update Product Discount

Using the http-method PUT and entity set SalesOrderOperationalItemPriceComponentCollection you can update the Product Discount, make sure you pass the values for following elements ObjectID, ParentObjectID, TypeCode, DecimalValue and MeasureUnitCode:

https://{{TenantHostname}}/sap/byd/odata/cust/v1/salesorderpricecomponents/SalesOrderOperationalItemPriceComponentCollection('{{SalesOrderItemPriceComponentObjectID}}')

In my example I’m using the JSON body( ParentObjectID is the Sales Order Item Object ID )
{
"ObjectID": "{{SalesOrderItemPriceComponentObjectID}}",
"ParentObjectID": "{{SalesOrderItemPriceComponentParentObjectID}}",
"TypeCode": "7PR6",
"DecimalValue": "30",
"MeasureUnitCode": "P1"
}



 

As result the sales order item product discount gets updated:



 

Step 3: Delete Product Discount

Using the http-method DELETE and entity set SalesOrderOperationalItemPriceComponentCollection you can delete the Product  Discount, make sure you pass the value of the specific instance id of product discount which just got updated.

https://{{TenantHostname}}/sap/byd/odata/cust/v1/salesorderpricecomponents/SalesOrderOperationalItemPriceComponentCollection('{{SalesOrderItemPriceComponentObjectID}}')

to delete an instance JSON body is required, you have to pass only the instance id as shown above.



Note: instance to be deleted can be fetched by performing the GET operation and getting the right instance of the product discount of sales order.

GET before delete is required since after the UPDATE operation the instance id of the product discount is changed.



 

Create Update and Delete Price using the Custom OData Service


User can create item Price in Item Pricing of Pricing and Invoicing tab of Sales Order using the OData service by following the steps mentioned below.



 

Step 1: Create Price

Using the http-method POST and entity set SalesOrderOperationalItemPriceComponentCollection you can create item Price, and make sure you pass the values for following elements ParentObjectID, TypeCode, DecimalValue and CurrencyCode:

https://{{TenantHostname}}/sap/byd/odata/cust/v1/salesorderpricecomponents/SalesOrderOperationalItem...

In my example I’m using the JSON body ( ParentObjectID is the Sales Order Item Object ID )
{		
"ParentObjectID": "{{SalesOrderItemPriceComponentParentObjectID}}",
"TypeCode": "7PR1",
"DecimalValue": "100",
"CurrencyCode": "USD"
}

 

As result ByD returns the following OData response body:



 

As you can see the document level Freight is created with relevant information.



 

Note: for Update and Delete of Item Price please follow same steps as mentioned above in step 2 and step 3 of Product Discount.

Note: Price is determined from price master data by the system during creation of Item in Sales Order .

  • Use Case 1: Item Price is determined by system and price is overwritten by the OData service after the above price odata create call.

  • Use Case 2: Item Price is not determined by system and price is created by the OData service after the above price odata create call.



Create Update and Delete Item Surcharge using the Custom OData Service


User can create item level Surcharge in Item Pricing of Pricing and Invoicing tab of Sales Order using the OData service by following the steps mentioned below.



 

Step 1: Create Item Surcharge (absolute value surcharge)

Using the http-method POST and entity set SalesOrderOperationalItemPriceComponentCollection you can create item Surcharge, and make sure you pass the values for following elements ParentObjectID, TypeCode, DecimalValue and CurrencyCode:

https://{{TenantHostname}}/sap/byd/odata/cust/v1/salesorderpricecomponents/SalesOrderOperationalItem...

In my example I’m using the JSON body ( ParentObjectID is the Sales Order Item Object ID )
{		
"ParentObjectID": "{{SalesOrderItemPriceComponentParentObjectID}}",
"TypeCode": "7PR3",
"DecimalValue": "10",
"CurrencyCode": "USD"
}

 

As result ByD returns the following OData response body:



 

As you can see the document level Freight is created with relevant information.



 

Note: for Update and Delete of Item Surcharge please follow same steps as mentioned above in step 2 and step 3 of Product Discount.

 

Create Update and Delete Item Surcharge(%) using the Custom OData Service


User can create item level Surcharge (%) in Item Pricing of Pricing and Invoicing tab of Sales Order using the OData service by following the steps mentioned below.



 

Step 1: Create Item Surcharge(%) percentage

Using the http-method POST and entity set SalesOrderOperationalItemPriceComponentCollection you can create item Surcharge(%), and make sure you pass the values for following elements ParentObjectID, TypeCode, DecimalValue and MeasureUnitCode:

https://{{TenantHostname}}/sap/byd/odata/cust/v1/salesorderpricecomponents/SalesOrderOperationalItem...

In my example I’m using the JSON body ( ParentObjectID is the Sales Order Item Object ID )
{		
"ParentObjectID": "{{SalesOrderItemPriceComponentParentObjectID}}",
"TypeCode": "7PR2",
"DecimalValue": "10",
"MeasureUnitCode": "P1"
}

 

As result ByD returns the following OData response body:



 

As you can see the document level Surcharge(%) is created with relevant information.



 

Note: for Update and Delete of Item Surcharge(%) please follow same steps as mentioned above in step 2 and step 3 of Product Discount.

 

Create Update and Delete Item Quality Loss Fee using the Custom OData Service


User can create item level Quality Loss Fee in Item Pricing of Pricing and Invoicing tab of Sales Order using the OData service by following the steps mentioned below.



 

Step 1: Create Item Quality Loss Fee

Using the http-method POST and entity set SalesOrderOperationalItemPriceComponentCollection you can create item Quality Loss Fee, and make sure you pass the values for following elements ParentObjectID, TypeCode, DecimalValue and CurrencyCode:

https://{{TenantHostname}}/sap/byd/odata/cust/v1/salesorderpricecomponents/SalesOrderOperationalItem...

In my example I’m using the JSON body ( ParentObjectID is the Sales Order Item Object ID )
{		
"ParentObjectID": "{{SalesOrderItemPriceComponentParentObjectID}}",
"TypeCode": "7PRA",
"DecimalValue": "10",
"CurrencyCode": "USD"
}

 

As result ByD returns the following OData response body:



 

As you can see the document level Quality Loss Fee is created with relevant information.



 

Note: for Update and Delete of Item Quality Loss Fee please follow same steps as mentioned above in step 2 and step 3 of Product Discount.


Create Update and Delete Item Goodwill (%) using the Custom OData Service


User can create item level Goodwill (%) in Item Pricing of Pricing and Invoicing tab of Sales Order using the OData service by following the steps mentioned below.



 

Step 1: Create Item Goodwill (%) percentage

Using the http-method POST and entity set SalesOrderOperationalItemPriceComponentCollection you can create item Goodwill (%), and make sure you pass the values for following elements ParentObjectID, TypeCode, DecimalValue and MeasureUnitCode:

https://{{TenantHostname}}/sap/byd/odata/cust/v1/salesorderpricecomponents/SalesOrderOperationalItem...

In my example I’m using the JSON body ( ParentObjectID is the Sales Order Item Object ID )
{		
"ParentObjectID": "{{SalesOrderItemPriceComponentParentObjectID}}",
"TypeCode": "7PRC",
"DecimalValue": "10",
"MeasureUnitCode": "P1"
}

 

As result ByD returns the following OData response body:



 

As you can see the document level Goodwill(%) is created with relevant information.



 

Note: for Update and Delete of Item Goodwill(%) please follow same steps as mentioned above in step 2 and step 3 of Product Discount.

 

Create Update and Delete Item Warranty(%) using the Custom OData Service


User can create item level Warranty (%) in Item Pricing of Pricing and Invoicing tab of Sales Order using the OData service by following the steps mentioned below.



 

Step 1: Create Item Warranty (%) percentage

Using the http-method POST and entity set SalesOrderOperationalItemPriceComponentCollection you can create item Warranyty(%), and make sure you pass the values for following elements ParentObjectID, TypeCode, DecimalValue and MeasureUnitCode:

https://{{TenantHostname}}/sap/byd/odata/cust/v1/salesorderpricecomponents/SalesOrderOperationalItem...

In my example I’m using the JSON body ( ParentObjectID is the Sales Order Item Object ID )
{		
"ParentObjectID": "{{SalesOrderItemPriceComponentParentObjectID}}",
"TypeCode": "7PR9",
"DecimalValue": "10",
"MeasureUnitCode": "P1"
}

 

As result ByD returns the following OData response body:



 

As you can see the document level Warranty(%) is created with relevant information.



 

Note: for Update and Delete of Item Warranty(%) please follow same steps as mentioned above in step 2 and step 3 of Product Discount.

 

Create Update and Delete Item Working Condition(%) using the Custom OData Service


User can create item level Working Condition(%) in Item Pricing of Pricing and Invoicing tab of Sales Order using the OData service by following the steps mentioned below.



 

Step 1: Create Item Working Condition (%) percentage

Using the http-method POST and entity set SalesOrderOperationalItemPriceComponentCollection you can create item Working Condition (%), and make sure you pass the values for following elements ParentObjectID, TypeCode, DecimalValue and MeasureUnitCode:

https://{{TenantHostname}}/sap/byd/odata/cust/v1/salesorderpricecomponents/SalesOrderOperationalItem...

In my example I’m using the JSON body ( ParentObjectID is the Sales Order Item Object ID )
{		
"ParentObjectID": "{{SalesOrderItemPriceComponentParentObjectID}}",
"TypeCode": "7PR7",
"DecimalValue": "10",
"MeasureUnitCode": "P1"
}

 

As result ByD returns the following OData response body:



 

As you can see the document level Working Condition (%) is created with relevant information.



 

Note: for Update and Delete of Item Working Condition (%) please follow same steps as mentioned above in step 2 and step 3 of Product Discount.

Note: to Create Read Update and Delete price components in a sales order with Gross Pricing Procedure please use the Type Codes mentioned in a table in the beginning of the blog and follow the similar steps mentioned above.
6 Comments