將Excel file上轉到Internal table的方法
1 定義輸入檔案(Local file for upload/download)
SELECTION-SCREEN BEGIN OF BLOCK b2 WITH FRAME TITLE text-002.
PARAMETERS p_file LIKE rlgrap-filename OBLIGATORY MODIF ID fin.
SELECTION-SCREEN END OF BLOCK b2.
2 Search help for get download path from PC
AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_file.
PERFORM get_pc_download_path(zbar00001) USING 'X'
CHANGING p_file.
ENDIF.
*&---------------------------------------------------------------------*
*& Search help for get download path form PC
*----------------------------------------------------------------------*
FORM get_pc_download_path USING value(p_value)
CHANGING p_pcfile LIKE rlgrap-filename.
CALL FUNCTION 'KD_GET_FILENAME_ON_F4'
EXPORTING
static = p_value
CHANGING
file_name = p_pcfile.
ENDFORM. " get_pc_download_path
3 Transfer Excel record to internal table
FORM transfer_to_it_file .
DATA : lt_intern TYPE alsmex_tabline OCCURS 0 WITH HEADER LINE.
DATA : l_row TYPE i,
l_col TYPE i,
l_tabix TYPE i.
CONSTANTS: c_linesize TYPE i VALUE 132.
DATA: l_row_st TYPE i VALUE '2',
l_row_ed TYPE i VALUE '65535',
l_col_st TYPE i VALUE '1',
l_col_ed TYPE i VALUE '15'.
*&fuction to upload excel data into internal table lt_intern
CALL FUNCTION 'ALSM_EXCEL_TO_INTERNAL_TABLE'
EXPORTING
filename = p_file
i_begin_col = l_col_st
i_begin_row = l_row_st
i_end_col = l_col_ed
i_end_row = l_row_ed
TABLES
intern = lt_intern
EXCEPTIONS
inconsistent_parameters = 1
upload_ole = 2
OTHERS = 3.
*&if file format is wrong etc., show error message.
IF sy-subrc <> 0.
MESSAGE s240(s#) WITH 'Error upload to internal table!'.
EXIT.
ENDIF.
*&no data in excel file
IF lt_intern[] IS INITIAL.
MESSAGE s240(s#) WITH 'No data be upload!'.
EXIT.
ELSE.
SORT lt_intern BY row col.
LOOP AT lt_intern.
l_row = lt_intern-row.
l_col = lt_intern-col + 1.
l_tabix = sy-tabix.
ASSIGN COMPONENT l_col OF STRUCTURE it_file TO
AT END OF row.
* when kpein = 0 have error
IF it_tab-kpein = 0.
it_tab-kpein = 1.
ENDIF.
it_file-zzsite = p_site.
it_file-zzerdat = g_erdat.
it_file-erdat = sy-datum.
it_file-erzet = sy-uzeit.
it_file-zzusdid = g_userid.
* Check DN number and item exists or not.
PERFORM convert_alpha_input USING it_file-vbeln.
PERFORM convert_alpha_input USING it_file-posnr.
PERFORM check_dn USING it_file-vbeln it_file-posnr l_row.
* Check date format
PERFORM check_date USING it_file-exdat l_row.
* Check currency
TRANSLATE it_file-waers TO UPPER CASE.
PERFORM check_currency USING it_file-waers l_row.
* Check amount format
PERFORM check_amount USING it_file-zzamont l_row.
* Check price unit value
PERFORM check_unit USING it_file-kpein l_row.
MOVE-CORRESPONDING it_file TO it_duplicate.
it_duplicate-count = 1.
COLLECT it_duplicate.
IF it_err[] IS INITIAL.
MOVE-CORRESPONDING it_file TO it_tab.
APPEND it_tab.
ENDIF.
CLEAR: it_tab, it_file.
ENDAT.
ENDLOOP.
ENDIF.
*&Check Record duplicate or not
PERFORM check_duplicate_record.
ENDFORM. " transfer_to_it_file
4 Check Record duplicate or not
FORM check_duplicate_record .
DATA : l_count TYPE i,
l_message(50).
CLEAR: l_message.
LOOP AT it_duplicate.
IF it_duplicate-count <> 1.
l_message = 'Records are duplicate'.
PERFORM write_error USING l_message sy-tabix.
ENDIF.
ENDLOOP.
ENDFORM. " check_duplicate_record
[@more@]來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/90072/viewspace-968699/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- 利用poi將Html中table轉為ExcelHTMLExcel
- Java 將Excel轉為SVG的方法JavaExcelSVG
- Java中將Excel轉換為JSON的兩種方法JavaExcelJSON
- Excel轉PDF怎麼轉?Excel轉PDF方法有哪些Excel
- TableTools Export Excel前Table內容格式的轉換應用ExportExcel
- Java 將Excel轉為OFDJavaExcel
- Mac上將dmg檔案轉成iso的方法Mac
- 如何將Excel轉PDF?3種免費方法很實用Excel
- EXCEL資料上傳到SQL SERVER中的簡單實現方法ExcelSQLServer
- C# 將PDF轉為ExcelC#Excel
- C# 將Excel轉為XMLC#ExcelXML
- python中將xmind轉成excelPythonExcel
- word與excel轉pdf方法Excel
- layui將table轉化表單顯示(即table.render轉為表單展示)UI
- HTML Table 輸出ExcelHTMLExcel
- 如何將Word文件轉成Excel表格?Excel
- 如何將圖片畫到canvas上?都有哪些方法?Canvas
- Win10系統下將excel檔案轉換為dbf檔案的方法Win10Excel
- pandas將Excel的所有行轉化為列表listExcel
- Java 將Excel轉為et和ett格式JavaExcel
- csv格式怎麼轉換成excel?csv格式轉換成excel格式檔案的方法Excel
- Word轉PPT\Excel的技巧方法,辦公更高效Excel
- C# 將資料寫入到Excel表格C#Excel
- 百度翻譯 Excel TableExcel
- PHP將整形數字轉為Excel下標PHPExcel
- C#/VB.NET 將Html轉為ExcelC#HTMLExcel
- node將js中的json物件生成到新的excel表中JSON物件Excel
- MySQL InnoDB File-Per-Table表空間MySql
- C# read excel file via ExcelDataReaderC#ExcelLDA
- Java 將Word轉為HTML的方法JavaHTML
- 線上pdf轉excel,辦公必備!Excel
- 利用CONCATENATE公式將Excel資料轉化為SQL公式ExcelSQL
- 金山文件怎麼匯出excel檔案 金山文件到處excel檔案的方法Excel
- 在Google的GKE上建立支援Internal Load Balancer的ServiceGo
- Vue+element ui table 匯出到excelVueUIExcel
- html table 匯出excel,親測有效HTMLExcel
- MyIsam 表 “ Incorrect key file for table 't_ '; try to repair it”AI
- GLOBAL TEMPORARY TABLE(轉)
- oracle cache table(轉)Oracle