‎2008 Apr 14 4:40 AM
Hi
which is the best way of transfers Material Master data into SAP system.
LSMW, BDC ( Session/Call Transaction ), or BAPI.
thanks and regrds.
‎2008 Apr 14 5:17 AM
Go with bapi
bdc -- 1)transaction is screen flow
2) time taking process
3) screen flow sequence is there during transfering
data
4) only to SAP
Bapi -- 1) no screen flow
2) during uploading data it directly hit the structures
3) quick response
‎2008 Apr 14 5:22 AM
Hi,
Bapi is the Best method,
No screens Calling Direct Updation,
With Regards ,
Kiran.G
REPORT y_test8.
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 " "
"Information
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
*--- 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
gewei(3), " Weight Unit
spart(2), " Division
ekgrp(3), " Purchasing group
vprsv(1), " Price control indicator
stprs(12), " Standard price
peinh(3), " Price unit
spras(2), " Language key
maktx(40), " Material description
END OF it_data.
*----
*
SELECTION SCREEN. *
*----
*
SELECTION-SCREEN BEGIN OF BLOCK scr1 WITH FRAME TITLE text-111.
PARAMETER : p_file TYPE rlgrap-filename OBLIGATORY DEFAULT " Input File
'C:\Material_master.XLS'.
PARAMETER : p_max(4) OBLIGATORY DEFAULT '100'. " no.of recs in a
PARAMETERS: p_header TYPE i DEFAULT 0. " Header Lines
PARAMETERS: p_begcol TYPE i DEFAULT 1 NO-DISPLAY,
p_begrow TYPE i DEFAULT 1 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 = '01' . " it_data-matkl.
bapi_mara1-base_uom = 'TO' . " it_data-meins.
bapi_mara1-unit_of_wt = it_data-gewei.
bapi_mara1-division = '01' . " 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 = '0001' . " it_data-werks.
bapi_marc1-pur_group = '3G0' . " it_data-ekgrp.
bapi_marcx-plant = '0001' . " it_data-werks.
bapi_marcx-pur_group = 'X'.
Accounting
bapi_mbew1-val_area = '0001'.
bapi_mbew1-price_ctrl = it_data-vprsv.
bapi_mbew1-std_price = it_data-stprs.
bapi_mbew1-price_unit = it_data-peinh.
bapi_mbewx-val_area = 'X' . " 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
.
‎2008 Apr 14 5:42 AM
‎2008 Apr 15 9:34 PM
Hi ,
Bapi is the best method because error handling is easy and as
it is an remote enabled funtion module we just call the bapi into ur program and pass the parameter and tables required to it.
when u take lsmw if want to take different views for differnt plants and upload material master it become some what tough to write code in lsmw.
when u go for session method and cal transcations we should be careful while recording and the cusor positions.
for material master upload use BAPI_MATERIAL_SAVEDATA
thanks and regards
dilip
‎2008 Apr 16 6:32 AM