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 MM01

Former Member
0 Likes
759

Hello Experts,

I have developed a Z report using BAPI BAPI_Material_savedata for extending my existing materials for another Plant. When i run my Report Program it is not giving me any error but a success message but then when my MM Consultant is testing the same he is complaining that the storage location is not getting uploaded.I have debugged my program everything is working fine , then what can be the reason behind this. Is it that the data being uploaded is wrong , My Functional Consultant does not have any idea about this. Can anyone tell me that is this a technical problem or a Functional one.I am attaching my program below:

4 REPLIES 4
Read only

Former Member
0 Likes
697

Heres my code :

&----


*& Report ZBAPI_DUMMY

*&

&----


*&

*&

&----


REPORT ZBAPI_MM01.

*&----


----


*& Report ZBAPI2

*&

&----


*&

*&

&----


  • TABLES

----


----


  • FLAGS *

----


DATA: F_STOP. " Flag used to stop processing

----


  • DATA DECLARATIONS *

----


DATA : V_EMPTY TYPE I, " No. of empty records

V_TOTAL TYPE I. " Total no. of records.

----


  • STRUCTURES & INTERNAL TABLES

----


*--- BAPI structures

DATA: BAPI_HEAD LIKE BAPIMATHEAD, " Header Segment with Control

BAPI_MAKT LIKE BAPI_MAKT, " Material Description

BAPI_MARA1 LIKE BAPI_MARA, " Client Data

BAPI_MARAX LIKE BAPI_MARAX, " Checkbox Structure for BAPI_MARA

BAPI_MARC1 LIKE BAPI_MARC, " Plant View

BAPI_MARCX LIKE BAPI_MARCX, " Checkbox Structure for BAPI_MARC

BAPI_MBEW1 LIKE BAPI_MBEW, " Accounting View

BAPI_MBEWX LIKE BAPI_MBEWX, " Checkbox Structure for BAPI_MBEW

BAPI_RETURN LIKE BAPIRET2, " Return Parameter

BAPI_MARDL LIKE BAPI_MARD,

BAPI_MARDX LIKE BAPI_MARDX.

*--- Internal table to hold excel file data

DATA: IT_INTERN TYPE ALSMEX_TABLINE OCCURS 0 WITH HEADER LINE.

*--- Internal table to hold Matetrial descriptions

DATA: BEGIN OF IT_MAKT OCCURS 100.

INCLUDE STRUCTURE BAPI_MAKT.

DATA: END OF IT_MAKT.

*--- Internal to hold the records in the text file

DATA : BEGIN OF IT_DATA OCCURS 100,

WERKS(4), " Plant

MTART(4), " Material type

MATNR(18), " Material number

MATKL(9) , " Material group

MBRSH(1), " Industry sector

MEINS(3), " Base unit of measure

SPART(2), " Division

EKGRP(3), " Purchasing group

PRCTR(10), " Profit Center

VPRSV(1), " Price control indicator

BKLAS(4), "Valuation Class

*stprs(12), " Standard price

PEINH(3), " Price unit

SPRAS(2), " Language key

MAKTX(40), " Material description

LGORT(4) , " storage location

DISMM(2) , "MRP TYPE

VERPR(23), " Moving Average Price

MTVFP(2) , " Availability Check

DISLS(2) , "Lot Size

DISPO(3) , "MRP Controller

BESKZ(1) , "Procurment Type

FHORI(3) , "SCHEDMARGIN KEY

PERKZ(1) , "Period Indicator

END OF IT_DATA.

----


  • SELECTION SCREEN. *

----


SELECTION-SCREEN BEGIN OF BLOCK SCR1 WITH FRAME TITLE TEXT-111.

PARAMETER : P_FILE TYPE RLGRAP-FILENAME OBLIGATORY " Input File

.

PARAMETER : P_MAX(4) OBLIGATORY DEFAULT '100'. " no.of recs in a session

PARAMETERS: P_HEADER TYPE I DEFAULT 0. " Header Lines

PARAMETERS: P_BEGCOL TYPE I DEFAULT 1 NO-DISPLAY,

P_BEGROW TYPE I DEFAULT 2 NO-DISPLAY,

P_ENDCOL TYPE I DEFAULT 100 NO-DISPLAY,

P_ENDROW TYPE I DEFAULT 32000 NO-DISPLAY.

SELECTION-SCREEN END OF BLOCK SCR1.

----


  • AT SELECTION-SCREEN *

----


AT SELECTION-SCREEN ON VALUE-REQUEST FOR P_FILE.

*--- Validating file

PERFORM VALIDATE_FILE USING P_FILE.

----


  • START-OF-SELECTION

----


START-OF-SELECTION.

*--- Perform to convert the Excel data into an internal table

PERFORM CONVERT_XLS_ITAB.

IF NOT IT_DATA[] IS INITIAL.

*--- Perform to delete Header lines

