上載EXCEL檔案到SAP系統內錶FUNCTION

2021-05-04 13:11:38 字數 3288 閱讀 5928

思路:在選擇螢幕中點開選擇電腦中需要上傳的excel檔案( perform filesystem_show changing g_subrc p_file.),檔案上傳後用相應functiong傳到內錶中。(zhrit101)

form filesystem_show  changing pl_subrc    type i

pl_file     type rlgrap-filename.

data: l_file_tab type filetable,

l_file     type file_table,

l_title    type string.

l_title = text-001.

call method cl_gui_frontend_services=>file_open_dialog

exporting

window_title            = l_title

changing

file_table              = l_file_tab

rc                      = pl_subrc

exceptions

file_open_dialog_failed = 1

cntl_error              = 2

error_no_gui            = 3

others                  = 4.

check sy-subrc = 0.

loop at l_file_tab into l_file.

str_file = l_file.

move str_file to pl_file.

exit.

endloop.

endform.                    " filesystem_show,從電腦中選擇excel檔案

form upload_excel_file .

data: lt_intern like alsmex_tabline occurs 0 with header line.

data: l_tabix like sy-tabix.

data: l_begcol type i,

l_begrow type i,

l_endcol type i,

l_endrow type i,

l_string type string.

** 設定上傳的excel file所要讀取的範圍

move : '1'     to l_begcol,

'1'     to l_begrow,

'5'   to l_endcol,                                        "excel檔案中實際用到多少列就填多少

'65535' to l_endrow.                                     "65536應該是最大行數吧,呵呵!

field-symbols : type any.

call function 'alsm_excel_to_internal_table'

exporting

filename                = p_file

i_begin_col             = l_begcol

i_begin_row             = l_begrow

i_end_col               = l_endcol

i_end_row               = l_endrow

tables

intern                  = lt_intern

exceptions

inconsistent_parameters = 1

upload_ole              = 2

others                  = 3.

if sy-subrc <> 0.

message '讀取excel出現錯誤' type 'e'.

else.

** 當第一筆為header時,刪除

delete it_intern where row = 1.

** 檢查上傳檔案是否有資料

if it_intern is initial.

message '請檢查你excel是否有資料' type 'i'.

exit.

endif.

sort it_intern by row col.

loop at it_intern.

at new  row.

g_col = 1.

endat.

if g_col = 1.

codeif sy-subrc <> 0.

message '讀取excel出現錯誤' type 'e'.

else.

** 當第一筆為header時,刪除

delete it_intern where row = 1.

** 檢查上傳檔案是否有資料

if it_intern is initial.

message '請檢查你excel是否有資料' type 'i'.

exit.

endif.

sort it_intern by row col.

loop at it_intern.

********************本來是想 case it_intern-col,可不行哦,不知道為什麼,就設了個g_col的變數*******

g_col = it_intern-col.         

case g_col.

when 1.

perform transfer_pernr_to_sap using it_intern-value changing it_bjtab-pernr.

when 2.

perform transfer_date_to_sap using it_intern-value changing it_bjtab-begda.

when 3.

it_bjtab-infotype = it_intern-value.

when 4.

it_bjtab-subty = it_intern-value.

when 5.

it_bjtab-pbyer = it_intern-value.

endcase.

clear it_intern.

endloop.

endform. 

多檔案上載系統程式

多檔案上載系統完整版 include include common.inc title 多個檔案的上載程式 include include header.inc 定義允許上載檔案的數目 define upload no 10 echo 歡迎您!一次可以最多上載 upload no.個檔案 n if ...

adb push上載檔案到SD儲存卡

1 android tools 目錄下 mksdcard指令 出1 gb的儲存卡 mksdcard 1024m home yinjk sdcard.img 經過一小段的硬碟讀取時間後,就會在android sdk tools 目錄下生成乙個檔案大小為1gb的sdcard.img檔案,也可以依照自己的...

從檔案讀取資料到SAP

從檔案讀取資料到sap report z read file neil data begin of man,name 20 type c,high type p decimals 2,weight type p decimals 2,end of man.data man1 like table o...