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

Dynamically Using BAPI_MATERIAL_SAVEDATA

Former Member
0 Likes
924

Greetings all,

I am trying to utilize BAPI_MATERIAL_SAVEDATA. This BAPI updates the material master. However I have a problem. I have an input file that holds the material number, the actual fieldname being updated, and the applicable data for that field (weird setup yes I know). The way this BAPI is setup, it seems like the importing parameter structures are all for specific material master tables (MARA, MARD, MARC, etc.). Within each of these importing parameters there are all the fields of each table, however they are named something different than the field itself, however the data element is the same (this can be seen by looking at the types of the import parameters).

My question is this: is it possible to take the input file specified above, and successfully use this BAPI? I will be updating both custom fields and standard SAP fields on the material master. However, these fields will NOT always be in MARA, so I must somehow tell the program 'depending on what field is coming in on each record of the input file, move the data to the appropriate import parameter structure on the BAPI (if it is a standard field, otherwise use the extension area of course under the TABLES section of the BAPI).

I would think a case statement checking for if the field exists in each table down the list on the BAPI import parameters since they correspond to the material master tables. However, I think there has got to be a better way to do this.

Im sure this isnt enough info for an answer but it is a start. Any ideas! Please Help!

2 REPLIES 2
Read only

Former Member
0 Likes
843

Hi

Hope it will help you.

Pls reward if help.

REPORT z34332_bdc_create_material .

data: la_headdata type BAPIMATHEAD,

la_clientdata type BAPI_MARA,

la_CLIENTDATAX type BAPI_MARAX,

la_return type BAPIRET2.

data: i_materialdescription type table of BAPI_MAKT,

wa_materialdescription like line of i_materialdescription.

la_headdata-MATERIAL = '000000000000000004'.

la_headdata-IND_SECTOR = 'M'.

la_headdata-MATL_TYPE = 'FERT'.

la_clientdata-BASE_UOM = 'FT3'.

la_CLIENTDATAX-BASE_UOM = 'X'.

la_clientdata-MATL_GROUP = '01'.

la_CLIENTDATAX-MATL_GROUP = 'X'.

wa_materialdescription = 'TEST'.

append wa_materialdescription to i_materialdescription.

clear: wa_materialdescription.

CALL FUNCTION 'BAPI_MATERIAL_SAVEDATA'

EXPORTING

headdata = la_headdata

CLIENTDATA = la_clientdata

CLIENTDATAX = la_CLIENTDATAX

  • PLANTDATA =

  • PLANTDATAX =

  • FORECASTPARAMETERS =

  • FORECASTPARAMETERSX =

  • PLANNINGDATA =

  • PLANNINGDATAX =

  • STORAGELOCATIONDATA =

  • STORAGELOCATIONDATAX =

  • VALUATIONDATA =

  • VALUATIONDATAX =

  • WAREHOUSENUMBERDATA =

  • WAREHOUSENUMBERDATAX =

  • SALESDATA =

  • SALESDATAX =

  • STORAGETYPEDATA =

  • STORAGETYPEDATAX =

  • FLAG_ONLINE = ' '

  • FLAG_CAD_CALL = ' '

IMPORTING

RETURN = la_return

TABLES

MATERIALDESCRIPTION = i_materialdescription

  • UNITSOFMEASURE =

  • UNITSOFMEASUREX =

  • INTERNATIONALARTNOS =

  • MATERIALLONGTEXT =

  • TAXCLASSIFICATIONS =

  • RETURNMESSAGES =

  • PRTDATA =

  • PRTDATAX =

  • EXTENSIONIN =

  • EXTENSIONINX =

.

write: la_return-TYPE, ',', la_return-MESSAGE.

clear: la_headdata, la_return, la_clientdata, la_clientdatax.

Pls reward if help.

Read only

Former Member
0 Likes
843

That does help, but it is more or less what I already have coded. You see my problem is the field might be custom and it might not. It might exist on the table MARA or it might not. It might be a field that exists on another material master table (other than mara). Yes, I am aware that most fields should exist in MARA, which they probably will. However there is the chance that they might not.

Im assuming I would need to use a field-symbol for the fieldname from each record in the input file and dynamically code the program to determine: if the field is standard SAP field, which import parameter on the BAPI does it go to (ex: if field exists in mara then use the clientdata parameter...if field does not exist here check for the plantdata parameter, etc.). But the components of these structures are named totally different than the fields, thus this would require a large translation table perhaps...which is not what I will do!

If more info is required for assistance in this issue, just let me know!

Thanks for your help!