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_material_savedata

Former Member
0 Likes
991

Hi Experts,

I am writing program for uploading material master using BAPI_Material_Savedata. Its works fine for all data except description. But when I check materials using TCode MM03, I found that one material having description of other Material's. I checked in debugging mode while uploading the file. The internal Table having same data & order as maintained in File with correct material's Description. When execute FM Bapi_material_savedata, its changing the order of description.

Please help me to fix this issue.

Thanks in advance

1 ACCEPTED SOLUTION
Read only

SuhaSaha
Product and Topic Expert
Product and Topic Expert
0 Likes
911

Hello,

It'll help you a lot if you can post relevant portions ofyour BAPI call.

Back to your question, i am 100% sure that there might be some minor bug in your code for e.g., clearing of work area, incorrect loop control mechanism, incorrect reading of table entries etc.

BR,

Suhas

7 REPLIES 7
Read only

SuhaSaha
Product and Topic Expert
Product and Topic Expert
0 Likes
912

Hello,

It'll help you a lot if you can post relevant portions ofyour BAPI call.

Back to your question, i am 100% sure that there might be some minor bug in your code for e.g., clearing of work area, incorrect loop control mechanism, incorrect reading of table entries etc.

BR,

Suhas

Read only

Former Member
0 Likes
911

Thanks Suhas for reply.

As per your suggestion , I am trying to find the bug.

Read only

Former Member
0 Likes
911
Data:
BAPI_HEAD LIKE BAPIMATHEAD,  
BAPI_MAKT LIKE BAPI_MAKT,    
BAPI_MARA1 LIKE BAPI_MARA,
BAPI_MARAX LIKE BAPI_MARAX,
BAPI_MARD1 LIKE BAPI_MARD,   
BAPI_MARDX LIKE BAPI_MARDX,
BAPI_MARC1 LIKE BAPI_MARC,   
BAPI_MARCX LIKE BAPI_MARCX,
BAPI_MBEW1 LIKE BAPI_MBEW,  
BAPI_MBEWX LIKE BAPI_MBEWX,
BAPI_RETURN LIKE BAPIRET2.   

DATA: BEGIN OF IT_MAKT OCCURS 0.
        INCLUDE STRUCTURE BAPI_MAKT.
DATA: END OF IT_MAKT.


DATA : BEGIN OF IT_DATA OCCURS 0,
         MATNR(18),     " Material Number
*        MBRSH(1),      " Industry Type
         MTART(4),      " Material Type
         WERKS(4),      " Plant
         LGORT(4),      " Storage Location
         MAKTX(40),     " Material Description
         MEINS(3),      " Unit
         MATKL(9),      " Material Group
*         SPART(2),     " Division
*         KAUTB(1),     " Auto PO Indicator
         BKLAS(4),      " Valuation Class
END OF IT_DATA.

   START-OF-SELECTION.
 PERFORM UPLOAD_DATA.

FORM UPLOAD_DATA.

  DESCRIBE TABLE IT_DATA LINES COUNT.

  CLEAR IT_DATA.

  LOOP AT IT_DATA.

    PRCNTG = ( SY-TABIX / COUNT ) * 100.

    TABIX = SY-TABIX.

    CONCATENATE text-002 IT_DATA-MATNR text-003 TABIX text-004 COUNT
        into TXT separated by SPACE.

    CALL FUNCTION 'SAPGUI_PROGRESS_INDICATOR'
         EXPORTING
              PERCENTAGE = PRCNTG
              TEXT       = TXT.

    BAPI_HEAD-MATERIAL = IT_DATA-MATNR.
    BAPI_HEAD-IND_SECTOR = 'A'.   "IT_DATA-MBRSH.
    BAPI_HEAD-MATL_TYPE = IT_DATA-MTART.

    BAPI_HEAD-BASIC_VIEW = 'X'.
    BAPI_HEAD-PURCHASE_VIEW = 'X'.
    BAPI_HEAD-STORAGE_VIEW  = 'X'.
    BAPI_HEAD-ACCOUNT_VIEW = 'X'.
    BAPI_HEAD-COST_VIEW = 'X'.

*    Material Description*
      IT_MAKT-LANGU = 'E'.
      IT_MAKT-MATL_DESC = IT_DATA-MAKTX.
      APPEND IT_MAKT.
      CLEAR IT_MAKT.

 * Storage Locations*
    BAPI_MARD1-PLANT = IT_DATA-WERKS.
    BAPI_MARD1-STGE_LOC = IT_DATA-LGORT.

    BAPI_MARDX-PLANT = IT_DATA-WERKS.
    BAPI_MARDX-STGE_LOC = IT_DATA-LGORT.

