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: 

update in material master

Former Member
0 Kudos

Hi,

I created an editable alv report using MARA table.

My requirement is when editing material type & save that, it should update in material master. To update in material master, i have to use BAPI.

Can any one help me on this?

Thanks in advance.

10 REPLIES 10

Former Member
0 Kudos

A lot of threads for this.

anyhow you can check:

BAPI_MATERIAL_EDIT

BAPI_MATERIAL_SAVEDATA

0 Kudos

Hi Elzkie,

Thanks for ur answer.

I tried BAPI_MATERIAL_SAVEDATA, but when checking in MM03 it displays the existing value only, not the changed value...

0 Kudos

Share your code. Did you try debugging your program and check the return messages if there is any? Use commit work after bapi?

0 Kudos

TYPE-POOLS: slis.

TYPES: BEGIN OF ty_mara,

   matnr TYPE mara-matnr,

   ersda TYPE mara-ersda,

   ernam TYPE mara-ernam,

   mtart TYPE mara-mtart,

   MATKL TYPE MARA-MATKL,

   END OF ty_mara.

DATA: t_mara TYPE STANDARD TABLE OF ty_mara,

       s_mara TYPE ty_mara,

       IT_MARA TYPE STANDARD TABLE OF TY_MARA.

DATA: t_marc TYPE STANDARD TABLE OF marc.

DATA: t_fcat TYPE slis_t_fieldcat_alv,

       s_fcat TYPE slis_fieldcat_alv.

DATA: t_fieldcat TYPE slis_t_fieldcat_alv,

       t_event TYPE slis_t_event,

       S_EVENT TYPE SLIS_ALV_EVENT.

DATA: I_HEADER TYPE SLIS_T_LISTHEADER,

       S_HEADER TYPE SLIS_LISTHEADER.

DATA : WA_HEADDATA TYPE BAPIMATHEAD,

        WA_CLIENTDATA TYPE BAPI_MARA,

        WA_CLIENTDATAX TYPE BAPI_MARAX.

DATA : IT_RETURN TYPE TABLE OF BAPIRET2,

        WA_RETURN TYPE BAPIRET2.

      

SELECTION-SCREEN BEGIN OF BLOCK B1 WITH FRAME TITLE TEXT-000.

   PARAMETERS: P_MATNR TYPE MARA-MATNR.

SELECTION-SCREEN END OF BLOCK B1.

START-OF-SELECTION.

   SELECT matnr ersda ernam mtart MATKL

     FROM mara

     INTO TABLE t_mara

     WHERE MATNR = P_MATNR.     "SELECT VALUES FROM MARA TABLE

   PERFORM fieldcat.

   PERFORM EVENTS.

   PERFORM display.

*&---------------------------------------------------------------------*

*&      Form  FIELDCAT

*&---------------------------------------------------------------------*

FORM FIELDCAT .

   s_fcat-fieldname = 'MATNR'.

   s_fcat-seltext_s = 'Material Number'.

   s_fcat-col_pos = 1.

   s_fcat-hotspot = 'X'.

   APPEND s_fcat TO t_fcat.

   CLEAR s_fcat.

   s_fcat-fieldname = 'MTART'.

   s_fcat-seltext_m = 'Material Type'.

   s_fcat-col_pos = 2.

                           " Editable

   APPEND s_fcat TO t_fcat.

   CLEAR s_fcat.

   s_fcat-fieldname = 'ERNAM'.

   s_fcat-seltext_l = 'Created by'.

   s_fcat-col_pos = 3.

   APPEND s_fcat TO t_fcat.

   CLEAR s_fcat.

   s_fcat-fieldname = 'ERSDA'.

   s_fcat-seltext_l = 'Created on'.          " FIELD CATALOG

   s_fcat-col_pos = 4.

   APPEND s_fcat TO t_fcat.

   CLEAR s_fcat.

   s_fcat-fieldname = 'MATKL'.

   s_fcat-seltext_l = 'Material Group'.          " FIELD CATALOG

   s_fcat-col_pos = 5.

   s_fcat-edit = 'X'.

   APPEND s_fcat TO t_fcat.

   CLEAR s_fcat.

ENDFORM.                    " FIELDCAT

*&---------------------------------------------------------------------*

*&      Form  EVENTS

*&---------------------------------------------------------------------*

FORM EVENTS .

   CALL FUNCTION 'REUSE_ALV_EVENTS_GET'

     EXPORTING

       I_LIST_TYPE     = 0

     IMPORTING

       ET_EVENTS       = t_event

     EXCEPTIONS

       LIST_TYPE_WRONG = 1

       OTHERS          = 2.              " GET & POPULATE EVENTS

   READ TABLE T_EVENT INTO S_EVENT WITH KEY NAME = SLIS_EV_TOP_OF_PAGE.

   IF SY-SUBRC = 0.

     S_EVENT-FORM = 'TOP_OF_PAGE'.

     MODIFY T_EVENT FROM S_EVENT TRANSPORTING FORM WHERE NAME = S_EVENT-FORM.

   ENDIF.

   CLEAR S_EVENT.

   READ TABLE T_EVENT INTO S_EVENT WITH KEY NAME = SLIS_EV_USER_COMMAND.

   IF SY-SUBRC = 0.

     S_EVENT-FORM = 'USER_COMMAND'.

     MODIFY T_EVENT FROM S_EVENT TRANSPORTING FORM WHERE NAME = S_EVENT-FORM.

   ENDIF.

