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 for upload material master

Former Member
0 Likes
2,888

Hi experts

i want to upload material master using BAPI

1) i have an excel sheet which has 3 fields

a) material number

b) plant

c) ABC code

i have used " ALSM_EXCEL_TO_INTERNAL " function module to upload data from excel sheet to internal table

Now i have to use BAPI to upload the data from internal table for this

i have to fill the BAPI structure as follows:

a) flag the field Mrp_view of MATHEAD structure.

b) Fill the Matnr field of MATHEAD with itab ( internal table which hasa excel data)

value.

c) Flag the required field in MARCX structure.

d) Fill the required fields flagged above in MARC.

after this i have to call

"BAPI_MATERIAL_SAVEDATA" to update in SAp system

Please help me

Points will be awarded.

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
1,741

yes u r going correctly...

that is the way.. finally call function to COMMIT... COMMIT-WORK....

5 REPLIES 5
Read only

Former Member
0 Likes
1,742

yes u r going correctly...

that is the way.. finally call function to COMMIT... COMMIT-WORK....

Read only

RichHeilman
Developer Advocate
Developer Advocate
0 Likes
1,741

Here is a sample program which updates standard price, you can use this as an example for updating your MARC fields.



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

Former Member
0 Likes
1,741

Hi,

Check this link for a sample code for the BAPI.

http://sap-img.com/abap/bapi-to-copy-materials-from-one-plant-to-another.htm

Mark if helpful

Thanks,

Tushar Mundlik

Read only

0 Likes
1,741

please give me specific answer

Thanks

Read only

0 Likes
1,741

Ok, I assumed that an example was a good enough start, obviously I was wrong. Anyway, here is the modified program which excepts the material plant and the ABC indictor value and updates the material master using the BAPI.



report zrich_0001 .

data: headdata type bapimathead.

data: plantdata type bapi_marc.
data: plantdatax type  bapi_marcx.
data: return type  bapiret2 .
data: returnm type table of bapi_matreturn2 with header line.
data: xmara type mara.

parameters: p_matnr type marc-matnr,
            p_werks type marc-werks,
            p_maabc type marc-maabc.

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-mrp_view        = 'X'.

plantdata-plant  = p_werks.
plantdata-abc_id = p_maabc.

plantdatax-plant  = p_werks.
plantdatax-abc_id = 'X'.


call function 'BAPI_MATERIAL_SAVEDATA'
     exporting
          headdata       = headdata
          plantdata      = plantdata
          plantdatax     = plantdatax
     importing
          return         = return
     tables
          returnmessages = returnm.

check sy-subrc  = 0.

Regards,

RIch Heilman