*    Basic View*
    BAPI_MARA1-BASE_UOM = IT_DATA-MEINS.
    BAPI_MARA1-MATL_GROUP = IT_DATA-MATKL.
    BAPI_MARA1-DIVISION = '01'.   "IT_DATA-SPART.

    BAPI_MARAX-BASE_UOM = 'X'.
    BAPI_MARAX-MATL_GROUP = 'X'.
    BAPI_MARAX-DIVISION = 'X'.

* Plant Data*
    BAPI_MARC1-PLANT = IT_DATA-WERKS.
    BAPI_MARC1-ISS_ST_LOC = IT_DATA-LGORT.

    BAPI_MARCX-PLANT = IT_DATA-WERKS.
    BAPI_MARCX-ISS_ST_LOC = 'X'.

*purchasing view*
    BAPI_MARC1-AUTO_P_ORD = 'X'. "IT_DATA-KAUTB.

    BAPI_MARCX-AUTO_P_ORD = 'X'.

* Accounting*
    BAPI_MBEW1-VAL_AREA = IT_DATA-WERKS.
    BAPI_MBEW1-VAL_CLASS = IT_DATA-BKLAS.
    BAPI_MBEW1-PRICE_CTRL = 'V'.
*    BAPI_MBEW1-STD_PRICE = '0.00'.
*    BAPI_MBEW1-PRICE_UNIT = '1'.

    BAPI_MBEWX-VAL_AREA = IT_DATA-WERKS.
    BAPI_MBEWX-VAL_CLASS = 'X'.
    BAPI_MBEWX-PRICE_CTRL = 'X'.
*    BAPI_MBEWX-STD_PRICE = 'X'.
*    BAPI_MBEWX-PRICE_UNIT = 'X'.


CALL FUNCTION 'BAPI_MATERIAL_SAVEDATA'
       EXPORTING
         HEADDATA                  = BAPI_HEAD
        CLIENTDATA                 = BAPI_MARA1
        CLIENTDATAX                = BAPI_MARAX
        PLANTDATA                  = BAPI_MARC1
        PLANTDATAX                 = BAPI_MARCX
        STORAGELOCATIONDATA        = BAPI_MARD1
        STORAGELOCATIONDATAX       = BAPI_MARDX
        VALUATIONDATA              = BAPI_MBEW1
        VALUATIONDATAX             = BAPI_MBEWX
      IMPORTING
        RETURN                     = BAPI_RETURN
      TABLES
        MATERIALDESCRIPTION        = IT_MAKT.

    IF BAPI_RETURN-TYPE = 'E'.

      WRITE:/ 'Error:' ,BAPI_RETURN-MESSAGE ,'for material:' ,
               IT_DATA-MATNR COLOR = 6 INVERSE ON.

    ELSEIF BAPI_RETURN-TYPE = 'S'.

      IF SY-SUBRC = 0.
        CALL FUNCTION 'BAPI_TRANSACTION_COMMIT' .

        WRITE AT :/LEN1 TABIX,
                   LEN2 'Successfully created material',
                   LEN6 it_data-matnr.
      ENDIF.

    ENDIF.

    CLEAR IT_DATA.

  ENDLOOP.

ENDFORM.          " END OF UPLOAD_DATA

As execution reach at Bapi_material_Savedata, it changes the order of Description in Internal Table IT_MAKT.

Please suggest me how to fix this issue.

Thanks in Advance.

Read only

Former Member
0 Likes
911

Hi ,

you are calling in BAPI in loop , so better to clear all variables before you go for next record.

regards

Prabhu

Read only

Former Member
0 Likes
911

Just After statement, "LOOP AT IT_DATA" add


Refresh it_makt.

.

This should solve your problem of incorrect description.

Though it is better to clear all other structures and tables also after, loop at it_data statement, otherwise some other thing might go wrong which is not caught now.

BR,

Diwakar

Read only

Former Member
0 Likes
911

Thanks Suhas, Prabhu & Diwakar.

Problem is solved.

Read only

SuhaSaha
Product and Topic Expert
Product and Topic Expert
0 Likes
911

Hello Rajdeep,

This is just for future reference!

For mass maintenance of materials you should rather use BAPI_MATERIAL_SAVEREPLICA and not BAPI_MATERIAL_SAVEDATA.

Cheers,

Suhas