Posted: Tue Sep 09, 2008 4:55 pm Post subject: Simulate the Prices for a Customer for a Material
Simulate the Prices for a Customer for a Material with the other relevent & required information
Code:
REPORT ZPRICING MESSAGE-ID ZZ LINE-COUNT 65.
************************************************************************
* Purpose : A Program - to determine a way to Calculate *
* Prices of Products Sold (would be used for a Family of *
* Pricing Reports) *
* Author: Joe Mason - SAP Chicago *
************************************************************************
TABLES: TCURT.
DATA: PRICE(20).
DATA: TEMP-PRICE LIKE KOMV-KBETR.
DATA: CONVERT-AMOUNT LIKE VBAK-NETWR.
PARAMETERS:
CUSTOMER LIKE KOMK-KUNNR DEFAULT '1036',
SALESORG LIKE KOMK-VKORG DEFAULT 'SB01',
DISTCHNL LIKE KOMK-VTWEG DEFAULT '01',
DIVISION LIKE KOMK-SPART DEFAULT '01',
COMPANY LIKE KOMK-BUKRS DEFAULT '10',
CURRENCY LIKE KOMK-HWAER DEFAULT 'USD',
ORDERTYP LIKE VBAK-AUART DEFAULT 'OR',
PRSDT LIKE KOMK-PRSDT DEFAULT SY-DATUM,
MATNR LIKE KOMP-MATNR DEFAULT 'EC1',
QTY LIKE KOMP-MGLME DEFAULT '001'.
CLEAR TCURT.
SELECT SINGLE * FROM TCURT WHERE SPRAS EQ SY-LANGU
AND WAERS EQ CURRENCY.
CLEAR PRICE.
PERFORM PRICING USING CUSTOMER SALESORG DISTCHNL DIVISION
COMPANY CURRENCY ORDERTYP PRSDT
MATNR QTY PRICE.
WRITE: / 'Price=', PRICE.
*---------------------------------------------------------------------*
* FORM PRICING *
*---------------------------------------------------------------------*
* ........ *
*---------------------------------------------------------------------*
FORM PRICING USING CUSTOMER SALESORG DISTCHNL DIVISION
COMPANY CURRENCY ORDERTYP PRSDT
MATNR QTY PRICE.
TABLES: KOMK, KOMP.
TABLES: MARA, MVKE, MARC.
TABLES: KNA1, KNB1, KNVV.
TABLES: TVAK, TAUUM.
TABLES: T683V.
TABLES: VTCOM, KUAGV.
DATA: CALC-TYPE LIKE KOMV-KSTEU VALUE 'C'.
* data: calc-type like komv-ksteu value 'A'.
DATA: PRELIM(1) VALUE ' '.
DATA: NO-CALC(1) VALUE ' '.
DATA: BEGIN OF XKOMV OCCURS 10.
INCLUDE STRUCTURE KOMV.
DATA: END OF XKOMV.
DATA: BEGIN OF XVBAPU OCCURS 10.
INCLUDE STRUCTURE VBAPU.
DATA: END OF XVBAPU.
DATA: BEGIN OF VBUV_TAB OCCURS 10.
INCLUDE STRUCTURE VBUVVB.
DATA: END OF VBUV_TAB.
DATA: BEGIN OF XSADRVB OCCURS 10.
INCLUDE STRUCTURE SADRVB.
DATA: END OF XSADRVB.
DATA: BEGIN OF XVBPAV OCCURS 10.
INCLUDE STRUCTURE VBPAV.
DATA: END OF XVBPAV.
DATA: BEGIN OF XKOMK OCCURS 10.
INCLUDE STRUCTURE KOMK.
DATA: END OF XKOMK.
DATA: SUBRC1 LIKE SY-SUBRC.
DATA: SUBRC2 LIKE SY-SUBRC.
DATA: CONV-SUBRC LIKE SY-SUBRC.
DATA: TEMP-CURR LIKE KOMV-WAERS.
DATA: COUNT-XKOMV TYPE P.
REFRESH : XKOMV, XVBAPU, VBUV_TAB, XSADRVB, XVBPAV.
CLEAR KOMK.
CLEAR KOMP.
* Minimum Amount of Information Needed
MOVE CUSTOMER TO KOMK-KUNNR. "Customer Sold-To
PERFORM LEFT-ALIGN-FLD USING KOMK-KUNNR.
PERFORM MAK-NUM USING KOMK-KUNNR.
MOVE SALESORG TO KOMK-VKORG. "Sales Organization
MOVE DISTCHNL TO KOMK-VTWEG. "Distribution Channel
MOVE DIVISION TO KOMK-SPART. "Division
MOVE COMPANY TO KOMK-BUKRS. "Company Code
MOVE CURRENCY TO KOMK-HWAER. "Local Currency
MOVE ORDERTYP TO KOMK-AUART. "External Order Type
MOVE PRSDT TO KOMK-PRSDT. "Pricing Date
MOVE MATNR TO KOMP-MATNR. "Material
PERFORM LEFT-ALIGN-FLD USING KOMP-MATNR.
PERFORM MAK-NUM USING KOMP-MATNR.
MOVE QTY TO KOMP-MGLME. "Order Quantity
* Get the Order Header Data - from SAP Customer Data
CLEAR KNA1.
CLEAR KNB1.
CLEAR KNVV.
SELECT SINGLE * FROM KNA1 WHERE KUNNR EQ KOMK-KUNNR.
SELECT SINGLE * FROM KNB1 WHERE KUNNR EQ KOMK-KUNNR
AND BUKRS EQ KOMK-BUKRS.
SELECT SINGLE * FROM KNVV WHERE KUNNR EQ KOMK-KUNNR
AND VKORG EQ KOMK-VKORG
AND VTWEG EQ KOMK-VTWEG
AND SPART EQ KOMK-SPART.
MOVE-CORRESPONDING KNA1 TO KOMK.
MOVE-CORRESPONDING KNB1 TO KOMK.
MOVE-CORRESPONDING KNVV TO KOMK.
* Get the Order Type Related Data - from SAP
CLEAR TAUUM.
SELECT SINGLE * FROM TAUUM WHERE SPRAS EQ SY-LANGU
AND AUART EQ KOMK-AUART.
IF SY-SUBRC EQ 0.
MOVE TAUUM-AUART TO KOMK-AUART.
ELSE.
SELECT * FROM TAUUM WHERE SPRAS EQ SY-LANGU
AND AUART_SPR EQ KOMK-AUART.
EXIT.
ENDSELECT.
MOVE TAUUM-AUART TO KOMK-AUART. "Internal Order Type
ENDIF.
CLEAR TVAK.
CLEAR T683V.
* Get the Pricing Procedure
SELECT SINGLE * FROM TVAK WHERE AUART EQ KOMK-AUART.
SELECT SINGLE * FROM T683V WHERE VKORG EQ KOMK-VKORG
AND VTWEG EQ KOMK-VTWEG
AND SPART EQ KOMK-SPART
AND KALVG EQ TVAK-KALVG
AND KALKS EQ KNVV-KALKS.
MOVE-CORRESPONDING TVAK TO KOMK.
MOVE-CORRESPONDING TVAK TO KOMP.
MOVE-CORRESPONDING T683V TO KOMK.
MOVE-CORRESPONDING T683V TO KOMP.
MOVE T683V-KALSM TO KOMK-KALSM. "Pricing Procedure
* Get the Order Line item Data - from SAP
CLEAR MARA.
CLEAR MVKE.
SELECT SINGLE * FROM MARA WHERE MATNR EQ KOMP-MATNR.
SELECT SINGLE * FROM MVKE WHERE MATNR EQ KOMP-MATNR
AND VKORG EQ KOMK-VKORG
AND VTWEG EQ KOMK-VTWEG.
MOVE-CORRESPONDING MARA TO KOMP.
MOVE-CORRESPONDING MVKE TO KOMP.
MOVE-CORRESPONDING KNA1 TO KOMP.
MOVE-CORRESPONDING KNB1 TO KOMP.
MOVE-CORRESPONDING KNVV TO KOMP.
MOVE MVKE-DWERK TO KOMP-WERKS. "Delivery Plant
SELECT SINGLE * FROM MARC WHERE MATNR EQ KOMP-MATNR
AND WERKS EQ KOMP-WERKS.
MOVE-CORRESPONDING MARC TO KOMP.
* Additional Data
MOVE 'C' TO KOMK-VBTYP.
MOVE KOMK-AUART TO KOMK-FKART.
MOVE KOMK-AUART TO KOMK-AUART_SD.
MOVE 'B' TO KOMK-HITYP_PR.
MOVE KOMK-HWAER TO KOMK-WAERK. "Document Currency
MOVE KOMK-KUNNR TO KOMK-KNRZE.
MOVE KOMK-KUNNR TO KOMK-KUNRE.
MOVE KOMK-KUNNR TO KOMK-KUNWE.
MOVE 'V' TO KOMK-KAPPL. "Application Type
MOVE KOMP-WERKS TO KOMK-WERKS.
MOVE KOMK-PRSDT TO KOMK-FBUDA.
MOVE KOMK-PRSDT TO KOMK-FKDAT.
MOVE KOMK-PRSDT TO KOMK-ERDAT.
MOVE KOMK-PRSDT TO KOMK-AUDAT.
MOVE KOMP-MGLME TO KOMP-MGAME.
MOVE KOMP-MGLME TO KOMP-LMENG.
* move '0000000001' to komk-belnr. "SD Document Number
MOVE MATNR TO KOMK-BELNR. "SD Document Number
MOVE KOMK-BELNR TO KOMP-VGBEL.
MOVE KOMK-BELNR TO KOMK-KNUMV.
MOVE KOMK-BELNR TO KOMP-AUBEL.
MOVE '000010' TO KOMP-VGPOS. "Line Number
MOVE KOMP-VGPOS TO KOMP-KPOSN.
MOVE KOMP-VGPOS TO KOMP-AUPOS.
MOVE KOMP-WERKS TO KOMP-BWKEY. "Valuation Area
MOVE KOMP-MATNR TO KOMP-PMATN.
IF KOMP-MEINS IS INITIAL.
MOVE 'EA' TO KOMP-MEINS.
ENDIF.
MOVE KOMP-MEINS TO KOMP-LAGME.
MOVE KOMP-MEINS TO KOMP-VRKME.
MOVE KOMP-MEINS TO KOMP-KMEIN.
MOVE 1 TO KOMP-UMVKZ.
MOVE 1 TO KOMP-UMVKN.
MOVE 'X' TO KOMP-PRSFD.
* Additional Data - to call VIEW_KUAGV
CLEAR VTCOM.
* vtcomag-kunnr = us_kunnr.
* vtcomag-vbtyp = vbak-vbtyp.
* vtcomag-vbeln = vbak-vbeln.
* vtcomag-vkorg = vbak-vkorg.
* vtcomag-vtweg = vbak-vtweg.
* vtcomag-spart = vbak-spart.
* vtcomag-pargr = tvak-pargr.
* vtcomag-auart = tvak-auart.
* vtcomag-hityp_pr = tvak-hityp_pr.
* vtcomag-vbobj = 'A'.
MOVE-CORRESPONDING KOMK TO VTCOM.
MOVE-CORRESPONDING KOMP TO VTCOM.
MOVE-CORRESPONDING TVAK TO VTCOM.
MOVE 'A' TO VTCOM-VBOBJ.
CALL FUNCTION 'VIEW_KUAGV'
EXPORTING
COMWA = VTCOM
IMPORTING
AGWA = KUAGV
TABLES
XVBPA = XVBPAV
VBUV_TAB = VBUV_TAB
XSADR = XSADRVB
EXCEPTIONS
OTHERS = 1.
MOVE SY-SUBRC TO SUBRC1.
MOVE-CORRESPONDING KUAGV TO KOMK.
MOVE-CORRESPONDING KUAGV TO KOMP.
* Additional Data - same as Data in Pricing USER EXITS (MV45AFZZ)
MOVE MVKE-MVGR1 TO KOMP-ZZMVGR1.
MOVE MVKE-MVGR2 TO KOMP-ZZMVGR2.
MOVE MVKE-MVGR3 TO KOMP-ZZMVGR3.
MOVE MVKE-MVGR4 TO KOMP-ZZMVGR4.
MOVE MVKE-MVGR5 TO KOMP-ZZMVGR5.
MOVE KNVV-KVGR1 TO KOMP-ZZKVGR1.
MOVE KNVV-KVGR2 TO KOMP-ZZKVGR2.
MOVE KNVV-KVGR3 TO KOMP-ZZKVGR3.
MOVE KNVV-KVGR4 TO KOMP-ZZKVGR4.
MOVE KNVV-KVGR5 TO KOMP-ZZKVGR5.
MOVE MARA-PRDHA+00(5) TO KOMP-ZZPRODH1.
MOVE MARA-PRDHA+05(4) TO KOMP-ZZPRODH2.
MOVE MARA-PRDHA+09(3) TO KOMP-ZZPRODH3.
MOVE MARA-PRDHA+12(3) TO KOMP-ZZPRODH4.
MOVE MARA-PRDHA+15(3) TO KOMP-ZZPRODH5.
CALL FUNCTION 'PRICING'
EXPORTING
CALCULATION_TYPE = CALC-TYPE
COMM_HEAD_I = KOMK
COMM_ITEM_I = KOMP
PRELIMINARY = PRELIM
NO_CALCULATION = NO-CALC
IMPORTING
COMM_HEAD_E = KOMK
COMM_ITEM_E = KOMP
TABLES
TKOMV = XKOMV
* SVBAP = xvbapu
EXCEPTIONS
OTHERS = 1.
MOVE SY-SUBRC TO SUBRC2.
DESCRIBE TABLE XKOMV LINES COUNT-XKOMV.
CLEAR PRICE.
CLEAR TEMP-PRICE.
CLEAR CONV-SUBRC.
CLEAR TEMP-CURR.
LOOP AT XKOMV.
* Statement BELOW is Specific to a Pricing Procedure for a Customer
* Will LIKELY have to be CHANGED at your Installation
* IS the Condition - where the Final Price is STORED
IF XKOMV-KSCHL EQ 'ZGP ' "Condition for Calculated Price
AND TEMP-PRICE IS INITIAL.
MOVE XKOMV-KBETR TO TEMP-PRICE.
IF CURRENCY NE XKOMV-WAERS.
MOVE TEMP-PRICE TO CONVERT-AMOUNT.
CALL FUNCTION 'CONVERT_TO_LOCAL_CURRENCY'
EXPORTING
FOREIGN_AMOUNT = CONVERT-AMOUNT
FOREIGN_CURRENCY = XKOMV-WAERS
LOCAL_CURRENCY = CURRENCY
DATE = PRSDT
IMPORTING
LOCAL_AMOUNT = CONVERT-AMOUNT
EXCEPTIONS
NO_RATE_FOUND = 1
OTHERS = 2.
MOVE XKOMV-WAERS TO TEMP-CURR.
MOVE SY-SUBRC TO CONV-SUBRC.
IF SY-SUBRC EQ 0.
MOVE CONVERT-AMOUNT TO TEMP-PRICE.
ENDIF.
ENDIF.
ENDIF.
* Statement BELOW is Specific to a Pricing Procedure for a Customer
* Will LIKELY have to be CHANGED at your Installation
* IS the Condition - where the OVERRIDE to a Price is Stored
* (if that is USED at ALL)
IF XKOMV-KSCHL EQ 'Z120' "Condition for Price Overrride
AND XKOMV-KBETR > 0.
MOVE XKOMV-KBETR TO TEMP-PRICE.
IF CURRENCY NE XKOMV-WAERS.
MOVE TEMP-PRICE TO CONVERT-AMOUNT.
CALL FUNCTION 'CONVERT_TO_LOCAL_CURRENCY'
EXPORTING
FOREIGN_AMOUNT = CONVERT-AMOUNT
FOREIGN_CURRENCY = XKOMV-WAERS
LOCAL_CURRENCY = CURRENCY
DATE = PRSDT
IMPORTING
LOCAL_AMOUNT = CONVERT-AMOUNT
EXCEPTIONS
NO_RATE_FOUND = 1
OTHERS = 2.
MOVE SY-SUBRC TO CONV-SUBRC.
MOVE XKOMV-WAERS TO TEMP-CURR.
IF SY-SUBRC EQ 0.
MOVE CONVERT-AMOUNT TO TEMP-PRICE.
ENDIF.
ENDIF.
ENDIF.
IF NOT TEMP-PRICE IS INITIAL.
WRITE TEMP-PRICE TO PRICE.
SHIFT PRICE LEFT BY 5 PLACES.
MOVE '/' TO PRICE+15(1).
MOVE XKOMV-KMEIN TO PRICE+16(4).
IF CONV-SUBRC NE 0.
SHIFT PRICE LEFT BY 5 PLACES.
MOVE '/' TO PRICE+15(1).
MOVE TEMP-CURR TO PRICE+16(4).
ENDIF.
ENDIF.
ENDLOOP.
IF SUBRC1 NE 0
OR SUBRC2 NE 0
OR COUNT-XKOMV EQ 0
OR TEMP-PRICE EQ 0.
MOVE '**Not Yet Available **' TO PRICE.
ENDIF.
CALL FUNCTION 'PRICING_REFRESH'
TABLES
TKOMK = XKOMK
TKOMV = XKOMV
EXCEPTIONS
OTHERS = 1.
ENDFORM.
INCLUDE ZCONINC3.
WRITE: / ' in', TCURT-LTEXT.
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum You cannot attach files in this forum You cannot download files in this forum
All product names are trademarks of their respective companies. SAPNET.RU websites are in no way affiliated with SAP AG. SAP, SAP R/3, R/3 software, mySAP, ABAP, BAPI, xApps, SAP NetWeaver and any other are registered trademarks of SAP AG. Every effort is made to ensure content integrity. Use information on this site at your own risk.