CRM Service, SAP CRM

OData Example: Create Update Delete Price Components of Service Order in SAP Business ByDesign

SAP Business ByDesign (ByD) provides you with REST/OData access to Service 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 service 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 service order using SAP Business ByDesign Custom OData Services.

Also Read: SAP CRM Certification Preparation Guide

Sample service order header level price components include:

  • Overall Discount
  • Freight
  • Restocking Fee
  • Surcharge

Sample service order item level price components include:

  • Product Discount
  • Price
  • Surcharge (Fixed Value)
  • Surcharge (%)
  • Quality Loss Fee
  • Goodwill (%)
  • Warranty (%)
  • Working Condition (%)

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

Expose ByD Service 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 Service 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,ServiceOrderPriceAndTaxCalculation, ServiceOrderOperationalPriceComponent, ServiceOrderItem, ServiceOrderOperationalItemPriceComponent. In my example I included the following elements to my Custom OData Service “serviceorderpricecomponents“:

  • ID
  • ServiceOrderPriceAndTaxCalculation (header level price components)
  • ServiceOrderOperationalPriceComponent
    • TypeCode
    • DecimalValue
    • CurrencyCode
    • BaseMeasureUnitCode
    • BaseDecimalValue
    • MeasureUnitCode
    • RateBaseQuantityTypeCode
  • ServiceOrderItem (created from the Item association from ServiceOrderPriceAndTaxCalculation )
  • ServiceOrderOperationalItemPriceComponent (created from the OperationalItemPriceComponent association from ServiceOrderItem )
    • 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/serviceorderpricecomponents

If needed you can retrieve the metadata using the metadata URL

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

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

Document Level Price Components

The service 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  0007
Freight  7PR8 
Restocking Fee  7PRB
Surcharge  0001 
Surcharge 2 0002 
Surcharge 3 0003 
Surcharge 4 0004 
Surcharge 5 0005 

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

Price Component Type Code 
Gross Overall Discount 1007
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 Service Order.

Step 1: Create Overall Discount

Using the http-method POST and entity set ServiceOrderOperationalPriceComponent 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/serviceorderpricecomponents/ServiceOrderOperationalPriceComponentCollection

In my example I’m using the JSON body ( the ParentObjectID is the Service Order Object ID)

