Wednesday, August 28, 2013

Fast Price Retrieval for SAP CRM

We all know that pricing in SAP is very complex. It’s not easy to retrieve a customer specific net value for a specific material, which includes scales and different discounts and surcharges. This article will explain a solution to quickly retrieve pricing information (<100ms).


Within SAP CRM the IPC (Internet Pricing Configurator) is used to handle all pricing request. (The IPC is a JAVA based solution running in the SAP Virtual Machine Container). The only solution to find the correct price is currently an order simulation. This basically creates a complete order in SAP CRM (including all logic not relevant for pricing) but does not save the order. Main disadvantage of this solution is that this is time consuming.

Therefore SAP has introduced a new Remote Function Call (RFC) SPE_CALCULATE_PRICE. This function call is only available from Support Package SP29 of SAP_AP onwards. This is Java Function Module that can be called via SAP Java Connector (SAP JCo). It allows executing pricing (price determination and price calculation) with only one call.

This function module will just call the IPC directly, to retrieve the price for one or multiple products. In our test lab the order simulation took more than 1000 ms (milli seconds) and the pricing call did the same job in just 100 ms.  Because this is a low level function module, you have to provide all needed details for calculating the price yourself. For example you have to specify the sales organization, customer GUID (not the number), product GUID (not the number) , the pricing procedure, the currency etc.

This article will clarify how to use this new Remote Function Call

All information in black is mandatory, information in orange is optional and information in red is not needed.

FUNCTION SPE_CALCULATE_PRICE.
*’----------------------------------------------------------------------
*’*’Local Interface:
*’ IMPORTING
*’    VALUE(IS_HEADER_INPUT) TYPE PRIT_HEADER_INPUT
*’    VALUE(IT_ITEM_ADDNL_INPUT) TYPE PRIT_ITEM_ADDNL_INPUT_T

*’ EXPORTING
*’    VALUE(ES_HEADER_RESULT) TYPE PRIT_HEAD_RET
*’    VALUE(ET_ITEM_CALC_ADDNL_RESULT) TYPE PRIT_ITEM_ADDNL_RESULT_T
*’    VALUE(ET_TRACE) TYPE PRIT_ITEM_TRACE_T
*’ TABLES
*’    IT_ITEM_MAIN_INPUTNPUT TYPE PRIT_ITEM_MAIN_INPUTNPUT_T
*’    IT_ITEM_ATTRIB_INPUTNPUT TYPE PRIT_ITEM_ATTRIBUTE_T
*’    IT_ITEM_TIMESTMP_INPUT TYPE PRIT_ITEM_TIMESTAMP_T
*’    IT_MANUAL_COND_INPUT TYPE PRIT_COND_INPUT_T OPTIONAL
*’    ET_ITEM_CALC_MAIN_RESLT TYPE PRIT_ITEM_MAIN_RESULT_T OPTIONAL
*’    ET_MESSAGES TYPE PRIT_MESSAGE_T OPTIONAL
*’----------------------------------------------------------------------
ENDFUNCTION.

Table IS_HEADER_INPUT //header data


This table should contain some basic pricing header information and pricing attributes on header level needed to find the correct header price conditions.

IS_HEADER_INPUT-APPLICATION = ‘CRM’.
IS_HEADER_INPUT-PRC_PROCEDURE_NAME = ‘0PRT01’. (This must be your pricing procedure)
IS_HEADER_INPUT-DOCUMENT_CURRENCY_UNIT = ‘EUR’.
IS_HEADER_INPUT-LOCAL_CURRENCY_UNIT = ‘EUR’.

Now we have to provide all pricing attributes on header level. This is for example sales organization and sold-to party. The table IS_HEADER_INPUT contains another table called ATTRIBUTES and this table contains a table VALUES. Both tables needs to be filled with the attribute name and corresponding value (this is not the correct coding, but explains how to fill the structures):

