Application Development and Automation Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

BAPI :

Former Member
0 Likes
1,025

Urgent!!!

Do we have any BAPI for changing the Standard price of a material in MM02 in the Accounting view???

Shekar.

1 ACCEPTED SOLUTION
Read only

RichHeilman
Developer Advocate
Developer Advocate
0 Likes
981

Here is a simple example program which will help you code it.




report zrich_0003 .

data: headdata type bapimathead.

data: valdata type  bapi_mbew.
data: valdatax type  bapi_mbewx.
data: return type  bapiret2 .
data: returnm type table of bapi_matreturn2 with header line.
data: xmara type mara.

parameters: p_matnr type mbew-matnr,
            p_bwkey type mbew-bwkey,
            p_bwtar type mbew-bwtar,
            p_stprs type mbew-stprs.

select single * from mara into xmara
          where matnr = p_matnr.

headdata-material        = xmara-matnr.
headdata-ind_sector      = xmara-mbrsh.
headdata-matl_type       = xmara-mtart.
headdata-account_view = 'X'.

valdata-val_area  = p_bwkey.
valdata-val_type  = p_bwtar.
valdata-std_price = p_stprs.

valdatax-val_area  = p_bwkey.
valdatax-val_type  = p_bwtar.
valdatax-std_price = 'X'.

call function 'BAPI_MATERIAL_SAVEDATA'
     exporting
          headdata       = headdata
          valuationdata  = valdata
          valuationdatax = valdatax
     importing
          return         = return
     tables
          returnmessages = returnm.

check sy-subrc  = 0.

Regards,

Rich Heilman

13 REPLIES 13
Read only

suresh_datti
Active Contributor
0 Likes
981

check the tcode BAPI & expand the MM node on the left hand side.. you will get alist of all the vaialble BAPIs..

~Suresh

Read only

0 Likes
981

Try BAPI_MATERIAL_SAVEDATA.

Read only

ferry_lianto
Active Contributor
0 Likes
981

Hi Shekar,

You can use BAPI BAPI_MATERIAL_SAVEDATA.

Hope this will help.

Regards,

Ferry Lianto

Read only

RichHeilman
Developer Advocate
Developer Advocate
0 Likes
982

Here is a simple example program which will help you code it.




report zrich_0003 .

data: headdata type bapimathead.

data: valdata type  bapi_mbew.
data: valdatax type  bapi_mbewx.
data: return type  bapiret2 .
data: returnm type table of bapi_matreturn2 with header line.
data: xmara type mara.

parameters: p_matnr type mbew-matnr,
            p_bwkey type mbew-bwkey,
            p_bwtar type mbew-bwtar,
            p_stprs type mbew-stprs.

select single * from mara into xmara
          where matnr = p_matnr.

headdata-material        = xmara-matnr.
headdata-ind_sector      = xmara-mbrsh.
headdata-matl_type       = xmara-mtart.
headdata-account_view = 'X'.

valdata-val_area  = p_bwkey.
valdata-val_type  = p_bwtar.
valdata-std_price = p_stprs.

valdatax-val_area  = p_bwkey.
valdatax-val_type  = p_bwtar.
valdatax-std_price = 'X'.

call function 'BAPI_MATERIAL_SAVEDATA'
     exporting
          headdata       = headdata
          valuationdata  = valdata
          valuationdatax = valdatax
     importing
          return         = return
     tables
          returnmessages = returnm.

check sy-subrc  = 0.

Regards,

Rich Heilman

Read only

0 Likes
981

Thanks for the info RICH!

But when I modify your code as per my requirement and use it in the following way where in the Material numbers for which I got to modify the standad price to 777 come from my Internal table I_Itab, it doesn't work.

could you please help me in findng it out like WHY????? it doesnt populate the standard price as 777 eventhough it executes with out any error..

data: headdata type bapimathead.

data: valdata type bapi_mbew.

data: valdatax type bapi_mbewx.

data: return type bapiret2 .

data: returnm type table of bapi_matreturn2 with header line.

Loop at I_ItabS.

headdata-material = I_ItabS-matnr.

valdata-std_price = '777'.

valdatax-std_price = '777'.

call function 'BAPI_MATERIAL_SAVEDATA'

exporting

headdata = headdata

valuationdata = valdata

valuationdatax = valdatax

importing

return = return

tables

returnmessages = returnm.

Endloop.

Read only

0 Likes
981

It could be a COMMIT issue..you can put a function call to BAPI_TRANSACTION_COMMIT after the original BAPI.

~Suresh

Read only

0 Likes
981

The reason is that you are not setting the "X" structure correctly, eash structure has an "X" structure where you are telling the BAPI that you want to modify that specific field.

You have....



valdata-std_price = '777'.
valdatax-std_price = '777'.


Make it like this.



valdata-std_price = '777'.
valdatax-std_price = 'X'.


Regards,

RIch Heilman

Read only

0 Likes
981

Ya Rich!

I tried it. But it does the same.

Anything else we can do?

Read only

0 Likes
981

Thanks RICH!!

I got it this time.

I didn't knew that BWKEY is mandatory, which was my mistake.

Anyways thank you once again.

Read only

0 Likes
981

Yes BWKEY is part of the key and it required.

Regards,

Rich Heilman

Read only

Former Member
0 Likes
981

Hi,

Were you able to manually change the standard price in MM02??

Thanks,

Naren

Read only

0 Likes
981

yes I can change the Stnd price manually through MM02.

I donnow where I'm missing.

Its really annoying!

Read only

Former Member
0 Likes
981

Hi,

Did you try Rich's code??Also add commit work..at the end ..

report zrich_0003 .

data: headdata type bapimathead.

data: valdata type bapi_mbew.

data: valdatax type bapi_mbewx.

data: return type bapiret2 .

data: returnm type table of bapi_matreturn2 with header line.

data: xmara type mara.

parameters: p_matnr type mbew-matnr,

p_bwkey type mbew-bwkey,

p_bwtar type mbew-bwtar,

p_stprs type mbew-stprs.

select single * from mara into xmara

where matnr = p_matnr.

headdata-material = xmara-matnr.

headdata-ind_sector = xmara-mbrsh.

headdata-matl_type = xmara-mtart.

headdata-account_view = 'X'.

valdata-val_area = p_bwkey.

valdata-val_type = p_bwtar.

valdata-std_price = p_stprs.

valdatax-val_area = p_bwkey.

valdatax-val_type = p_bwtar.

valdatax-std_price = 'X'.

call function 'BAPI_MATERIAL_SAVEDATA'

exporting

headdata = headdata

valuationdata = valdata

valuationdatax = valdatax

importing

return = return

tables

returnmessages = returnm.

check sy-subrc = 0.

<b>COMMIT WORK.</b>

Thanks,

Naren