PERFORM DELETE_HEADER_EMPTY_RECS.

ENDIF.

----


  • END OF SELECTION. *

----


END-OF-SELECTION.

*--- Perform to upload Material Master data

PERFORM UPLOAD_MATMAS.

----


  • Form : validate_input_file

----


  • Description : To provide F4 help for file if read from PC

----


FORM VALIDATE_FILE USING F_FILE TYPE RLGRAP-FILENAME.

CALL FUNCTION 'KD_GET_FILENAME_ON_F4'

CHANGING

FILE_NAME = F_FILE

EXCEPTIONS

MASK_TOO_LONG = 1

OTHERS = 2.

IF SY-SUBRC <> 0.

MESSAGE S010(ZLKPL_MSGCLASS). " 'Error in getting filename'.

ENDIF.

ENDFORM. " validate_input_file

&----


*& Form CONVER_XLS_ITAB

&----


  • text

----


FORM CONVERT_XLS_ITAB.

CALL FUNCTION 'ALSM_EXCEL_TO_INTERNAL_TABLE'

EXPORTING

FILENAME = P_FILE

I_BEGIN_COL = P_BEGCOL

I_BEGIN_ROW = P_BEGROW

I_END_COL = P_ENDCOL

I_END_ROW = P_ENDROW

TABLES

INTERN = IT_INTERN.

IF SY-SUBRC <> 0.

  • MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO

  • WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.

ENDIF.

*--- Perform to move the data into an internal data

PERFORM MOVE_DATA.

ENDFORM. " CONVERT_XLS_ITAB

&----


*& Form MOVE_DATA

&----


  • text

----


FORM MOVE_DATA.

DATA : LV_INDEX TYPE I.

FIELD-SYMBOLS <FS> .

*--- Sorting the internal table

SORT IT_INTERN BY ROW COL.

CLEAR IT_INTERN.

LOOP AT IT_INTERN.

MOVE IT_INTERN-COL TO LV_INDEX.

*--- Assigning the each record to an internal table row

ASSIGN COMPONENT LV_INDEX OF STRUCTURE IT_DATA TO <FS> .

*--- Asigning the field value to a field symbol

MOVE IT_INTERN-VALUE TO <FS> .

AT END OF ROW.

APPEND IT_DATA.

CLEAR IT_DATA.

ENDAT.

ENDLOOP.

ENDFORM. " MOVE_DATA

&----


*& Form DELETE_HEADER_EMPTY_RECS

&----


  • To delete the Header and empty records

----


FORM DELETE_HEADER_EMPTY_RECS.

DATA: LV_TABIX LIKE SY-TABIX.

IF NOT P_HEADER IS INITIAL.

LOOP AT IT_DATA.

IF P_HEADER > 0 AND NOT IT_DATA IS INITIAL.

DELETE IT_DATA FROM 1 TO P_HEADER.

  • P_HEADER = 0.

EXIT.

ENDIF.

ENDLOOP.

ENDIF.

CLEAR IT_DATA.

*--- To delete the empty lines from internal table

LOOP AT IT_DATA.

LV_TABIX = SY-TABIX.

IF IT_DATA IS INITIAL.

V_EMPTY = V_EMPTY + 1.

DELETE IT_DATA INDEX LV_TABIX..

ENDIF.

ENDLOOP.

CLEAR IT_DATA.

*--- Total no of recs in file

DESCRIBE TABLE IT_DATA LINES V_TOTAL.

IF V_TOTAL = 0.

MESSAGE I013(ZLKPL_MSGCLASS). " No records in the file

F_STOP = 'X'.

STOP.

ENDIF.

ENDFORM. " DELETE_HEADER_EMPTY_RECS

&----


*& Form UPLOAD_MATMAS

&----


  • to upload Material Master data

----


FORM UPLOAD_MATMAS .

LOOP AT IT_DATA.

  • Header

BAPI_HEAD-MATERIAL = IT_DATA-MATNR.

BAPI_HEAD-IND_SECTOR = IT_DATA-MBRSH.

BAPI_HEAD-MATL_TYPE = IT_DATA-MTART.

BAPI_HEAD-BASIC_VIEW = 'X'.

BAPI_HEAD-PURCHASE_VIEW = 'X'.

BAPI_HEAD-ACCOUNT_VIEW = 'X'.

  • Material Description

REFRESH IT_MAKT.

IT_MAKT-LANGU = IT_DATA-SPRAS.

IT_MAKT-MATL_DESC = IT_DATA-MAKTX.

APPEND IT_MAKT.

  • Client Data - Basic

BAPI_MARA1-MATL_GROUP = IT_DATA-MATKL.

BAPI_MARA1-BASE_UOM = IT_DATA-MEINS.

  • bapi_mara1-unit_of_wt = it_data-gewei.

BAPI_MARA1-DIVISION = IT_DATA-SPART.