IS_HEADER_INPUT-ATTRIBUTES[]-FIELDNAME = ‘DIS_CHANNEL’.
IS_HEADER_INPUT-ATTRIBUTES[]-VALUES[] = ‘01’. (this must be your distribution channel)
IS_HEADER_INPUT-ATTRIBUTES[]-FIELDNAME = ‘SALES_ORG’.
IS_HEADER_INPUT-ATTRIBUTES[]-VALUES[] = ‘O 500000001’. (this must be your sales organization)
IS_HEADER_INPUT-ATTRIBUTES[]-FIELDNAME = ‘SOLD_TO_PARTY’.
IS_HEADER_INPUT-ATTRIBUTES-VALUES[] = ‘A542HGJG7687687JGJHG76701’. (this must be the GUID for the customer number

Table IT_ITEM_MAIN_INPUT //item data


This table should contain the products and the related quantities. Multiple products can be added using the same call.

IT_ITEM_MAIN_INPUT-ITEM_ID = ‘6B28CB5091CE8C33E10000000A4233D1’. (this can be any generated number and is only used to link items and attributes together)
IT_ITEM_MAIN_INPUT-PRODUCT_ID = ‘E212CC425DFF4625E10000000A422065’.
IT_ITEM_MAIN_INPUT-QUANTITY = ‘10’.
IT_ITEM_MAIN_INPUT-QUANTITY_UNIT = ‘PC’.
IT_ITEM_MAIN_INPUT-EXCH_RATE_TYPE = ‘M’.

Table IT_ITEM_ATTRIB_INPUT // item data attributes


This table should be used to provide the pricing specific attributes, needed to find the price conditions. The attributes depend on your customizing and needs. For example when you have price conditions based on (part of) the product hierarchy, you have to provide the hierarchy using attributes. To get an overview of your specific attributes, use function call SPC_GET_PRICING_PROCEDURE_INFO.

IT_ITEM_ATTRIB_INPUT-ITEM_ID = ‘6B28CB5091CE8C33E10000000A4233D1’. (this ID should be identical to the ID used for IT_ITEM_MAIN_INPUT-ITEM_ID)
IT_ITEM_ATTRIB_INPUT-FIELDNAME = 'PRODUCT'.
IT_ITEM_ATTRIB_INPUT-FIELDVALUE = ‘E212CC425DFF4625E10000000A422065’.
   
IT_ITEM_ATTRIB_INPUT-ITEM_ID = ‘6B28CB5091CE8C33E10000000A4233D1’.
IT_ITEM_ATTRIB_INPUT-FIELDNAME = 'PRC_INDICATOR'.
IT_ITEM_ATTRIB_INPUT-FIELDVALUE = 'X'.
   
IT_ITEM_ATTRIB_INPUT-ITEM_ID = ‘6B28CB5091CE8C33E10000000A4233D1’.
IT_ITEM_ATTRIB_INPUT-FIELDNAME = 'PRICE_PRODUCT'.
IT_ITEM_ATTRIB_INPUT-FIELDVALUE = ‘E212CC425DFF4625E10000000A422065’.
   
IT_ITEM_ATTRIB_INPUT-ITEM_ID = ‘6B28CB5091CE8C33E10000000A4233D1’.
IT_ITEM_ATTRIB_INPUT-FIELDNAME = 'PROCESS_QTY_UNIT'.
IT_ITEM_ATTRIB_INPUT-FIELDVALUE = ‘PC’.
   

Table IT_ITEM_TIMESTMP_INPUT //time stamp data


This table should contain the required timestamps for selecting the correct price conditions.

IT_ITEM_TIMESTMP_INPUT-ITEM_ID = ‘6B28CB5091CE8C33E10000000A4233D1’.
IT_ITEM_TIMESTMP_INPUT-FIELDNAME = 'PRICE_DATE'.
IT_ITEM_TIMESTMP_INPUT-TIMESTAMP = ‘20041021000000’.

IT_ITEM_TIMESTMP_INPUT-ITEM_ID = ‘6B28CB5091CE8C33E10000000A4233D1’.
IT_ITEM_TIMESTMP_INPUT-FIELDNAME = 'TAX_DATE'.
IT_ITEM_TIMESTMP_INPUT-TIMESTAMP = ‘20041021000000’.

Result


As a result tables ES_HEADER_RESULT (header price conditions) and ET_ITEM_CALC_ADDNL_RESULT (item price conditions) are returned. The result will not contain all individual price conditions but only a list of net and gross value including the subtotals from the mentioned price procedure.

Example:


In case of problems it is helpful to switch on the price trace using following parameter IS_HEADER_INPUT-PERFORM_TRACE = ‘X’. Table ET_TRACE will contain the price trace in XML format.

Recommendation


This function module can increase the performance of retrieving price information (related to order simulation) in case you only need to have some specific pricing information and need limited attributes. When also availability check is needed order simulation must be used. This new function module can be very helpful when implementing websites connected to SAP or customer specific reports which must generated specific price information.

4 comments:

  1. Brilliant and useful. Thanks for the post. You guys do such a good job with the information you share on your site. I have been here several times and your site is one of my few trusted sources of not just solutions to current problems, but exciting information on SAP CRM and other areas.

    ReplyDelete
  2. Thanks for the post. Please, I'd like to know how to pass quantity scales for pricing conditions to the IPC. For example from qty 0 to 20 units, price = 100 usd. From qty 21 units, price = 90 usd. Thanks.

    ReplyDelete
  3. This is quite useful. Thanks for sharing.

    However, I am stuck at trying to influence the pricing by adding the manual condition. For eg. When I am trying to give Discount (saying using condition type ZDIV), my net value is not changing. It still remains the same.

    Am I missing something?

    ReplyDelete
  4. This is a great piece of work. I tried with the steps given in this blog but unfortunately its not working for me. I am trying it with the custom pricing procedure in our system with additional set of item attributes. Can you please let me know what I might be doing wrong and how do I identify the errors?

    ReplyDelete