Skip to Content
0
Former Member
Oct 24, 2012 at 09:49 AM

SD user exit

225 Views

I am having a bit of a momement here. I know this should be easy but I just can;t see what I am doing wrong. I want to re-calculate the order quantity when a user enters a new line or changes a line.

I thought I could use MV45AFZB-USEREXIT_CHECK_VBAP, which works initially, and sets my value to what it should be. But then if i change that line again it always reverts back to the first calcualted value, and the user exit is not being invoked.

So I tried MV45AFZZ-USEREXIT_MOVE_FIELD_TO_VBAP but it only works on new lines.

I tried MV45AFZZ-USEREXIT_MOVE_FIELD_TO_VBEP and looping round yvbap, but then I get into the same problem as the CHECK_VBAP in that if I try to change the line again it always reverts back to the original calculated value???

if vbap-kwmeng > 0.

* +AF231012 add minimum order qty check for customer info rec materials

select single minlf megru into (lv_minlf, lv_megru)

from knmt

where vkorg = vbak-vkorg

and vtweg = vbak-vtweg

and kunnr = vbak-kunnr

and matnr = vbap-matnr.

if sy-subrc = 0.

CALL FUNCTION 'CONVERSION_EXIT_CUNIT_INPUT'

EXPORTING

input = lv_megru

LANGUAGE = SY-LANGU

IMPORTING

OUTPUT = lv_megru

EXCEPTIONS

UNIT_NOT_FOUND = 1

OTHERS = 2.

IF sy-subrc <> 0.



ENDIF.



* now get the Unit of measure mapping

select single umrez into lv_umrez

from marm

where matnr = vbap-matnr

and meinh = lv_megru.



lv_min_qty = lv_umrez * lv_minlf.

* divide for example our EA's into Cartons and update the qty with the rounded down figure

* not sure why Tomy system multiplies things up, doesn't happen in other systems

lv_int = ( yvbap-kwmeng DIV lv_umrez ) DIV 1000. "DIV calcs the integer quotient - always rounds down

* now we have for example the number of cartons that can be used so now convert this back to EA's

vbap-kwmeng = ( lv_int * lv_umrez ) * 1000.

if vbap-kwmeng LT lv_min_qty. "if less than min qty change to min qty

vbap-kwmeng = lv_min_qty.

endif.



clear us_dialog.

MESSAGE S902 WITH vbap-matnr lv_megru.

endif.

endif.