REPORT z_bapi_mat.
**********************************************************************
* STRUCTURE DECLARATIONS *
**********************************************************************
TABLES: bapimathead, "Headerdata
bapi_mara, "Clientdata
bapi_marax, "Clientdatax
bapi_marc, "Plantdata
bapi_marcx, "Plantdatax
bapi_makt, "Material description
bapiret2. "Return messages
DATA:v_file TYPE string.
DATA:
BEGIN OF lsmw_material_master,
matnr(018) TYPE c, "Material number
mtart(004) TYPE c, "Material type
mbrsh(001) TYPE c, "Industry sector
werks(004) TYPE c, "Plant
maktx(040) TYPE c, "Material description
dismm(002) TYPE c, "Extra Field Added In the Program as itsrequired
meins(003) TYPE c, "Base unit of measure
matkl(009) TYPE c, "Material group
spart(002) TYPE c, "Division
labor(003) TYPE c, "Lab/office
prdha(018) TYPE c, "Product hierarchy
mstae(002) TYPE c, "X-plant matl status
mtpos_mara(004) TYPE c, "Gen item cat group
brgew(017) TYPE c, "Gross weight
gewei(003) TYPE c, "Weight unit
ntgew(017) TYPE c, "Net weight
groes(032) TYPE c, "Size/Dimensions
magrv(004) TYPE c, "Matl grp pack matls
bismt(018) TYPE c, "Old material number
wrkst(048) TYPE c, "Basic material
profl(003) TYPE c, "DG indicator profile
kzumw(001) TYPE c, "Environmentally rlvt
bstme(003) TYPE c, "Order unit
vabme(001) TYPE c,
ekgrp(003) TYPE c, "Purchasing group
xchpf(001) TYPE c, "Batch management
ekwsl(004) TYPE c, "Purchasing key value
webaz(003) TYPE c, "GR processing time
mfrpn(040) TYPE c, "Manufacturer part number
mfrnr(010) TYPE c, "Manufacturer number
vprsv(001) TYPE c, "Price control indicator
stprs(015) TYPE c, "Standard price
bwprh(014) TYPE c, "Commercial price1
bklas(004) TYPE c, "Valuation class
END OF lsmw_material_master.
**********************************************************************
* INTERNAL TABLE DECLARATIONS *
**********************************************************************
*to store the input data
DATA: BEGIN OF it_matmaster OCCURS 0.
INCLUDE STRUCTURE lsmw_material_master.
DATA: END OF it_matmaster.
*for material description
DATA:BEGIN OF it_materialdesc OCCURS 0.
INCLUDE STRUCTURE bapi_makt .
DATA:END OF it_materialdesc.
*to return messages
DATA:BEGIN OF it_return OCCURS 0.
INCLUDE STRUCTURE bapiret2.
DATA:END OF it_return.
************************************************************************
* SELECTION SCREEN
************************************************************************
SELECTION-SCREEN BEGIN OF BLOCK b1 WITH FRAME TITLE text-002.
PARAMETERS:p_file LIKE rlgrap-filename OBLIGATORY.
SELECTION-SCREEN END OF BLOCK b1 .
************************************************************************
* AT SELECTION SCREEN
************************************************************************
AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_file.
CALL FUNCTION 'F4_FILENAME'
EXPORTING
program_name = syst-cprog
dynpro_number = syst-dynnr
field_name = 'P_FILE'
IMPORTING
file_name = p_file.
**********************************************************************
* TO UPLOAD THE DATA *
**********************************************************************
START-OF-SELECTION.
v_file = p_file.
CALL FUNCTION 'GUI_UPLOAD'
EXPORTING
filename = v_file
filetype = 'ASC'
has_field_separator = 'X'
TABLES
data_tab = it_matmaster
EXCEPTIONS
file_open_error = 1
file_read_error = 2
no_batch = 3
gui_refuse_filetransfer = 4
invalid_type = 5
no_authority = 6
unknown_error = 7
bad_data_format = 8
header_not_allowed = 9
separator_not_allowed = 10
header_too_long = 11
unknown_dp_error = 12
access_denied = 13
dp_out_of_memory = 14
disk_full = 15
dp_timeout = 16
OTHERS = 17.
IF sy-subrc <> 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.
**********************************************************************
* DATA POPULATIONS *
**********************************************************************
LOOP AT it_matmaster.
bapimathead-material = it_matmaster-matnr.
bapimathead-ind_sector = it_matmaster-mbrsh.
bapimathead-matl_type = it_matmaster-mtart.
bapimathead-basic_view = 'X'.
bapimathead-purchase_view = 'X'.
bapimathead-account_view = 'X'.
bapi_mara-matl_group = it_matmaster-matkl.
bapi_mara-old_mat_no = it_matmaster-bismt.
bapi_mara-base_uom = it_matmaster-meins.
bapi_mara-basic_matl = it_matmaster-wrkst.
bapi_mara-mfr_no = it_matmaster-mfrnr.
bapi_marax-matl_group = 'X'.
bapi_marax-old_mat_no = 'X'.
bapi_marax-base_uom = 'X'.
bapi_marax-basic_matl = 'X'.
bapi_marax-mfr_no = 'X'.
bapi_marc-plant = it_matmaster-werks.
bapi_marc-pur_group = it_matmaster-ekgrp.
bapi_marcx-plant = it_matmaster-werks.
bapi_marcx-pur_group = 'X'.
it_materialdesc-langu = 'EN'.
it_materialdesc-matl_desc = it_matmaster-maktx.
APPEND it_materialdesc.
CALL FUNCTION 'BAPI_MATERIAL_SAVEDATA'
EXPORTING
headdata = bapimathead
clientdata = bapi_mara
clientdatax = bapi_marax
plantdata = bapi_marc
plantdatax = bapi_marcx
IMPORTING
return = it_return
TABLES
materialdescription = it_materialdesc.
WRITE:/ it_return-type,
2 it_return-id,
22 it_return-number,
25 it_return-message.
ENDLOOP.
추가하자면,
'BAPI_MATERIAL_SAVEDATA'로는 classification view가 생성되지 않습니다.
'BAPI_OBJCL_CHANGE' function을 후에 사용해야 생성 됩니다.
이거 생성하느라 막노동했습니다^^:;