Automate Header Pricing Conditions on Sales Orders
Business Scenario: Automate header pricing conditions on sales orders at the header level. Currently SAP doesn’t have the capability to automate header condition types. What we mean by automate is, for example, item condition types, you can set those up with a condition record and when certain criteria is met the record is automatically inserted into the sales order. Transaction VK11/VK12/VK13 allows you to enter in the condition record type and then create/change/display records for different condition types.
Solution: Put some custom code within the sales order user exit MV45AFZZ. There are several places in which custom code can be placed in order to update the sales order header condition type. One place the code can be put is the FORM userexit_save_document_prepare (which is the form that gets executed one time right before the sales document gets saved. Another place and probably the best place to put it is in the FORM userexit_pricing_prepare_tkomk. In our solution we have placed the code in the FORM userexit_pricing_prepare_tkomk. Depending on the way the environment is setup you will either have to create an enhancement or you can just update the code directly. In our example we are updating the code directly. If you need to do an enhancement or would like assistance using other FORMS feel free to ask for pointers.
1. Go to SE38 and enter in MV45AFZZ and click on change. (If it asks you for an object key that means you need to create an enhancement).
2. Go down to the FORM userexit_pricing_prepare_tkomk.
3. In our instance we only wanted to update the header freight condition type on the creation of the sales order. In order to do this you need to start your custom code with an “if” statement that checks to make sure that t180-trtyp = ‘H’. If it does, that means that it’s in creation mode. The snippet of code I’m pasting is in relation to pulling information from a custom table to determine what the condition record should be and update the incoterms and payment terms along with the condition record.
4. Also note in the code that there is a global variable that is set, gv_update_pricing. We had to do this in order for the new pricing to update automatically since the terms were being updated. This code needs to be placed in the FORM userexit_new_pricing_vbkd of user exit MV45AFZB. I’ve put the code, in order to update the pricing automatically, down below also. And again this is only done when creating the sales order.