{		
                "ParentObjectID": "00163E7306A31EE9AE81BA7D941D2543",
                "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: Service 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 ServiceOrderOperationalPriceComponentCollection 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/serviceorderpricecomponents/ServiceOrderOperationalPriceComponentCollection(‘{{ServiceOrderPriceComponentObjectID}}’)

In my example I’m using the JSON body ( the ParentObjectID is the Service Order Object ID)

{
            "ObjectID": "{{ServiceOrderPriceComponentObjectID}}",
            "ParentObjectID": "{{ServiceOrderPriceComponentParentObjectID}}",
                "TypeCode": "0007",
                "DecimalValue": "30",
                "MeasureUnitCode": "P1"
}

As result the service order overall discount gets updated:

Step 3: Delete Overall Discount

Using the http-method DELETE and entity set ServiceOrderOperationalPriceComponentCollection 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/serviceorderpricecomponents/ServiceOrderOperationalPriceComponentCollection(‘00163E7306A31EE9AE81BA7D941D254300163E7306A31EE9AE81EA354CD346AC’)

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 overall all discount of service 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 Service Order using the OData service by following the steps mentioned below.

Step 1: Create Freight

Using the http-method POST and entity set ServiceOrderOperationalPriceComponent 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/serviceorderpricecomponents/ServiceOrderOperationalPriceComponentCollection

In my example I’m using the JSON body ( the ParentObjectID is the Service Order Object ID)

{		
                "ParentObjectID": "00163E7306A31EE9AE81BA7D941D2543",
                "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 Service Order using the OData service by following the steps mentioned below.

Step 1: Create Restocking Fee

Using the http-method POST and entity set ServiceOrderOperationalPriceComponent 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/serviceorderpricecomponents/ServiceOrderOperationalPriceComponentCollection

In my example I’m using the JSON body ( the ParentObjectID is the Service Order Object ID)

{		
                "ParentObjectID": "00163E7306A31EE9AE81BA7D941D2543",
                "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 Service Order using the OData service by following the steps mentioned below.

Step 1: Create Surcharge

Using the http-method POST and entity set ServiceOrderOperationalPriceComponent 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/serviceorderpricecomponents/ServiceOrderOperationalPriceComponentCollection

In my example I’m using the JSON body ( the ParentObjectID is the Service Order Object ID)

{		
                "ParentObjectID": "00163E7306A31EE9AE81BA7D941D2543",
                "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 service 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.

Additional Surcharges in Service Order UI

Item Level Price Components

The service 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 Gross 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 Service Order.

lete 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 Service Order.

Step 1: Create Product Discount

Using the http-method POST and entity set ServiceOrderOperationalItemPriceComponentCollection 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/serviceorderpricecomponents/ServiceOrderOperationalItemPriceComponentCollection

In my example I’m using the JSON body ( ParentObjectID is the Item Object ID )

{		
                "ParentObjectID": "00163E7306A31EE9AE81BB68D5C9859E",
                "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: Service 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 ServiceOrderOperationalItemPriceComponentCollection 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/serviceorderpricecomponents/ServiceOrderOperationalItemPriceComponentCollection(‘{{ServiceOrderItemPriceComponentObjectID}}’)

In my example I’m using the JSON body ( ParentObjectID is the Item Object ID )

{
            "ObjectID": "{{ServiceOrderItemPriceComponentObjectID}}",
            "ParentObjectID": "{{ServiceOrderItemPriceComponentParentObjectID}}",
                "TypeCode": "7PR6",
                "DecimalValue": "30",
                "MeasureUnitCode": "P1"
}

As result the service order item product discount gets updated:

Step 3: Delete Product Discount

Using the http-method DELETE and entity set ServiceOrderOperationalItemPriceComponentCollection 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/serviceorderpricecomponents/ServiceOrderOperationalItemPriceComponentCollection(‘{{ServiceOrderItemPriceComponentObjectID}}’)

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 service 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 Service Order using the OData service by following the steps mentioned below.

Step 1: Create Price

Using the http-method POST and entity set ServiceOrderOperationalItemPriceComponentCollection 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/serviceorderpricecomponents/ServiceOrderOperationalItemPriceComponentCollection

In my example I’m using the JSON body ( ParentObjectID is the Item Object ID )

{		
                "ParentObjectID": "{{ServiceOrderItemPriceComponentParentObjectID}}",
                "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 Service 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 Service 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 ServiceOrderOperationalItemPriceComponentCollection 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/serviceorderpricecomponents/ServiceOrderOperationalItemPriceComponentCollection

In my example I’m using the JSON body ( ParentObjectID is the Item Object ID )

{		
                "ParentObjectID": "{{ServiceOrderItemPriceComponentParentObjectID}}",
                "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 Service 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 ServiceOrderOperationalItemPriceComponentCollection 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/serviceorderpricecomponents/ServiceOrderOperationalItemPriceComponentCollection

In my example I’m using the JSON body ( ParentObjectID is the Item Object ID )

{		
                "ParentObjectID": "{{ServiceOrderItemPriceComponentParentObjectID}}",
                "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 ServiceOrder 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 ServiceOrderOperationalItemPriceComponentCollection 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/serviceorderpricecomponents/ServiceOrderOperationalItemPriceComponentCollection

In my example I’m using the JSON body ( ParentObjectID is the Item Object ID )

{		
                "ParentObjectID": "{{ServiceOrderItemPriceComponentParentObjectID}}",
                "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 Service 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 ServiceOrderOperationalItemPriceComponentCollection 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/serviceorderpricecomponents/ServiceOrderOperationalItemPriceComponentCollection

In my example I’m using the JSON body ( ParentObjectID is the Item Object ID )

{		
                "ParentObjectID": "{{ServiceOrderItemPriceComponentParentObjectID}}",
                "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 Service 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 ServiceOrderOperationalItemPriceComponentCollection 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/serviceorderpricecomponents/ServiceOrderOperationalItemPriceComponentCollection

In my example I’m using the JSON body ( ParentObjectID is the Item Object ID )

{		
                "ParentObjectID": "{{ServiceOrderItemPriceComponentParentObjectID}}",
                "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 Service 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 ServiceOrderOperationalItemPriceComponentCollection 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/serviceorderpricecomponents/ServiceOrderOperationalItemPriceComponentCollection

In my example I’m using the JSON body ( ParentObjectID is the Item Object ID )

{		
                "ParentObjectID": "{{ServiceOrderItemPriceComponentParentObjectID}}",
                "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 service 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.

Leave a Reply

Your email address will not be published. Required fields are marked *