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: 
Qi_Liu
Product and Topic Expert
Product and Topic Expert
本篇是在采购:中国含税采购价的基础上详细介绍第三个方案,即定制化条件类型来实现采购含税价自动计算净价的方案。希望能给大家快速实施带来帮助。

1. 新建条件类型Z000


SSCUI 101094 Set condition types for pricing in purchasing



2. 设置为负值的百分比折扣


双击刚刚创建的Z000条目,进入如下配置界面。选择X表示负值条件类型。两个AA代表百分数,以及附加计算类型。

后面步骤创建了新的定价程序,别忘了再回来把新的定价程序Z10001更新上去


其实不设置成负的也可以,改变相应的增强代码就行。文章最后给大家演示正值的代码。

3. 复制标准创建新的定价过程条目Z10001


SSCUI 101095 Set the calculation schema for purchasing



4. 把新的条件类型加入到定价过程Z10001步骤中



去掉手动的勾,就会自动出现在采购订单上。否则需要再采购订单上手工输入条件类型。

5.分配定价过程给采购组织


SSCUI 102144 Determine Calculation Schema for Standard Purchase Orders *


此时在没有增强badi的时候我们可以看看效果:11块总价, 10%税率(负数), 净价为11-11*0.1=9.9



6.增强实施


APP: 自定义字段和逻辑

6.1 搜增强PRCG_DOC_ITEM_CONDITION_AMOUNT


如果没有人创建过,点创建



6.2 在新建界面中选中再次搜索,点步骤2




6.3添加过滤值


随便一个数值例如1320.

这个过滤值1320 会在后面配置步骤‘将增强标识分配到例程编号’的时候被F4搜索出来。



6.4 点审核




6.5 点创建




6.6点发布


点发布之后,才能打开代码编辑器写代码



6.7 打开代码编辑器点编辑


粘贴如下代码:
* Mandatory step for all implementations:
* Move the importing parameters to the changing parameters.
MOVE-CORRESPONDING item_amounts TO item_result_amounts.
MOVE-CORRESPONDING item_attributes TO item_result_attributes.
MOVE-CORRESPONDING item_quantities TO item_result_quantities.
MOVE-CORRESPONDING prcg_element_attributes TO prcg_element_result_amounts.

* General remark:
* The enhancement ID that you assign to a routine number must correspond to the BAdI filter of the current implementation.
* In the configuratin of a pricing procedure, you assign the routine number to a condition type or to a subtotal line.

* In the following, an example implementation of a condition amount routine for the condition item is presented.
* Such type of routine can be used to change the value for a pricing element.

* The example implementation below sets the condition amount equal to the net amount plus the tax amount.
* When the routine number is assigned to a subtotal line at the end of the pricing procedure, it shows the final value of the line item.

TRY.
prcg_element_result_amounts-CONDITIONAMOUNT = prcg_element_result_amounts-CONDITIONBASEVALUE – prcg_element_result_amounts-CONDITIONBASEVALUE / ( 1 + ABS( prcg_element_result_amounts-CONDITIONRATEVALUE / 100 ) ).

prcg_element_result_amounts-CONDITIONAMOUNT = – prcg_element_result_amounts-CONDITIONAMOUNT.

IF prcg_element_result_amounts-conditionamount = 0.
* it is possible to raise a message if an issue is identified
pricing_message = ‘Check the condition amount of the condition XY01’.
* indicate a pricing error if required
item_result_attributes-pricinghaserror = abap_true.
ENDIF.
CATCH cx_sy_conversion_error cx_sy_arithmetic_error INTO DATA(lx_conversion).

prcg_element_result_amounts-conditioninactivereason = ‘X’.
prcg_element_result_amounts-conditionamount = 0.
* You should use the statement “RAISE EXCEPTION” only for critical business errors or programming runtime errors.
RAISE EXCEPTION TYPE cx_ble_runtime_error
EXPORTING
previous = lx_conversion.

