匯入物料主檔基本資料的BDC程式

TolyHuang發表於2007-05-16

Report zbdc_mm_w_test no standard page heading line-size 255.
include .
tables:mara,makt.
data : bdcdata_itab like bdcdata occurs 0 with header line.
data : messtab like bdcmsgcoll occurs 0 with header line.

data: s_mode(1) type c.
data : size type i.

data: begin of wa_tab,
matnr like mara-matnr, "物料碼
mtart like mara-mtart, "物料型別
maktx like makt-maktx, "物料描述
maktxen like makt-maktx, "物料英文名
meins like mara-meins, " 物料單位
bismt like mara-bismt, "舊物產碼
matkl like mara-matkl, "物料群組
spart like mara-spart, "部門
brgew(10) type c, "毛重
ntgew(10) type c, "淨重
gewei like mara-gewei, "重量單位
volum(10) type c, "容量
voleh like mara-voleh, "數量單位
magrv like mara-magrv, "物料群組﹕包裝物料
end of wa_tab.

data: it_tab like wa_tab occurs 0 with header line.

data: begin of wa_tabtemp,
matnr type char50, "物料碼
mtart type char50, "物料型別
maktx type char50, "物料描述
maktxen type char50, "物料英文名
meins type char50, " 物料單位
bismt type char50, "舊物產碼
matkl type char50, "物料群組
spart type char50, "部門
brgew type char50, "毛重
ntgew type char50, "淨重
gewei type char50, "重量單位
volum type char50, "容量
voleh type char50, "數量單位
magrv type char50, "物料群組﹕包裝物料
end of wa_tabtemp.

data: temp_tab like wa_tabtemp occurs 0 with header line.

*** END GENERATED DATA SECTION ***

[@more@]

selection-screen: skip 1.

selection-screen begin of block b1 with frame title t1.

selection-screen : skip 1.
parameters : s_fname like rlgrap-filename obligatory.
selection-screen : skip 1.

parameters : rad_a radiobutton group rad type c,
rad_n radiobutton group rad type c,
rad_e radiobutton group rad type c.
selection-screen end of block b1.

at selection-screen on value-request for s_fname.
perform get_s_fname.

at selection-screen on radiobutton group rad.
if rad_a = 'X'.
s_mode = 'A'.
endif.

if rad_n = 'X'.
s_mode = 'N'.
endif.

if rad_e = 'X'.
s_mode = 'E'.
endif.

initialization.
t1 = '選擇匯入檔案'.

start-of-selection.


perform upload_to_itab.

loop at it_tab into wa_tab.
perform call_mm01.
call transaction 'MM01' using bdcdata_itab
mode s_mode
update 'S'
messages into messtab.

endloop.

end-of-selection.

*&---------------------------------------------------------------------*
*& FORM CALL_CT01
*&---------------------------------------------------------------------*
* 設定螢幕欄位值
*----------------------------------------------------------------------*
form call_mm01.
data: cname(16) type c.

clear bdcdata_itab.
refresh bdcdata_itab.

perform bdc_dynpro using 'SAPLMGMM' '0060'.
perform bdc_field using 'BDC_CURSOR' 'RMMG1-MTART'.
perform bdc_field using 'BDC_OKCODE' '=AUSW'.
perform bdc_field using 'RMMG1-MATNR' wa_tab-matnr.
perform bdc_field using 'RMMG1-MBRSH' 'M'.
perform bdc_field using 'RMMG1-MTART' wa_tab-mtart.

perform bdc_dynpro using 'SAPLMGMM' '0070'.
perform bdc_field using 'BDC_CURSOR' 'MSICHTAUSW-DYTXT(01)'.
perform bdc_field using 'BDC_OKCODE' '=ENTR'.
perform bdc_field using 'MSICHTAUSW-KZSEL(01)' 'X'.

perform bdc_dynpro using 'SAPLMGMM' '4004'.
perform bdc_field using 'BDC_OKCODE' '=BU'.
perform bdc_field using 'MAKT-MAKTX' wa_tab-maktx.
perform bdc_field using 'MARA-MEINS' wa_tab-meins.
perform bdc_field using 'MARA-MATKL' wa_tab-matkl.
perform bdc_field using 'MARA-BISMT' wa_tab-bismt.
perform bdc_field using 'MARA-SPART' wa_tab-spart.
perform bdc_field using 'MARA-BRGEW' wa_tab-brgew.
perform bdc_field using 'MARA-GEWEI' wa_tab-gewei.
perform bdc_field using 'MARA-NTGEW' wa_tab-ntgew.
perform bdc_field using 'MARA-VOLUM' wa_tab-volum.
perform bdc_field using 'MARA-VOLEH' wa_tab-voleh.
perform bdc_field using 'MARA-MAGRV' wa_tab-magrv.
perform bdc_field using 'BDC_CURSOR' 'MARA-MAGRV'.

endform. "CALL_CT01

*&---------------------------------------------------------------------*
*& FORM GET_S_FNAME
*&---------------------------------------------------------------------*
* 選擇檔案資料來源
*----------------------------------------------------------------------*
form get_s_fname.
call function 'WS_FILENAME_GET'
exporting
def_filename = '*.txt'
def_path = 'd:'
mask = ',*.txt.'
mode = 'O'
title = 'FIND THE TEXT FILE FOR OUTPUT'
importing
filename = s_fname
* RC =
exceptions
inv_winsys = 1
no_batch = 2
selection_cancel = 3
selection_error = 4
others = 5
.
endform. "GET_S_FNAME

*&---------------------------------------------------------------------*
*& Form UPLOAD_TO_ITAB
*&---------------------------------------------------------------------*
* 讀檔案資料到內表
*----------------------------------------------------------------------*
form upload_to_itab.
call function 'WS_UPLOAD'
exporting
filename = s_fname
filetype = 'DAT'
importing
filelength = size
tables
data_tab = temp_tab
exceptions
conversion_error = 1
file_open_error = 2
file_read_error = 3
invalid_type = 4
no_batch = 5
unknown_error = 6
invalid_table_width = 7
gui_refuse_filetransfer = 8
customer_error = 9
others = 10.

loop at temp_tab from 2.
move-corresponding temp_tab to it_tab.
append it_tab.
clear it_tab.
endloop.
endform. "UPLOAD_TO_ITAB

*----------------------------------------------------------------------*
* START NEW SCREEN *
*----------------------------------------------------------------------*
form bdc_dynpro using program dynpro.
clear bdcdata_itab.
bdcdata_itab-program = program.
bdcdata_itab-dynpro = dynpro.
bdcdata_itab-dynbegin = 'X'.
append bdcdata_itab.
endform. "BDC_DYNPRO

*----------------------------------------------------------------------*
* INSERT FIELD *
*----------------------------------------------------------------------*
form bdc_field using fnam fval.
if fval <> ''.
clear bdcdata_itab.
bdcdata_itab-fnam = fnam.
bdcdata_itab-fval = fval.
append bdcdata_itab.
endif.
endform. "BDC_FIELD

來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/9437124/viewspace-915243/,如需轉載,請註明出處,否則將追究法律責任。

相關文章