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

Former Member
0 Likes
2,191

Dear gurus

I want to create a BAPI for material master

with only certian fields

MARA-MATKL

MARA-MTART

MARA-BISMT

MARA-MEINS

MARA-ZEINR

MARA-GROES

MARA-NORMT

MARA-WRKST

MARA-LVORM

MAKT-MAKTX

MARC-EKGRP

MARC-KAUTB

MARC-WERKS

where material number is internal

Can anybody help with code for this

thanks & regards

senthil

1 ACCEPTED SOLUTION
Read only

RichHeilman
Developer Advocate
Developer Advocate
0 Likes
1,789

There is already a BAPI which you can use.

BAPI_MATERIAL_SAVEDATA.

Regards,

Rich Heilman

10 REPLIES 10
Read only

RichHeilman
Developer Advocate
Developer Advocate
0 Likes
1,790

There is already a BAPI which you can use.

BAPI_MATERIAL_SAVEDATA.

Regards,

Rich Heilman

Read only

0 Likes
1,789

i am new to this

how to use it

senthil

Read only

0 Likes
1,789

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.

Regards,

Rich Heilman

Read only

0 Likes
1,789

No, it will not assign automatically, you will need to use BAPI BAPI_MATERIAL_GETINTNUMBER to get the next number for the material type.

Regards,

Rich Heilman

Read only

0 Likes
1,789

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.

Regards,

Rich Heilman

Read only

0 Likes
1,789

thank u very much

where i can give the

ekgrp Purchasing group

kautb  Autom.PO 

in the purchasing view

Thanks

senthil

Read only

0 Likes
1,789

Hi, for purchasing info, use the PLANTDATA parameters.

FieldsPUR_GROUP and AUTO_P_ORD

Regards,

Rich Heilman

Read only

0 Likes
1,789

Hello,

Thanks for your note, please could explain me why a BAPI has two parameters alike? for example BAPI_MATERIAL_SAVE_DATA has CLIENTEDATA and CLIENTEDATAX, PLANTDATA and PLANTDATAX.

Thanks for advance.

Read only

Former Member
0 Likes
1,789

Hi,

For internal number call the FM BAPI_MATERIAL_GETINTNUMBER to get the number ..

And pass this internal number in field HEADDATA-MATERIAL to the BAPI BAPI_MATERIAL_SAVEDATA.

Thanks,

Naren

Read only

ferry_lianto
Active Contributor
0 Likes
1,789

Hi,

You need to fill parameter PLANTDATA-PUR_GROUP and PLANTDATA-AUTO_P_ORD.

Also don't forget to mark with X for parameter PLANTDATAX-PUR_GROUP and PLANTDATAX-AUTO_P_ORD.

Hope this will help.

Regards,

Ferry Lianto