Application Development Blog Posts
Learn and share on deeper, cross technology development topics such as integration and connectivity, automation, cloud extensibility, developing at scale, and security.
cancel
Showing results for 
Search instead for 
Did you mean: 
former_member196157
Active Participant

Item Wise Pricing Calculations of Sales Order Using Function Module

Introduction:

                The requirement we had in one of the project undertook this year is carry out the pricing functionality of sales order on web (i.e. in Webdynpro applications).

This document gives you technical approach to calculate the PRICING functionality which is mostly useful in a web based applications.

Requirement:

Develop the web based application to create the sales order ( tcode: VA01).

After developing the application to create the sales order the client requires the item wise calculation of net value and pricing conditions as per the standard. This window is display on the portal application as per the standard.

As we know that there is standard function module “PRICING” to carry out the standard sales order pricing item wise. In this document I explain the’ Z’ RFC function module to calculate the pricing. In this ‘Z’ function module I use the standard FM PRICING and other required function modules. Using this ‘Z’ function module you can integrate this RFC into a web application. 

List of standard function modules used:

  1. SPR_KOMK_KOMP_FILL
  2. PRICING
  3. PRICING_SUBSCREEN_SET_DATA
  4. PRICING_DIALOG_PAI

Steps:

  1. Create the Function Group ZPRICING and activate it.

2) Create new function module Z_SO_PRICING_CALCULATE using pricing group ZPRICING (Tcode SE37)

    

    

3)        In the attributes set the processing type as “Remote-Enabled Module“

4) The import Parameters are:

5) Changing Parameters are:

    

6) Tables of FM

       

7) Source Code:

FUNCTION Z_SO_PRICING_CALCULATE.
*"----------------------------------------------------------------------
*"*"Local Interface:
*"  IMPORTING
*"     VALUE(IV_SALES_ORG) TYPE  VBAK-VKORG
*"     VALUE(IV_DIST_CHANNEL) TYPE  VBAK-VTWEG
*"     VALUE(IV_DIVISION) TYPE  VBAK-SPART
*"     VALUE(IV_ORDER_TYPE) TYPE  VBAK-AUART
*"     VALUE(IV_ITEM_NUMBER) TYPE  VBAP-POSNR
*"     VALUE(IV_MATERIAL) TYPE  VBAP-MATNR
*"     VALUE(IV_PLANT) TYPE  VBAP-WERKS
*"     VALUE(IV_ORDER_QUANTITY) TYPE  VBAP-KWMENG
*"     VALUE(IV_SALES_VKALS) TYPE  PISPR-VKALS
*"     VALUE(IV_SOLD_TO_PARTY) TYPE  VBAK-KUNNR
*"     REFERENCE(IV_SHIP_TO_PARTY) TYPE  VBAK-KUNNR
*"     VALUE(IV_CURRENCY) TYPE  VBAK-WAERK
*"     REFERENCE(ITEM_CAT) TYPE  T184-PSTYV
*"  TABLES
*"      PT_KOMV_DISP STRUCTURE  KOMV
*"  CHANGING
*"     VALUE(CS_KOMK) TYPE  KOMK OPTIONAL
*"     VALUE(CS_KOMP) TYPE  KOMP OPTIONAL
*"----------------------------------------------------------------------

DATA: pi_i_spr TYPE  pispr.
DATA: pe_i_komk TYPE  komk,
pe_i_komp
TYPE  komp.

DATA  pt_return TYPE TABLE OF bapiret2.
DATA: p_caltyp TYPE komv-ksteu,
ps_komk 
LIKE komk,
ps_komp
LIKE komp.
DATA: pt_komv TYPE TABLE OF komv.

DATA: kalvg TYPE tvak-kalvg.
DATA: vbtyp TYPE tvak-vbtyp.
DATA: kalsm TYPE t683-kalsm.
DATA: zterm TYPE knvv-zterm,
billto
TYPE knvp-kunnr,
payer
TYPE knvp-kunnr,
shipto
TYPE knvp-kunnr,
kokrs
TYPE tka02-kokrs,
regio
TYPE t001w-regio,
meins
TYPE mara-meins.
DATA  mtpos TYPE mara-mtpos_mara.
DATA: pstyv  TYPE T184-pstyv.


pi_i_spr
-vkorg = IV_SALES_ORG.
pi_i_spr
-vtweg = IV_DIST_CHANNEL.
pi_i_spr
-spart = IV_DIVISION.
pi_i_spr
-matnr = IV_MATERIAL.
pi_i_spr
-werks = IV_PLANT.
pi_i_spr
-mgame = IV_ORDER_QUANTITY.
pi_i_spr
-vkals = IV_SALES_VKALS.
pi_i_spr
-kunnr = IV_SOLD_TO_PARTY.
* pi_i_spr-kunnr = IV_SHIP_TO_PARTY.
pi_i_spr
-kwaer = IV_CURRENCY.


CALL FUNCTION 'SPR_KOMK_KOMP_FILL'
EXPORTING
pi_i_spr                   
= pi_i_spr
IMPORTING
pe_i_komk                  
= pe_i_komk
pe_i_komp                  
= pe_i_komp
EXCEPTIONS
org_structure_not_completed
= 1
OTHERS                      = 2.