* Remark: Alternative exception handling
* TRY.
* RAISE EXCEPTION TYPE cx_pricing_formula EXPORTING error_message = ‘Conversion Error’ ##NO_TEXT .
* CATCH cx_pricing_formula INTO DATA(lx_pricing_formula).
* RAISE EXCEPTION TYPE cx_ble_runtime_error
* EXPORTING
* previous = lx_pricing_formula.
* ENDTRY.

ENDTRY.

 

计算逻辑详解


语法ABS()就是正负号互换的意思。

输出:

CONDITIONAMOUNT 就是我们想要求的Z000对应的税额(taxamount) -1 CNY

输入:

CONDITIONBASEVALUE 就是我们手工输入的PMP0总价(grossamount) 11CNY

CONDITIONRATEVALUE 就是我们手工输入的Z000的税率(taxrate)  -10

所以英文公式:

taxamount = grossamount - netamount = grossamount - grossamount/(1+taxrate)

翻译成中文公式:

税额          =  总价  -  净价     =  总价 - 总价/ (1+税率)

翻译成代码公式:

CONDITIONAMOUNT = CONDITIONBASEVALUE - CONDITIONBASEVALUE/ (1+ ABS(CONDITIONRATEVALUE))

注意这里算出来的CONDITIONAMOUNT是个正的税额。要想在计算过程中减去它。还要加一句代码把它变成负的

CONDITIONAMOUNT = -CONDITIONAMOUNT

 

7. 新建3开头的7位数例程编号以及历程描述


Eg 3000067

SSCUI 102430 Set Alternative Calculation of Condition Amount



8. 将增强标识分配到例程编号


 


增强表示符可以从F4中选步骤6.3设置的过滤值



9. 增强实施“定义凭证中条件金额的备选计算”


重复步骤6,搜增强PRCG_DOC_CONDITION_AMOUNT

点击发布之后,代码可以编辑一下,什么也不用写,保存发布。这一步必须要做,因为这一步不做,步骤六的增强就不起作用。


现在来看看效果,11块的总价,10%的税率自动决定出来的净价为10块。



彩蛋环节


如果不想设置Z000条件类型成负值,我们可以设置成正值,搭配以下增强实施代码,也可以实现同样的净价结果。
MOVE-CORRESPONDING item_amounts TO item_result_amounts.
MOVE-CORRESPONDING item_attributes TO item_result_attributes.
MOVE-CORRESPONDING item_quantities TO item_result_quantities.
MOVE-CORRESPONDING prcg_element_attributes TO prcg_element_result_amounts.

prcg_element_result_amounts-CONDITIONAMOUNT = prcg_element_result_amounts-CONDITIONBASEVALUE * prcg_element_result_amounts-CONDITIONRATEVALUE / 100 / ( 1 + prcg_element_result_amounts-CONDITIONRATEVALUE / 100 ).
prcg_element_result_amounts-CONDITIONAMOUNT = - prcg_element_result_amounts-CONDITIONAMOUNT.

效果如图:

100块的总价,13%的税率自动决定出来的净价为88.5块。


欢迎各位测试,如果有尾差的问题,反应给我,简单调优一下。

 

本文涉及功能基于SAP S/4HANA Cloud, Public Edition 2308版本,后续版本可能会有变化请参考最新信息。
The features covered in this article are based on SAP S/4HANA Cloud, Public Edition 2308, please refer to the latest information for changes in subsequent versions.

Hope you LIKE it if it addresses your issue. After that, please feel free to comment and I will follow up.
如果有帮助到您欢迎点Like,有问题可以评论继续探讨。

更多链接

SAP S/4HANA Cloud for Sourcing and Procurement, Public Edition
https://community.sap.com/topics/s4hana-cloud-sourcing-procurement

SAP S/4HANA Cloud for Supply Chain, Public Edition
https://community.sap.com/topics/s4hana-cloud-supply-chain

SAP S/4HANA Cloud for Manufacturing, Public Edition
https://community.sap.com/topics/s4hana-cloud-manufacturing
2 Comments