ENDFORM.                    " EVENTS

*&---------------------------------------------------------------------*

*&      Form  DISPLAY

*&---------------------------------------------------------------------*

FORM DISPLAY .

   CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'

     EXPORTING

       I_CALLBACK_PROGRAM      = sy-repid

       I_CALLBACK_USER_COMMAND = 'USER_COMMAND '

       I_CALLBACK_TOP_OF_PAGE  = 'TOP_OF_PAGE'

       IT_FIELDCAT             = t_fcat

       IT_EVENTS               = t_event

     TABLES

       T_OUTTAB                = t_mara.

ENDFORM.                    " DISPLAY

FORM USER_COMMAND USING R_UCOMM LIKE SY-UCOMM

                         RS_SELFIELD TYPE SLIS_SELFIELD.

   CASE R_UCOMM.

     WHEN '&IC1'.                  " USER COMMAND --> When double click displays MM03

       READ TABLE T_MARA INTO S_MARA INDEX RS_SELFIELD-TABINDEX.

       IF SY-SUBRC = 0.

         SET PARAMETER ID 'MAT' FIELD P_MATNR.       " To display MATNR in MM03

         SET PARAMETER ID 'MXX' FIELD 'K'.           " To directly display basic data when press enter

       CALL TRANSACTION 'MM03'.

       ENDIF.

     WHEN '&DATA_SAVE'.            " USER COMMAND --> To save data after modify

       PERFORM SAVE.

   ENDCASE.

ENDFORM.

FORM TOP_OF_PAGE.

   CLEAR I_HEADER.

   S_HEADER-TYP = 'H'.

   S_HEADER-INFO = 'MATERIAL'.

   APPEND S_HEADER TO I_HEADER.

CLEAR S_HEADER.

   S_HEADER-TYP = 'S'.

   S_HEADER-KEY = 'Material No:'.

   S_HEADER-INFO = P_MATNR.

   APPEND S_HEADER TO I_HEADER.

   CALL FUNCTION 'REUSE_ALV_COMMENTARY_WRITE'

     EXPORTING

       IT_LIST_COMMENTARY = I_HEADER.

ENDFORM.

FORM SAVE .

   LOOP AT T_MARA INTO S_MARA.

     WA_HEADDATA-MATERIAL = S_MARA-MATNR. "material no

     WA_HEADDATA-MATL_TYPE = S_MARA-MTART. "material type

     WA_CLIENTDATA-MATL_GROUP = S_MARA-MATKL. "material group

     WA_CLIENTDATAX-MATL_GROUP = 'X'. "passing material group

   CALL FUNCTION 'BAPI_MATERIAL_SAVEDATA'

     EXPORTING

       HEADDATA                   = wa_headdata

      CLIENTDATA                  = WA_CLIENTDATA

      CLIENTDATAX                 = WA_CLIENTDATAX

    IMPORTING

      RETURN                      = WA_RETURN.

     

  IF WA_RETURN-TYPE = 'E'.

       CALL FUNCTION 'BAPI_TRANSACTION_ROLLBACK'.

       WRITE:/ WA_HEADDATA-MATERIAL, 'is not changed' COLOR 3.

     ELSE.

       CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'

         EXPORTING

           WAIT = 'X'.

       IF SY-SUBRC EQ 0.

         WRITE:/ WA_HEADDATA-MATERIAL, 'is changed' COLOR 5.

       ENDIF.

     ENDIF.

ENDLOOP.

ENDFORM.                    " SAVE

0 Kudos

What you find in WA_RETURN?

I simulated the same thing in SE37 and it works perfectly

0 Kudos

Hi,

have you passed BAPIMATHEAD-BASIC_VIEW = 'X'

and try

    CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'

         EXPORTING

           WAIT = 'X'. " Replace X with space


as you might be checking MM03 in new session just after getting success message.


when you will hit BACK button then only your ALV fm will execute completely.


thanks!!

0 Kudos

i found the type 'E' in WA_RETURN

0 Kudos

Then thats the reason why its not updating Populate the internal table for return so you can check whats the specific error in bapi.

0 Kudos

And...?

Please, we are willing to help not to do your job! If it's an 'E' it means there is an error with the corresponding message.

Read it and you can address your code to solve it!

JL23
Active Contributor
0 Kudos

changing a material type is not the same like changing a value in any other field.

the field selection itself is based on the material type, there are countless restrictions before you can change a material type. Try it online in MMAM transaction to see which errors you get. You can also find more than 200 discussions in SCN where people reported problems with a material type change.