上傳本地.CSV檔案到內表中

kevinhaerbin發表於2009-02-20

TYPE-POOLS: truxs.

DATA: filename TYPE string VALUE '',
path TYPE string VALUE '',
fullpath TYPE string VALUE ''.
DATA: l_rc TYPE i,
l_filetable TYPE filetable.
DATA w_ans .

DATA gt_line TYPE truxs_t_text_data.
DATA: gt_data LIKE STANDARD TABLE OF zobj_personeel WITH HEADER LINE.

PARAMETERS p_file TYPE string.

AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_file.
* Open The txt File
CALL METHOD cl_gui_frontend_services=>file_open_dialog
EXPORTING
window_title = 'please choose import file'
file_filter = 'Notpad(*.TXT)|*.TXT|Excel(*.XLS)|*.XLS|ALL(*.*)|*.*|'
multiselection = space
CHANGING
file_table = l_filetable
rc = l_rc
EXCEPTIONS
file_open_dialog_failed = 1
cntl_error = 2
error_no_gui = 3
not_supported_by_gui = 4
OTHERS = 5.
IF sy-subrc = 0 AND l_rc = 1.
READ TABLE l_filetable INTO p_file INDEX 1.
ENDIF.

START-OF-SELECTION.
IF p_file IS INITIAL.

MESSAGE 'please select a file' TYPE 'I'.
SET SCREEN 1000.
LEAVE SCREEN.

ENDIF.

CALL FUNCTION 'GUI_UPLOAD'
EXPORTING
filename = p_file
TABLES
data_tab = gt_line
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.

CALL FUNCTION 'TEXT_CONVERT_CSV_TO_SAP'
EXPORTING
i_field_seperator = ';'
i_tab_raw_data = gt_line
TABLES
i_tab_converted_data = gt_data
EXCEPTIONS
conversion_failed = 1
OTHERS = 2.


1) you use the function POPUP_TO_CONFIRM serveral times in the program, but did not test what button the user cklicked on. There is a return field (answer) from that function that contains a code for each button (1 = yes, 2 = no and a = cancel.) by testing this field you can decide if the action should be done.
2) when creating the screen 1100 in which you showed all fields under eachother. Herefor you created textelements for that screen. it is always better to refer to fields in the datadictionary. By doing so you don't have to translate all your textelements when someone logs on in another language. I changed all these references to the table fileds to which they correspond.
3) there was also a problem with the data saved to the table. e.g. for matnr ther is a standard convertion exit that you can use for converting the data to standard SAP data. A material is always stored with leading zeros. therefor you can define on the screenfield that userexit (MATN1).
4.also I added search helps where possible . you can do that also on the definition of the screen field.

[@more@]

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

相關文章