Background
Sales order approval workflow is an important feature in SAP S/4HANA Cloud Public Edition to control the sales process. It ensures that certain sales orders are reviewed and approved by authorized personnel before they can be processed further. Please refer to SAP Help for more details on how to configure sales order approval workflow.
In standard, approval workflows are triggered based on predefined criteria such as order value, customer group, or sales document type. However, some businesses require more sophisticated approval logic — for example, triggering approval when the profit margin of a sales order falls below a certain threshold.
In this blog, I will explain how to use a Cloud BAdI to implement custom logic to trigger approval workflow when the profit margin percentage is lower than the defined alert line.
Business Example
Supply company XYZ sells various products to customers. The company XYZ has a business policy that any sales order with a profit margin lower than 20% must be reviewed and approved by a sales manager before it can be processed further. This ensures that the company does not sell products at a loss or at an unacceptably low margin.
Since the standard approval workflow does not support profit margin as a trigger condition, company XYZ needs a custom solution to fulfill this requirement.
Solution Overview
The solution consists of the following steps:
- Define a custom pricing procedure with subtotal 6 configured to capture the profit margin amount
- Define a custom approval request reason for low profit margin
- Implement custom logic in Cloud BAdI to check the profit margin and trigger approval
Step 1: Define Pricing Procedure with Profit Margin Subtotal
Define a new pricing procedure and configure subtotal 6 (field KZWI6) to capture the profit margin amount.
Add a new pricing procedure determination based on customer pricing procedure “ZY” to ensure the new pricing procedure is used for the relevant sales process.
Maintain the customer pricing procedure in the customer master data sales area data.
This ensures the pricing procedure is determined if the sales order is created for this customer master data.
Step 2: Define Approval Request Reason
Go to the relevant SSCUI to define a new approval request reason code “ZY02” for low profit margin.
Assign the approval request reason “ZY02” to the sales order document category so that it can be used to trigger the approval workflow.
Save the configurations for approval workflow.
Step 3: Implement Cloud BAdI
The Cloud BAdI SD_APM_SET_APPROVAL_REASON shall be implemented with custom logic to check the profit margin and set the approval request reason.
Implement the following custom logic in the BAdI:
* Check profit margin and assign approval request reason
IF salesdocument-sddocumentcategory = 'C' AND
salesdocument-soldtoparty = '0099900003' AND
salesdocument-salesdocumenttype="TA" AND
salesdocument-sddocumentreason = 'Z01'.
DATA lv_margin_percentage TYPE p LENGTH 8 DECIMALS 2.
LOOP AT salesdocumentitem INTO DATA(ls_item).
"avoid division by zero
IF ls_item-netamount = 0.
CONTINUE.
ENDIF.
lv_margin_percentage = ( ls_item-subtotal6amount / ls_item-netamount ) * 100.
IF lv_margin_percentage < 20. "profit margin is less than 20%
salesdocapprovalreason = 'ZY02'. "low profit margin
RETURN.
ENDIF.
CLEAR lv_margin_percentage.
ENDLOOP.
ENDIF.
The logic checks the profit margin percentage for each sales order item. If any item has a profit margin lower than 20%, the approval request reason ZY02 is set, which triggers the approval workflow.
Business Process Testing
Test Case 1: Sales order with low profit margin
Create a sales order with material TG-D11 with default pricing. The net value is EUR 175.50 and the profit margin amount is EUR -14.50, resulting in a profit margin percentage of -8.26%.
Since the profit margin is lower than 20%, the approval request reason ZY02 is automatically set and the sales order is placed in approval workflow.
Test Case 2: Sales order with high profit margin
Create a sales order with material TG11 with default pricing. The net value is EUR 284.40 and the profit margin amount is EUR 150.20, resulting in a profit margin percentage of 52.81%.
Since the profit margin is higher than 20%, no approval request reason is set and the sales order can be processed without approval.
Conclusion
By combining a custom pricing procedure with a Cloud BAdI implementation, it is possible to trigger sales order approval workflow based on profit margin percentage. This allows companies to enforce business policies that ensure sales orders with low profit margins are reviewed and approved before processing.
This approach demonstrates the power of Cloud BAdIs in SAP S/4HANA Cloud Public Edition to extend standard business processes without modifying the core system. Please feel free to submit your requirements through the Customer Influence Portal to help us prioritize our product roadmap.
Besides, you can also check blog Sales Document BAdI Overview to get to know more use cases of using sales document Cloud BAdIs in SAP S/4HANA Public Cloud.
Status: DRAFT — pending review before publishing