SELECT SINGLE kalvg vbtyp FROM tvak INTO (kalvg, vbtyp)
WHERE auart = IV_ORDER_TYPE. "Pricing and doc Category
SELECT SINGLE zterm FROM knvv INTO zterm
WHERE kunnr = IV_SOLD_TO_PARTY
AND vkorg = IV_SALES_ORG
AND vtweg = IV_DIST_CHANNEL
AND spart = IV_DIVISION.


*  SELECT SINGLE kunn2 FROM knvp INTO SHIPTO
*                            WHERE kunnr = IV_SOLD_TO_PARTY
*                            AND vkorg = IV_SALES_ORG
*                            AND vtweg = IV_DIST_CHANNEL
*                            AND spart = IV_DIVISION
*                            AND parvw = 'WE'.

SELECT SINGLE kunn2 FROM knvp INTO billto
WHERE kunnr = IV_SOLD_TO_PARTY
AND vkorg = IV_SALES_ORG
AND vtweg = IV_DIST_CHANNEL
AND spart = IV_DIVISION
AND parvw = 'RE'.
SELECT SINGLE kunn2 FROM knvp INTO PAYER
WHERE kunnr = IV_SOLD_TO_PARTY
AND vkorg = IV_SALES_ORG
AND vtweg = IV_DIST_CHANNEL
AND spart = IV_DIVISION
AND parvw = 'RG'.


select single kokrs from tka02 into kokrs where bukrs = pe_i_komk-bukrs.

select single regio from t001w into regio where werks = IV_PLANT.
SELECT SINGLE meins mtpos_mara FROM mara INTO (meins , mtpos)
WHERE matnr = IV_MATERIAL.

*  SELECT SINGLE pstyv FROM t184 INTO pstyv
*                            WHERE auart = IV_ORDER_TYPE
*                            AND mtpos = mtpos
*                            AND vwpos = ''
*                            AND uepst = ''.

SELECT SINGLE prsfd from tvap into  pe_i_komp-prsfd where pstyv = item_cat.
*******************Fill Up All Required Values in KOMK**********************
pe_i_komk
-KUNWE = IV_SHIP_TO_PARTY.
pe_i_komk
-KUNRE = billto.
pe_i_komk
-KNRZE = PAYER.
pe_i_komk
-zterm = zterm.
pe_i_komk
-KALSM = IV_SALES_VKALS.
pe_i_komk
-PRSDT = sy-datum.
pe_i_komk
-FBUDA = sy-datum.
pe_i_komk
-FKDAT = sy-datum.
pe_i_komk
-ERDAT = sy-datum.
pe_i_komk
-AUDAT = sy-datum.
pe_i_komk
-LAND1_WE = pe_i_komk-LAND1.
pe_i_komk
-ALAND_WERK = pe_i_komk-LAND1.
pe_i_komk
-VBTYP = vbtyp.
pe_i_komk
-KOKRS = kokrs.
pe_i_komk
-VKORGAU = IV_SALES_ORG.
pe_i_komk
-AUART_SD = IV_ORDER_TYPE.
pe_i_komk
-TRTYP = 'H'.
pe_i_komk
-AUART = IV_ORDER_TYPE.

****************Fill Up All Required Values in KOMP*************
pe_i_komp
-KPOSN = IV_ITEM_NUMBER.
pe_i_komp
-WKREG = regio.
pe_i_komp
-MGLME = IV_ORDER_QUANTITY.
pe_i_komp
-MGAME = IV_ORDER_QUANTITY.
pe_i_komp
-KMEIN = meins.
pe_i_komp
-PSTYV = item_cat.
pe_i_komp
-TAXPS = IV_ITEM_NUMBER.
*    pe_i_komp-IX_KOMK = '1'.

CALL FUNCTION 'PRICING'
EXPORTING
calculation_type     
= 'B'
comm_head_i          
= pe_i_komk
comm_item_i          
= pe_i_komp
IMPORTING
comm_head_e          
= pe_i_komk
comm_item_e          
= pe_i_komp
TABLES
tkomv                
= pt_komv.

CALL FUNCTION 'PRICING_SUBSCREEN_SET_DATA'
EXPORTING
comm_head_i          
= pe_i_komk
comm_item_i          
= pe_i_komp
trtyp_i              
= lv_trans_typ
TABLES
tkomv                
= pt_komv
ykomv                
= pt_komv_disp
EXCEPTIONS
error                
= 1
OTHERS                = 2.

CS_KOMK
= pe_i_komk.
CS_KOMP
= pe_i_komp.

***Refreshing the Pricing after Chages in any Condition Type Values******

***i.e. if the condition records are not automatically calculated********

*** i.e. they are manually entered*
*data: pt_komv_disp1 type vfsc0_vfkomv_tab.
*
*CALL FUNCTION 'PRICING_DIALOG_PAI'
*  EXPORTING
*   CALCULATION_TYPE       = 'A'
*    comm_head_i            = pe_i_komk
*    comm_item_i            = pe_i_komp
*  IMPORTING
*    COMM_HEAD_E            = pe_i_komk
*    COMM_ITEM_E            = pe_i_komp
*  TABLES
*    tkomv                  = pt_komv_disp
* CHANGING
*    C_VFKOMV               = pt_komv_disp1
*          .
ENDFUNCTION.

😎 Finally activate the Function group and all includes and then activate the FM Z_SO_PRICING_CALCULATE…..

9) Finally you can filter the data of internal table “pt_komv_disp” and display it in a separate window and the output is look like this…………….

Important Note:

I develop the function module as per the project requirement. You might have modify the code as per your specific requirement.

1 Comment