How to Get Accurate Pricing in SD for Customer and Material?

Pricing in SAP

Custom Function Module to retrieve accurate Pricing in SD for Customer and Material.

Of late, we have been focussing on HANA, UI5, Fiori and all the related new jargons. But in reality, a major percentage of clients are still in the classical database and they still have simple requirements of getting the right data. They might complain a little about performance or/and look and feel of their current ERP, but at the end of the day, they cannot be pissed off more than with the wrong report, output or data. So still today, our age old clients have the same age old secret desire to play with correct data only. 🙂 

There are many situations where we need to find out the correct price of an Item(i.e. Material) for a Customer. The below custom Function Module, which we created, can be used as an API or as a utility FM to get the pricing details of a material; and can be called from any report program or enhancement as per the requirement.

The beauty here is, this FM takes only few information like the customer, material, and sales area details as input, but during the process of retrieval of pricing, we need much more information for which we have to fetch data from more than 20 tables, which is handled systematically inside this FM. Our idea is not to teach you how to create a custom FM, but to provide you a ready reference, in case you have a similar requirement in Pricing. Believe us, Pricing is a must in every SAP Project.

Even if you might not need this FM exactly, but we are positive, you would need many of the tables and standard function modules while working in some customization and in those instances, this article might help as a use case scenario for those tables and FMs.

Scope of the development

  • Create a Function Module with the import and table parameters (shown below).
  • Inside the FM use the detailed logic given below to fill the communication structure (Header structure KOMK and Item structure KOMP) which is very much important to get the accurate pricing from the FM PRICING.
  • Call the standard FM ‘PRICING’ with the proper input. In the table parameter TKOMV of the FM PRICING, we can get all the condition type and their values
  • After getting the output from the FM PRICING then prepare the output table for the custom FM to display them in the output.

Import parameter:

SAP ABAP Training

Table parameter:


MM Pricing

Also Read: PO re-Price issue in BAPI_PO_CHANGE

Detailed Logic for the Function Module

  • Create one Function Module with the above Import and Table parameters.
  • Write the below logic inside the function module.

Call FM ‘PRICING_REFRESH’ to refresh the previous pricing if exist.

Fill the Communication structure (Header structure KOMK and Item structure KOMP) which is very much important to get the accurate pricing from the FM PRICING.

Fill the Header Communication structure KOMK

Select all the fields from tables KNVV, MARA, MVKE and KNA1 and pass to the corresponding field of the header communication structure.

Select Pricing procedure

Move the required fields from KNVV to the header structure

Move the required fields from KNA1 to the header structure

Select the region from table T001W

Pass customer from Import parameter

Get the Head office A/C number from KNB1 table

Also Check: Do all ABAPers know Fixed Point Arithmetic?

Get the Customer hierarchy Number

If the customer is supposed to receive retail pricing, check condition ZS22 to see if C2, CC and/or RX items should also be Retail Priced.

* Check to see if the Zero Percent Flag should not apply to this customer Check the Sold-to.

Fill the Item Communication structure KOMP

Move the corresponding field of MVKE and MARA to the item communication structure.

* Get the Default item category for the document

* Clear active price methods, net indicator, program and super net each time those are moved during MOVE CORRESPONDING.

* Finally pass the Communication structure to call the Standard FM PRICING and get the accurate Pricing Values

After execution of the standard FM PRICING.

PRICING Function Module

All the condition type and their corresponding values will be populated in the table parameter of the PRICING FM.

FM Pricing

Output from standard Order

VA01 Sales Order

Sample output of the FM after execution.

Enhance Pricing

The output which is prepared from the table parameter TKOMV of the standard FM PRICING.

Do not miss this: Ready Reckoner for SAP Developers. SD, MM, FI flow and tables for ABAPers.

Function Modules and Tables to Remember that are used in this Z function Module

Function Modules:

  1. ‘PRICING_REFRESH’ called before calling the FM ‘PRICING’ to refresh the Pricing values if anything exists.
  2. KNVV_SINGLE_READ  to get the Customer Master Sales Data
  3. MARA_SINGLE_READ  to get the Material master data
  4. MVKE_SINGLE_READ to get the Sales Data for Material
  5. RV_VBAP_PSTYV_DETERMINE to get the item category
  6. SD_CUSTOMER_HIERARCHY_PATH to get the customer hierarchy
  7. PRICING to get the customer and material Pricing
  8. SD_CONDTAB_SELECT to get the start date and end date of the condition record number to populate in the output.

Table used to get the Accurate Pricing of Customer and material:


Point to remember

Either we have to populate all the fields of the communication structure (Header and Item) manually that are populated in the standard USER Exits or some how we have to call the below USER Exits to get the accurate pricing of the Customer and material.


We know you do not want to see 100 of lines of codes on our blog. But being a technical blog, sometimes we take the liberty to flood you with ABAP codes and syntax. 🙂 . Please bear with us. This FM is an outcome of a request from a genuine reader. Since one of our readers was getting benefitted offline, therefore we thought of publishing it so that, few other ABAPers in need might get some lead and help at the time of distress.

The custom FM might look simple and straight forward, but while trying to figure out the logic and build them, it took quite some time for us. Hope, you would not have to spend that many hours if you have a similar requirement.

So…What Do You Think?

Now we want to hear from you.

Do you think, this article explaining some custom logic for Pricing in helpful?

Whether you feel it is helpful or not, in either case, please leave a quick comment below.

Are you Fiori Ready? Check this end to end Fiori Implementation.



    • Thanks Richard for your input on this.

      But some cases it is required only to determine the pricing of an Item/Material without creating a Sales Order. In that case we need to call the standard FM PRICING to get the pricing information.

      The above mentioned process and code reference will help us to smoothly fill all required information in both (KOMK and KOMP) communication structures for calling the Function Module PRICING.

      • BAPI_SALESORDER_SIMULATE -> doesnt create anything, it simulates a sales order to use scales groups and sales org dist channel to SIMULATE actual behavior without exeuting it -> my main concern with your code is that its not supported by SAP (direct sql and function module references). BAPI’s obviously are supported and will work moving forward regardless of patching or upgrades ( at least expected too). Especially in a world where S4 migrations are common place direct SQL calls and (SAP internal function module calls to lesser extent) should be avoided. Just my opinion.

        Thanks for taking the time to reply.


Please enter your comment!
Please enter your name here