Application Development 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: 

How to Read .html file from the Desk top.

former_member196331
Active Contributor
0 Kudos
590

Need suggestions.
I have a file in my desk top.It has some columns and rows like internal table.

What is the best way to load the file into sap, I.e into my internal table.Once selected the file from the desk top and execute the program. Data has to come to Internal table.

12 REPLIES 12

raymond_giuseppi
Active Contributor
310

Once you upload the html file, you have to parse the returned string looking for tags related to table to split data and remove other tags such as display attributes.

* Simple case
table between <table> and </table>
records between <tr> </tr>
header texts between <th> and </th>
cell values between <td> and </td>
* But could be 
<table style="width:100%">
<th rowspan="2">Telephone:</th>
* Exercise: generate a table with word and export it to html and look with notepad++

Are you good with string related statements and REGEX?

0 Kudos
310

Thank you very much , but initially i am struggling to load the file to desktop to my internal table.

0 Kudos
310

Then, read links provided by Horst Keller for gui upload method and string manipulation.

0 Kudos
310

Thanks for your help.I am using below code, first capturing the Data into my internal table. But only Html part i am getting, Content i am not getting.

TYPE-POOLS: truxs.

DATA: i_text_data TYPE truxs_t_text_data,
v_filename_string TYPE string.

DATA: BEGIN OF itab OCCURS 0,
name(30),
phone(15),
fax(500).
DATA: END OF itab.

PARAMETERS: p_file LIKE rlgrap-filename.

START-OF-SELECTION.

v_filename_string = p_file.

CALL FUNCTION 'GUI_UPLOAD'
EXPORTING
filename = v_filename_string
filetype = 'ASC'
has_field_separator = 'X'
* HEADER_LENGTH = 0
* READ_BY_LINE = 'X'
" dat_mode = 'I'
* IMPORTING
* FILELENGTH =
* HEADER =
TABLES
data_tab = i_text_data
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.

310

Try to clear the 'has field separator' and 'read by line' parameters. (How was this html generated, asking cause some CR/LF characters were found?) then build the work area string from internal table whose rows should now been completely filled with the file data.

Are you not confident with you OO abilities, you didn't use CL_GUI_FRONTEND_SERVICES=>GUI_UPLOAD (At least you didn't use obsolete WS_UPLOAD)

0 Kudos
310

Don't use GUI_UPLOAD, use the appropriate method CL_GUI_FRONTEND_SERVICES. This will not resolve your problem, but it makes your program slightly better.

0 Kudos
310

But only fist row only it is fetching.

this feature is only supported for internal tables that have exactly one data field which must be of the type character or string.

0 Kudos
310

i will check it

0 Kudos
310

Ok multiple lines some how i got it.

CALL FUNCTION 'GUI_UPLOAD'
EXPORTING
filename = 'C:\Users\user\Desktop\final.html'
* FILETYPE = 'ASC
* has_field_separator = ',' <-- Comment this
* HEADER_LENGTH = 0
* READ_BY_LINE = 'X'
* IMPORTING
* FILELENGTH =
* HEADER =
TABLES
data_tab = i_datatab
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.
IF sy-subrc EQ 0.
ENDIF.

310

Raymond Giuseppi

Thank you very much. Working perfectly. Fetch the data into string. Using Upload method. and used REGEX For removing data between < and > and then done some extra work.