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

Problem with bapi_material_savedata

Former Member
0 Likes
625

Hi I am trying to use BAPI_MATERIAL_SAVEDATA to create material master records.

But, its asking for the material number, in my case, material numbers are internally generated, then how to proceed with this??

Plz help me in this

Thanks

2 REPLIES 2
Read only

Former Member
0 Likes
387

hi ,

Here is a sample program for creating a material. IF the material number is to be internal assigned, I believe that you can just leave the material number blank, if not you will need to somehow get the next available, maybe using Number range get function module

report zrich_0003 .

data: headdata type bapimathead.

data: clientdata type bapi_mara.

data: clientdatax type bapi_marax.

data: descdata type table of BAPI_MAKT with header line.

data: return type bapiret2 .

data: returnm type table of bapi_matreturn2 with header line.

data: xmara type mara.

parameters: p_matnr type mara-matnr.

headdata-material = p_matnr.

headdata-ind_sector = 'M'.

headdata-matl_type = 'FERT'.

headdata-basic_view = 'X'.

clientdata-BASE_UOM = 'EA'.

clientdatax-BASE_UOM = 'X'.

clientdata-old_mat_no = 'Old Material'.

clientdatax-old_mat_no = 'X'.

clientdata-division = '00'.

clientdatax-division = 'X'.

descdata-LANGU = sy-langu.

descdata-MATL_DESC = 'This is the description'.

append descdata.

call function 'BAPI_MATERIAL_SAVEDATA'

exporting

headdata = headdata

clientdata = clientdata

clientdatax = clientdatax

  • PLANTDATA =

  • PLANTDATAX =

  • FORECASTPARAMETERS =

  • FORECASTPARAMETERSX =

  • PLANNINGDATA =

  • PLANNINGDATAX =

  • STORAGELOCATIONDATA =

  • STORAGELOCATIONDATAX =

  • VALUATIONDATA =

  • VALUATIONDATAX =

  • WAREHOUSENUMBERDATA =

  • WAREHOUSENUMBERDATAX =

  • SALESDATA =

  • SALESDATAX =

  • STORAGETYPEDATA =

  • STORAGETYPEDATAX =

importing

return = return

tables

MATERIALDESCRIPTION = descdata

  • UNITSOFMEASURE =

  • UNITSOFMEASUREX =

  • INTERNATIONALARTNOS =

  • MATERIALLONGTEXT =

  • TAXCLASSIFICATIONS =

returnmessages = returnm

  • PRTDATA =

  • PRTDATAX =

  • EXTENSIONIN =

  • EXTENSIONINX =

.

check sy-subrc = 0.

if it is not the case....

you will need to use BAPI BAPI_MATERIAL_GETINTNUMBER to get the next number for the material type

Here is another sample, using the mentioned function module to get the next available number and create the material.

report zrich_0001.

data: headdata type bapimathead.

data: clientdata type bapi_mara.

data: clientdatax type bapi_marax.

data: descdata type table of bapi_makt with header line.

data: return type table of bapiret2 with header line.

data: returnm type table of bapi_matreturn2 with header line.

data: imat type table of bapimatinr with header line.

call function 'BAPI_MATERIAL_GETINTNUMBER'

exporting

material_type = 'ZROH'

  • INDUSTRY_SECTOR = 'M'

tables

material_number = imat.

read table imat index 1.

if sy-subrc = 0.

headdata-material = imat-material.

endif.

headdata-ind_sector = 'M'.

headdata-matl_type = 'ZROH'.

headdata-basic_view = 'X'.

clientdata-base_uom = 'EA'.

clientdatax-base_uom = 'X'.

clientdata-old_mat_no = 'Old Material'.

clientdatax-old_mat_no = 'X'.

clientdata-division = '00'.

clientdatax-division = 'X'.

descdata-langu = sy-langu.

descdata-matl_desc = 'This is the description'.

append descdata.

call function 'BAPI_MATERIAL_SAVEDATA'

exporting

headdata = headdata

clientdata = clientdata

clientdatax = clientdatax

  • PLANTDATA =

  • PLANTDATAX =

  • FORECASTPARAMETERS =

  • FORECASTPARAMETERSX =

  • PLANNINGDATA =

  • PLANNINGDATAX =

  • STORAGELOCATIONDATA =

  • STORAGELOCATIONDATAX =

  • VALUATIONDATA =

  • VALUATIONDATAX =

  • WAREHOUSENUMBERDATA =

  • WAREHOUSENUMBERDATAX =

  • SALESDATA =

  • SALESDATAX =

  • STORAGETYPEDATA =

  • STORAGETYPEDATAX =

importing

return = return

tables

materialdescription = descdata

  • UNITSOFMEASURE =

  • UNITSOFMEASUREX =

  • INTERNATIONALARTNOS =

  • MATERIALLONGTEXT =

  • TAXCLASSIFICATIONS =

returnmessages = returnm

  • PRTDATA =

  • PRTDATAX =

  • EXTENSIONIN =

  • EXTENSIONINX =

.

check sy-subrc = 0.

~~Naveen

Read only

0 Likes
387

Hi, Thanks for your reply.

I tried using BAPI_MATERIAL_GETINTNUMBER to get the next available material number. I run the Function module directly in se37 to get the next available material number. but the problem is, evrytime i run the BAPI_MATERIAL_GETINTNUMBER, the material number keeps on geting incremented even if i dont create one material.

for ex. i created a mat no 33 and later i run the bapi BAPI_MATERIAL_GETINTNUMBER, thn it gave me corrcet no 34. Now again i tried to run the same bapi, evn now it shld give me 34 since i havnt created any material yet, but its givng me 35 as the next material number. how to proceed with this?