Application Development 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: 

extend material by 'BAPI_MATERIAL_SAVEDATA'

Former Member
0 Kudos

Hi,

the code is as below(it is failed):

BAPIMATHEAD-MATERIAL = it_error-MATNR.

BAPIMATHEAD-BASIC_VIEW = 'X'.

BAPI_MARC-PLANT = IT_GOUJIAN-WERKS.

BAPI_MARCX-PLANT = 'X'.

CALL FUNCTION 'BAPI_MATERIAL_SAVEDATA'

EXPORTING

headdata = BAPIMATHEAD

PLANTDATA = BAPI_MARc

PLANTDATAX = BAPI_MARcx.

CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'.

i just want to extend material created to more plants .

any advice?

1 ACCEPTED SOLUTION

Former Member
0 Kudos

Hello,

DATA: BEGIN OF GT_TAR_ORG OCCURS 0,

WERKS TYPE WERKS,

WEART TYPE /RB04/OES_YL3_WERKT,

MTART TYPE MTART,

END OF GT_TAR_ORG.

LOOP AT GT_TAR_ORG.

HEADDATA-MATL_TYPE = GT_TAR_ORG-MTART.

GR_PLANTDATA-PLANT = GT_TAR_ORG-WERKS.

GR_PLANTDATAX-PLANT = GT_TAR_ORG-WERKS.

CALL FUNCTION 'BAPI_MATERIAL_SAVEDATA'

EXPORTING

HEADDATA = HEADDATA

CLIENTDATA = GR_CLIENTDATA

CLIENTDATAX = GR_CLIENTDATAX

PLANTDATA = GR_PLANTDATA

PLANTDATAX = GR_PLANTDATAX

IMPORTING

RETURN = GR_RETURN

TABLES

MATERIALDESCRIPTION = MATERIALDESCRIPTION

UNITSOFMEASURE = UNITSOFMEASURE

UNITSOFMEASUREX = UNITSOFMEASUREX

RETURNMESSAGES = GT_RETURNMESSAGES

MATERIALLONGTEXT = GT_MATERIALLONGTEXT

EXTENSIONIN = GT_EXTENSIONIN

EXTENSIONINX = GT_EXTENSIONINX.

    • Append the return messages to the return table.

APPEND GR_RETURN TO RETURNMESSAGES.

APPEND LINES OF GT_RETURNMESSAGES TO RETURNMESSAGES.

RETURN = GR_RETURN.

ENDLOOP.

      • If the BAPI is unsuccessful the error flag is X.

  • IF GR_RETURN-TYPE CA 'AEX'.

  • GF_ERROR = 'X'.

  • ENDIF.

LOOP AT GT_RETURNMESSAGES.

IF GT_RETURNMESSAGES-TYPE CA 'AEX'.

GF_ERROR = 'X'.

ENDIF.

ENDLOOP.

    • Commit only if the updations were successfull

    • Commit only if the updations were successfull

IF GF_ERROR IS INITIAL.

COMMIT WORK AND WAIT.

ELSE.

ROLLBACK WORK.

ENDIF.

If useful reward.

Regards,

Vasanth

1 REPLY 1

Former Member
0 Kudos

Hello,

DATA: BEGIN OF GT_TAR_ORG OCCURS 0,

WERKS TYPE WERKS,

WEART TYPE /RB04/OES_YL3_WERKT,

MTART TYPE MTART,

END OF GT_TAR_ORG.

LOOP AT GT_TAR_ORG.

HEADDATA-MATL_TYPE = GT_TAR_ORG-MTART.

GR_PLANTDATA-PLANT = GT_TAR_ORG-WERKS.

GR_PLANTDATAX-PLANT = GT_TAR_ORG-WERKS.

CALL FUNCTION 'BAPI_MATERIAL_SAVEDATA'

EXPORTING

HEADDATA = HEADDATA

CLIENTDATA = GR_CLIENTDATA

CLIENTDATAX = GR_CLIENTDATAX

PLANTDATA = GR_PLANTDATA

PLANTDATAX = GR_PLANTDATAX

IMPORTING

RETURN = GR_RETURN

TABLES

MATERIALDESCRIPTION = MATERIALDESCRIPTION

UNITSOFMEASURE = UNITSOFMEASURE

UNITSOFMEASUREX = UNITSOFMEASUREX

RETURNMESSAGES = GT_RETURNMESSAGES

MATERIALLONGTEXT = GT_MATERIALLONGTEXT

EXTENSIONIN = GT_EXTENSIONIN

EXTENSIONINX = GT_EXTENSIONINX.

    • Append the return messages to the return table.

APPEND GR_RETURN TO RETURNMESSAGES.

APPEND LINES OF GT_RETURNMESSAGES TO RETURNMESSAGES.

RETURN = GR_RETURN.

ENDLOOP.

      • If the BAPI is unsuccessful the error flag is X.

  • IF GR_RETURN-TYPE CA 'AEX'.

  • GF_ERROR = 'X'.

  • ENDIF.

LOOP AT GT_RETURNMESSAGES.

IF GT_RETURNMESSAGES-TYPE CA 'AEX'.

GF_ERROR = 'X'.

ENDIF.

ENDLOOP.

    • Commit only if the updations were successfull

    • Commit only if the updations were successfull

IF GF_ERROR IS INITIAL.

COMMIT WORK AND WAIT.

ELSE.

ROLLBACK WORK.

ENDIF.

If useful reward.

Regards,

Vasanth