Application Development and Automation Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

Query

Former Member
0 Likes
938

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.

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
898

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!!

10 REPLIES 10
Read only

Former Member
0 Likes
898

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. ?

Read only

Former Member
0 Likes
898

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

Read only

0 Likes
898

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 ...

Read only

0 Likes
898

Hi,

Use the FM "SO_SPLIT_FILE_AND_PATH" and split the filename and validate as per your requirement.

Cheers

VJ

Read only

0 Likes
898

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...

Read only

0 Likes
898

Any reponses for this query ??

Read only

0 Likes
898

hi,

did u try using FM GUI_UPLOAD??

Read only

0 Likes
898

Yes ... I did .. but in that the excel file values were shown as ## while debugging the internal table

Read only

Former Member
0 Likes
899

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!!

Read only

0 Likes
898

Thanx Vikram