BAPI_MARAX-MATL_GROUP = 'X'.

BAPI_MARAX-BASE_UOM = 'X'.

BAPI_MARAX-UNIT_OF_WT = 'X'.

BAPI_MARAX-DIVISION = 'X'.

  • Plant - Purchasing

BAPI_MARC1-PLANT = IT_DATA-WERKS.

BAPI_MARC1-PUR_GROUP = IT_DATA-EKGRP.

BAPI_MARC1-PROFIT_CTR = IT_DATA-PRCTR.

BAPI_MARC1-MRP_TYPE = IT_DATA-DISMM.

BAPI_MARC1-AVAILCHECK = IT_DATA-MTVFP.

BAPI_MARC1-LOTSIZEKEY = IT_DATA-DISLS.

BAPI_MARC1-MRP_CTRLER = IT_DATA-DISPO.

BAPI_MARC1-PROC_TYPE = IT_DATA-BESKZ.

BAPI_MARC1-SM_KEY = IT_DATA-FHORI.

BAPI_MARC1-PERIOD_IND = IT_DATA-PERKZ.

BAPI_MARCX-PLANT = IT_DATA-WERKS.

BAPI_MARCX-PUR_GROUP = 'X'.

  • Storage Location.

BAPI_MARDL-STGE_LOC = IT_DATA-LGORT.

BAPI_MARDX-STGE_LOC = IT_DATA-LGORT.

  • Accounting

BAPI_MBEW1-VAL_AREA = IT_DATA-WERKS.

BAPI_MBEW1-PRICE_CTRL = IT_DATA-VPRSV.

BAPI_MBEW1-VAL_CLASS = IT_DATA-BKLAS.

BAPI_MBEW1-MOVING_PR = IT_DATA-VERPR.

  • bapi_mbew1-std_price = it_data-stprs.

BAPI_MBEW1-PRICE_UNIT = IT_DATA-PEINH.

BAPI_MBEWX-VAL_AREA = IT_DATA-WERKS.

BAPI_MBEWX-PRICE_CTRL = 'X'.

BAPI_MBEWX-STD_PRICE = 'X'.

BAPI_MBEWX-PRICE_UNIT = 'X'.

*--- BAPI to create material

CALL FUNCTION 'BAPI_MATERIAL_SAVEDATA'

EXPORTING

HEADDATA = BAPI_HEAD

CLIENTDATA = BAPI_MARA1

CLIENTDATAX = BAPI_MARAX

PLANTDATA = BAPI_MARC1

PLANTDATAX = BAPI_MARCX

  • FORECASTPARAMETERS =

  • FORECASTPARAMETERSX =

  • PLANNINGDATA =

  • PLANNINGDATAX =

  • STORAGELOCATIONDATA =

  • STORAGELOCATIONDATAX =

  • VALUATIONDATA = BAPI_MBEW1

  • VALUATIONDATAX = BAPI_MBEWX

  • WAREHOUSENUMBERDATA =

  • WAREHOUSENUMBERDATAX =

  • SALESDATA = BAPI_MVKE1

  • SALESDATAX = BAPI_MVKEX

  • STORAGETYPEDATA =

  • STORAGETYPEDATAX =

IMPORTING

RETURN = BAPI_RETURN

TABLES

MATERIALDESCRIPTION = IT_MAKT

  • UNITSOFMEASURE =

  • UNITSOFMEASUREX =

  • INTERNATIONALARTNOS =

  • MATERIALLONGTEXT =

  • TAXCLASSIFICATIONS =

  • RETURNMESSAGES =

  • PRTDATA =

  • PRTDATAX =

  • EXTENSIONIN =

  • EXTENSIONINX =

.

IF BAPI_RETURN-TYPE = 'E'.

WRITE:/ 'Error:' ,BAPI_RETURN-MESSAGE ,'for material:' ,

IT_DATA-MATNR.

ELSEIF BAPI_RETURN-TYPE = 'S'.

WRITE: 'Successfully created material' ,IT_DATA-MATNR.

ENDIF.

ENDLOOP.

ENDFORM. " UPLOAD_MATMAS

Read only

0 Likes
697

Use BAPI_TRANSACTION_COMMIT after the execution of your BAPI. This updates the database with the changes made by the BAPI which a user uses in his program.

Read only

Former Member
0 Likes
697

Hi,

check whether you are sorting and deleting the all adjacent duplicates in your program for the internal table which use for upload is based on plant and material .Otherwise check STORAGELOCATIONDATA structure in debugging mode for STGE_LOC is filled with data and update flag is set in STORAGELOCATIONDATAX for STGE_LOC.

otherwise check in the upload structure whether you used

lgort type lgort,"storage location this is wrong

lgort type lgort_d,"storage location this is right

regards,

Manesh.

Read only

Former Member
0 Likes
697

HI People thanks for helping, my problem is now solved.