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

Pricing in SAP
Share on Facebook7Share on LinkedIn64Tweet about this on TwitterShare on Google+0
Please Share!!

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:

SAP HANA

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:

KONH T001W MVKE A935
KNVV MARM KONP A906
MARA T683V A904 TVEP
MARC KNA1 A931 TVEPZ
MEAN KNB1 A918 LFA1

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.

  • USEREXIT_PRICING_PREPARE_TKOMK
  • USEREXIT_PRICING_PREPARE_TKOMP.

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.

 

Share on Facebook7Share on LinkedIn64Tweet about this on TwitterShare on Google+0
Please Share!!

About the Author

Jubaraj Swain
Jubaraj Swain

Jubaraj is a senior SAP Technical Consultant. He is an expert in the Module Pool Programming and one of the best in the industry. He has worked in the niche area of Catalog Management and Vistex.

He is fond of OOPs. He has also made his hands dirty in OData and he has Java and JS knowledge prior joining to SAP ABAP team. 

Find more about Jubaraj Swain at LinkedIn.

3 Comments on "How to Get Accurate Pricing in SD for Customer and Material?"

  1. Richard McArthur | July 18, 2017 at 1:55 am | Reply

    I would just use BAPI_SALESORDER_SIMULATE with the customer and material/article.

    • Jubaraj Swain Jubaraj Swain | July 19, 2017 at 4:25 am | Reply

      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.

      • Richard McArthur | July 19, 2017 at 10:16 pm | Reply

        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.

Leave a Reply to Richard McArthur Cancel reply

Your email address will not be published.


*