1
votes

I want to programmatically change the moving/average price(s) of materials for the following special case:

VPRSV = 'S'  (Standard price)
MLMAA = 'X'  (Material Ledger activated)
MLAST = '3'  (Material Price Determination = '3' (Single-/Multilevel))
period = current

It has to work when there is already a material document for the given material in the current period. All other special cases that I need are solved.

I am searching for the function module equivalent of changing the moving average price using MM02, not MR21.

Maybe BAPI_MATVAL_PRICE_CHANGE is what I'm searching for?

What confuses me is that I cannot find a parameter that determines that I want to change the moving average price and not the standard price. Did I miss a parameter? If not, does it change the standard price or moving average price?

And I'm not sure whether this function module is the equivalent of MM02 or MR21.

2
Maybe this is an alternative for your requirement ¿can you check this link? - Nelson Miranda
Hi Nelson, this code changes the standard price, I need to change the moving average price, although VPRSV = 'S' - Gerd Castan

2 Answers

1
votes

no, there is not such a function module. But you can use Bapi BAPI_MATVAL_PRICE_CHANGE to post price differences to ML. With this you can adjust your price to the value that you want.

1
votes

You should use BAPI_MATERIAL_SAVEDATA to do this. Several mandatory structures should be filled for the successful update of average price:

HEADDATA-MATERIAL        = P_MATNR. "material number

HEADDATA-ACCOUNT_VIEW    = 'X'. 

VALDATA-VAL_AREA         = P_BWKEY.  "valuation area

VALDATA-VAL_TYPE         = P_BWTAR.  "valuation type

VALDATA-MOVING_PR        = P_STPRS. "new value of moving price

VALDATAX-VAL_AREA        = P_BWKEY. "valuation area for tax accounting

VALDATAX-VAL_TYPE        = P_BWTAR. "valuation type for tax accounting

VALDATAX-MOVING_PR       = 'X'.    "update indicator

CALL FUNCTION 'BAPI_MATERIAL_SAVEDATA'
 EXPORTING
  HEADDATA = HEADDATA
  VALUATIONDATA = VALDATA
  VALUATIONDATAX = VALDATAX

 IMPORTING
  RETURN = BAPI_RETURN
 TABLES
MATERIALDESCRIPTION = INT_MAKT
.