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.
Showing results for 
Search instead for 
Did you mean: 

Control Low Margin Sales using Workflow

This blog provides the steps that can be used to control the Low Margin Sales Orders. This will help business improve the sales profitability. This configuration & setting verifies the margin {100 * (net price – cost price) / net price} of a sales order. In the event where a margin falls below the chosen threshold, an approval workflow will be triggered for the approvers to analyze and make decision whether to approve or reject the sales order.


  • The threshold has been hard coded in the extensibility logic

  • This document is a suggestion and should be adapted to your own logic / scenario

  • We suggest that you make use of a Custom Business Object to hold your business rules (eg: if Sales Org X, then margin is 20%, if Sales Org Y then margin 30%) to make this extensibility more flexible and let the users maintain the business rules (not code in a program)

If you are looking to control margin at the sales order item level please check the blog written by my colleague pascal_renet in which he leverages alternate price determination functionality to check the margin and throw an error message if the margin is too low.

Setup Standard Sales Order Workflow

Configuring Document Approvals

  • Go to the App "Manage Your Solution"

  • Select 'Configure Your Solution'

  • Search for 'Document Approvals'

Configure Document Approvals

  • Under Configuration Steps select Configure for 'Define Reasons for Approval Requests' (SSCUI ID 102751) – Required reasons can be defined

Define Reasons for Approval Requests

  • Under Configuration Steps select Configure for 'Assign Reasons for Approval Requests' (SSCUI ID 102752) – Assign defined reasons to relevant document category

Assign Reasons for Approval Requests

Setup Custom Logic

  • Go to the App "Custom Logic" ensure you are in tab 'Custom Logic'

  • Create a New Enhancement Implementation by selecting '+' and subsequently selecting Business Context as 'Sales: Sales Document', BAdI Description as 'Set Approval Request Reasons for Sales Documents', enter the required description and select 'Create'

Enhancement Implementation

  • Example code provides some inspiration to set up the workflow on the basis of Sales Organization, Customer Classification and Terms of Payment. Let's look at example of Sales Order

if salesdocument-sddocumentcategory = 'C'  and salesdocument-salesdocumenttype = 'TA'  and salesdocument-salesorganization = '1010'.
salesdocapprovalreason = 'ZOR1'.

  • This draft can be saved using 'Save Draft' and subsequently can be published with 'Publish'

Set Up Approval Workflow

  • Go to the App "Manage Sales Document Workflows"

  • Select dropdown 'Workflow for Sales Orders'. If you use Sales Orders without Charge, similar setup would be required for 'Workflow for Sales Orders without Charge' and the sample code would require changes to include Sales Document Category 'I'

Sales Order Workflow

  • Create new workflow by selecting 'Create'

  • Define the 'Workflow Name', 'Description' and 'Validity Dates' if required

Workflow Setup

  • There are several options to define precondition, we are selecting here the 'Approval request reason of sales order is' and defining value 'ZOR1'

Start Condition(s)

  • Setup steps by selecting 'Create' to define who the approvers will be. Approver can be a 'Role' or an 'User' – select the approver required

  • Setup exception handling which will be used when Sales Order Approval is Rejected - where Required Action can be setup to suggest 'Rework of Sales Order' and Recipient would be 'Sales Order Request Processor'. Deadlines can be defined if required.

  • Save the workflow and 'Activate'

  • At this stage you have the standard workflow capability configured in your system

Note: The person who creates the sales order cannot approve it

Use Workflow only for Low Margin Sales Orders

Configure the Pricing Procedure

  • Go to the App "Manage Your Solution“

  • Select 'Configure Your Solution'

  • Search for 'Set Pricing Procedure' under Application Areas 'Sales'

Set Pricing Procedure

  • Under Configuration Steps select Configure for 'Set Pricing Procedure' (SSCUI ID 101117) – Select your pricing procedure used and here we will pass the cost price to the subtotal field. In the following example the Subtotal field is passed to 'Carry over value to KOMP-KZWI6'. This needs to be adapted based on your existing pricing configuration

Changing the custom logic

  • Go to the App "Custom Logic" ensure you are in tab 'Custom Logic'

  • Enhance the previous logic by selecting 'Create Draft' to read cost from Subtotal 6. Please note this is a sample logic – you will need to adapt it to your situation

if salesdocument-sddocumentcategory = 'C'  and salesdocument-salesdocumenttype = 'TA'  and salesdocument-salesorganization = '1010'.
data lv_totalcost like salesdocument-totalnetamount.
data lv_margin like salesdocument-yy1_somargin_sdh.

loop at salesdocumentitem into data(wa1_salesdocumentitem).
lv_totalcost = lv_totalcost + wa1_salesdocumentitem-subtotal6amount.

If salesdocument-totalnetamount > 0 and lv_totalcost > 0.
lv_margin = 100 * ( lv_totalcost / salesdocument-totalnetamount ).
if lv_margin < 20.
salesdocapprovalreason = 'ZOR1'.

  • This enhances the logic to set Sales Document Approval Reason only for orders that do not meet 20% margin requirement

  • Draft can now be saved using 'Save Draft' and subsequently can be published with 'Publish'

Usage - Low Margin Approval in Action

If the margin of the sales order falls below the desired margin workflow will be triggered

Low Margin Approval in Action


In closing, I hope you have now learned how to configure workflow for sales orders and control low margin sales orders within SAP S/4HANA Cloud. This will result ensuring prices and discounts are appropriately applied. This also means that you can now have higher profitability for your organization. I would encourage you follow Intelligent Adoption & Consumption community page for more such use cases.

Feel free to leave your feedback or questions in the comment section below.