Posted: Sun Nov 25, 2007 10:39 pm Post subject: User Exits In SD
User Exits In SD
User Exits In Sales Document Processing
User Exits in the SD module are implemented in a very different manner. Essentially what SAP have done is to provide a series of includes that contain procedures that are called regardless of whether they have been implemented or not. No sophistication unlike the other User Exits mentioned above.
Each of these includes contains different procedures for different user exits. You will have to check each one to find the one that you require.
You implement your Exit something like the following:
Code:
*---------------------------------------------------------------------*
* FORM USEREXIT_SAVE_DOCUMENT *
*---------------------------------------------------------------------*
* This userexit can be used to save data in additional tables *
* when a document is saved. *
* *
* If field T180-TRTYP contents 'H', the document will be *
* created, else it will be changed. *
* *
* This form is called at from form BELEG_SICHERN, before COMMIT *
* *
*---------------------------------------------------------------------*
FORM USEREXIT_SAVE_DOCUMENT.
* Example:
* CALL FUNCTION 'ZZ_EXAMPLE'
* IN UPDATE TASK
* EXPORTING
* ZZTAB = ZZTAB.
*{ INSERT CADK903250 1
*
Constants: c_Sales_Order type VbTyp value 'C',
c_Order_Without_Charge type VbTyp value 'I',
c_Transaction_Type_Add type TrTyp value 'H'.
*
*
If Vbak-Vbtyp = c_Sales_Order
or Vbak-Vbtyp = c_Order_Without_Charge.
*
* Creation or Change ??
*
If t180-TrTyp = c_Transaction_Type_Add.
*
* Do NOT change the order of these calls.
*
Call Function 'Z_XXXXXXXXXXXXXXXXX'
Exporting
Vbak = Vbak
Bsark = Vbkd-Bsark.
Call Function 'Z_XXXXXXXXXXXXXXXXXXXXX'
Starting New Task Vbak-Vbeln
Exporting
Vbak = Vbak
Ship_To = Kuwev-Kunnr
Delivery_Date = Rv45a-KetDat
Delivery_Plant = Rv45a-Dwerk
Tables
Vbap = xVbap.
EndIf.
EndIf.
*} INSERT
ENDFORM.
User Exits for Change Pricing
The following code in the MV45AFZZ include program.
Code:
*---------------------------------------------------------------------*
* FORM USEREXIT_PRICING_PREPARE_TKOMP *
*---------------------------------------------------------------------*
* This userexit can be used to move additional fields into the *
* communication table which is used for pricing: *
* *
* TKOMP for item fields *
* *
* This form is called from form PREISFINDUNG_VORBEREITEN. *
* *
*---------------------------------------------------------------------*
FORM userexit_pricing_prepare_tkomp.
---------------------------------------------------------------------
t y p e d e c l a r a t i o n s *
---------------------------------------------------------------------
types : begin of ty_s_retorders,
kunag type vbrk-kunag, " Customer Number
vbeln type vbrp-vbeln, " Billing Doucuement
matnr type vbrp-matnr, " Material Number
vgpos type vbrp-vgpos, " Item Number
fkimg type vbrp-fkimg, " Item Quantity
netwr type vbrp-netwr, " Net price of the Item
erdat type vbrk-erdat, " Date of cretaion of the record
value type vbrp-netwr, " Net value of the Item
end of ty_s_retorders,
ty_t_retorders type standard table of ty_s_retorders.
---------------------------------------------------------------------
v a r i a b l e s *
---------------------------------------------------------------------
data : lv_quant type vbrp-fkimg, " Total quantity
lv_value type vbrp-netwr, " Total value of the materials
lv_avgpr type vbrp-netwr, " Averge Price of the material
lv_dat type i, " variable to hold the year value
lv_date type vbrk-erdat. " Creation date of the docuement
---------------------------------------------------------------------
i n t e r n a l t a b l e s *
---------------------------------------------------------------------
data : gt_retorders type ty_t_retorders.
---------------------------------------------------------------------
g l o b a l d a t a d e c l a r a t i o n s *
---------------------------------------------------------------------
data : gs_output type ty_s_retorders.
CONSTANTS : lc_zpr0(4) TYPE c VALUE 'ZPR0' .
GET date VALUE which is 12 months ago.
lv_dat = sy-datum+0(4) - 1.
lv_date = sy-datum.
lv_date(4) = lv_dat.
SELECT data
SELECT vbrk~kunag " Customer Number
vbrp~vbeln " Billing Doucuement
vbrp~matnr " Material Number
vbrp~vgpos " Item Number
vbrp~fkimg " Item Quantity
vbrp~netwr " Net price of the Item
vbrk~erdat " Date of cretaion of the record
INTO TABLE gt_retorders
FROM vbrp JOIN vbrk
ON vbrk~vbeln = vbrp~vbeln
WHERE vbrk~erdat BETWEEN lv_date AND sy-datum
AND kunag EQ vbak-kunnr
AND matnr EQ vbap-matnr.
CLEAR: lv_quant,
lv_value.
LOOP the internal table AND get the total of quantity AND value
loop AT gt_retorders INTO gs_output.
gs_output-value = gs_output-fkimg * gs_output-netwr.
lv_quant = lv_quant + gs_output-fkimg.
lv_value = lv_value + gs_output-value.
ENDLOOP.
calculate the average pricing value
clear lv_avgpr .
lv_avgpr = lv_value / lv_quant.
CLEAR xkomv.
READ TABLE xkomv INTO xkomv WITH KEY kposn = vbap-posnr
kschl = lc_zpr0 .
IF sy-subrc EQ 0.
xkomv-kbetr = lv_avgpr .
MODIFY TABLE xkomv[] FROM xkomv TRANSPORTING kbetr .
ENDIF.
ENDFORM. "USEREXIT_PRICING_PREPARE_TKOMP
Q. How can i add new fields to SD-Pricing fieldcatalog.
A. If u want to add new fields in SD-pricing first add those fields in KOMKAZ(header), KOMPAZ(Item) Structures.
Then if ur doing pricing at the time of ORDER write the code in exit MV45AFZZ for passing the data from tables to pricing communication structure.
For header fields:
Code:
FORM userexit_pricing_prepare_tkomk.
TKOMK-zzfield = xxxx-zzfield2.
READ TABLE xvbpa WITH KEY parvw = 'ZD'.
IF sy-subrc EQ 0.
MOVE xvbpa-kunnr TO tkomk-zzparnr.
ENDIF.
ENDFORM. "USEREXIT_PRICING_PREPARE_TKOMK
For item fields:
Code:
FORM userexit_pricing_prepare_tkomp.
TKOMP-zzfield = xxxx-zzfield2.
MOVE vbap-mvgr1 TO tkomp-zzmvgr1.
MOVE vbap-mvgr2 TO tkomp-zzmvgr2.
MOVE vbap-mvgr3 TO tkomp-zzmvgr3.
ENDFORM. "USEREXIT_PRICING_PREPARE_TKOMP
And if ur doing pricing at the time of billing add the same code in RV60AFZZ.
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.