1

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.

Sandra Rossi
  • 11,934
  • 5
  • 22
  • 48
Gerd Castan
  • 6,275
  • 3
  • 44
  • 89
  • Maybe this is an alternative for your requirement ¿can you check this [link](https://wiki.scn.sap.com/wiki/display/ERPMan/Change+the+price+of+materials+as+in+MR21+using+function+modules)? – Nelson Miranda Aug 15 '16 at 16:54
  • Hi Nelson, this code changes the standard price, I need to change the moving average price, although `VPRSV = 'S'` – Gerd Castan Aug 16 '16 at 15:44

2 Answers2

1

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.

Tapio Reisinger
  • 196
  • 1
  • 8
  • Thanks. Does `BAPI_MATVAL_PRICE_CHANGE` change the moving average when `VPRSV = 'S'`? – Gerd Castan Aug 16 '16 at 07:58
  • If price control is standard price than moving average has no relevance. BAPI_MATVAL_PRICE_CHANGE is the the equivelant to transaction MR22. But to be honest, I think you should contact an experienced Material Ledger consultant. I think you try to do things which are definitely not supported by the system (see also your question related to transaction CKMM). In the worst case you will create non-repairable inconsistencies. – Tapio Reisinger Aug 17 '16 at 04:06
1

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
.
Suncatcher
  • 10,355
  • 10
  • 52
  • 90