‎2006 Sep 19 2:22 AM
Hi,
I have to upload an excel sheet from the desktop to the internal table & I am using the FM - TEXT_CONVERT_XLS_TO_SAP ... all is going well but the enduser wants that I should check for the situation where a wrong excel file is selected for the upload, then I need to throw an error that "wrong file selected".
Any reponses on how to handle it.
Thank You,
SB.
‎2006 Sep 19 4:27 AM
Hi SB,
You can select first row from the itab populated from excel and validate if the value = Rate Type as per you requirement.
REPORT zupload_excel_to_itab.
TYPE-POOLS: truxs.
PARAMETERS: p_file TYPE rlgrap-filename.
TYPES: BEGIN OF t_datatab,
col1(30) TYPE c,
col2(30) TYPE c,
col3(30) TYPE c,
END OF t_datatab.
DATA: it_datatab type standard table of t_datatab,
wa_datatab type t_datatab.
DATA: it_raw TYPE truxs_t_text_data.
CONSTANTS: c_filename(20) type c value 'Rate Pattern'.
At selection screen
AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_file.
CALL FUNCTION 'F4_FILENAME'
EXPORTING
field_name = 'P_FILE'
IMPORTING
file_name = p_file.
START-OF-SELECTION.
CALL FUNCTION 'TEXT_CONVERT_XLS_TO_SAP'
EXPORTING
I_FIELD_SEPERATOR =
i_line_header = 'X'
i_tab_raw_data = it_raw " WORK TABLE
i_filename = p_file
TABLES
i_tab_converted_data = it_datatab[] "ACTUAL DATA
EXCEPTIONS
conversion_failed = 1
OTHERS = 2.
IF sy-subrc <> 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.
read table it_datatab index 0.
if it_datatab-col1 <> c_filename.
message e001 with 'Incorrect File'.
endif.
END-OF-SELECTION.
Hope this would give you some idea.
Cheers,
Vikram
Pls reward for helpful replies!!
‎2006 Sep 19 2:31 AM
you could use a file path parameter to request user to input the file path.
then u need to define what is defined as error/wrong.
There after just a pop up window to say 'wrong file selected'?
If all is fine then u proceed to upload. ?
‎2006 Sep 19 2:33 AM
Hi ,
How do u want to validate that? Do you want to validate based on the file name? or File extension? Or incorrrect data?
If you want to validate the file name or file extension then you need to write ur own code.
If you want to validate based on the contents then you have to first upload and then loop through the data and validate.
Cheers
VJ
‎2006 Sep 19 2:41 AM
Well I need to validate based on the filename... & I hope that since this is a regular monthly upload ... the excel sheet will be saved with date ...
‎2006 Sep 19 2:48 AM
Hi,
Use the FM "SO_SPLIT_FILE_AND_PATH" and split the filename and validate as per your requirement.
Cheers
VJ
‎2006 Sep 19 2:55 AM
Hi Vijay ... but this may restrict the user to enter the filename always the same ... instead of that if the first line/column of the excel sheet will always be = "Rate Type"... then they will have the flexibility to use any name with an .xls extention ...
With the FM that I am using TEXT_CONVERT_XLS_TO_SAP ... can I select the header's 1st column = 'Rate Type' & if sy-subrc <> 0. then throw an error...
‎2006 Sep 19 3:27 AM
‎2006 Sep 19 3:46 AM
‎2006 Sep 19 4:08 AM
Yes ... I did .. but in that the excel file values were shown as ## while debugging the internal table
‎2006 Sep 19 4:27 AM
Hi SB,
You can select first row from the itab populated from excel and validate if the value = Rate Type as per you requirement.
REPORT zupload_excel_to_itab.
TYPE-POOLS: truxs.
PARAMETERS: p_file TYPE rlgrap-filename.
TYPES: BEGIN OF t_datatab,
col1(30) TYPE c,
col2(30) TYPE c,
col3(30) TYPE c,
END OF t_datatab.
DATA: it_datatab type standard table of t_datatab,
wa_datatab type t_datatab.
DATA: it_raw TYPE truxs_t_text_data.
CONSTANTS: c_filename(20) type c value 'Rate Pattern'.
At selection screen
AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_file.
CALL FUNCTION 'F4_FILENAME'
EXPORTING
field_name = 'P_FILE'
IMPORTING
file_name = p_file.
START-OF-SELECTION.
CALL FUNCTION 'TEXT_CONVERT_XLS_TO_SAP'
EXPORTING
I_FIELD_SEPERATOR =
i_line_header = 'X'
i_tab_raw_data = it_raw " WORK TABLE
i_filename = p_file
TABLES
i_tab_converted_data = it_datatab[] "ACTUAL DATA
EXCEPTIONS
conversion_failed = 1
OTHERS = 2.
IF sy-subrc <> 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.
read table it_datatab index 0.
if it_datatab-col1 <> c_filename.
message e001 with 'Incorrect File'.
endif.
END-OF-SELECTION.
Hope this would give you some idea.
Cheers,
Vikram
Pls reward for helpful replies!!
‎2006 Sep 19 5:15 AM