‎2006 Jul 10 11:53 AM
Hi,
Is there any Function module to read CSV file from presentation server or Application server?
Regards,
Madhu
‎2006 Jul 10 11:56 AM
Hi madhukeshwar,
1. Exactly for this purpose,
i have developed an independent FORM
where we give inputs
a) file name (eg. abcd.txt)
b) separator (eg , COMMA in your case)
c) internal table (eg. t001)
2. It will provide the data
in proper format
(no matter what the separator)
(it can work with any kind of separator)
3. just copy paste in new program.
REPORT abc.
*----
*----
change your table declaration and file name
*----
DATA : t001 LIKE TABLE OF t001 WITH HEADER LINE.
PERFORM myupload TABLES t001 USING 'd:\t001.txt' ','.
BREAK-POINT.
*----
in debug see t001
*----
INDEPENDENT FORM
*----
FORM myupload TABLES orgtab
USING filename separator.
*----
Data
DATA : BEGIN OF itab OCCURS 0,
myline(1000) TYPE c,
END OF itab.
DATA : extension(5) TYPE c.
DATA : name(100) TYPE c.
DATA : newfilename TYPE string.
*----
Step 1
CALL FUNCTION 'GUI_UPLOAD'
EXPORTING
filename = filename
TABLES
data_tab = itab.
*----
Step 2
LOOP AT itab.
REPLACE ALL OCCURRENCES OF separator IN itab-myline WITH
cl_abap_char_utilities=>horizontal_tab.
MODIFY itab.
ENDLOOP.
*----
Step 3
DATA : path LIKE pcfile-path.
path = filename.
CALL FUNCTION 'PC_SPLIT_COMPLETE_FILENAME'
EXPORTING
complete_filename = path
CHECK_DOS_FORMAT =
IMPORTING
DRIVE =
extension = extension
name = name
NAME_WITH_EXT =
PATH =
EXCEPTIONS
invalid_drive = 1
invalid_extension = 2
invalid_name = 3
invalid_path = 4
OTHERS = 5
.
*----
Step 4
newfilename = filename.
REPLACE name IN newfilename WITH 'temp'.
CALL FUNCTION 'GUI_DOWNLOAD'
EXPORTING
BIN_FILESIZE =
filename = newfilename
TABLES
data_tab = itab
FIELDNAMES =
.
*----
Step 5
CALL FUNCTION 'GUI_UPLOAD'
EXPORTING
filename = newfilename
has_field_separator = 'X'
TABLES
data_tab = orgtab.
ENDFORM. "myupload
3.
regards,
amit m.
‎2006 Jul 10 11:55 AM
‎2006 Jul 10 12:18 PM
Thanks.
My requirement is->
Read file (Presentation server) which is in CSV format.
put it into itab.
How can I use this FM?
Regards,
Madhu
‎2006 Jul 10 12:21 PM
hi Madhukar,
Use FM <b>GUI_UPLOAD</b> with filetype as 'CSV' this should work...
filetype = 'CSV'.
Regards,
Santosh
‎2006 Jul 10 11:56 AM
Hi madhukeshwar,
1. Exactly for this purpose,
i have developed an independent FORM
where we give inputs
a) file name (eg. abcd.txt)
b) separator (eg , COMMA in your case)
c) internal table (eg. t001)
2. It will provide the data
in proper format
(no matter what the separator)
(it can work with any kind of separator)
3. just copy paste in new program.
REPORT abc.
*----
*----
change your table declaration and file name
*----
DATA : t001 LIKE TABLE OF t001 WITH HEADER LINE.
PERFORM myupload TABLES t001 USING 'd:\t001.txt' ','.
BREAK-POINT.
*----
in debug see t001
*----
INDEPENDENT FORM
*----
FORM myupload TABLES orgtab
USING filename separator.
*----
Data
DATA : BEGIN OF itab OCCURS 0,
myline(1000) TYPE c,
END OF itab.
DATA : extension(5) TYPE c.
DATA : name(100) TYPE c.
DATA : newfilename TYPE string.
*----
Step 1
CALL FUNCTION 'GUI_UPLOAD'
EXPORTING
filename = filename
TABLES
data_tab = itab.
*----
Step 2
LOOP AT itab.
REPLACE ALL OCCURRENCES OF separator IN itab-myline WITH
cl_abap_char_utilities=>horizontal_tab.
MODIFY itab.
ENDLOOP.
*----
Step 3
DATA : path LIKE pcfile-path.
path = filename.
CALL FUNCTION 'PC_SPLIT_COMPLETE_FILENAME'
EXPORTING
complete_filename = path
CHECK_DOS_FORMAT =
IMPORTING
DRIVE =
extension = extension
name = name
NAME_WITH_EXT =
PATH =
EXCEPTIONS
invalid_drive = 1
invalid_extension = 2
invalid_name = 3
invalid_path = 4
OTHERS = 5
.
*----
Step 4
newfilename = filename.
REPLACE name IN newfilename WITH 'temp'.
CALL FUNCTION 'GUI_DOWNLOAD'
EXPORTING
BIN_FILESIZE =
filename = newfilename
TABLES
data_tab = itab
FIELDNAMES =
.
*----
Step 5
CALL FUNCTION 'GUI_UPLOAD'
EXPORTING
filename = newfilename
has_field_separator = 'X'
TABLES
data_tab = orgtab.
ENDFORM. "myupload
3.
regards,
amit m.
‎2006 Jul 10 11:57 AM
If its a one time activity you can use the transactions CG3Z transactions.
‎2006 Jul 10 1:44 PM
Hi Madhu,
Use this function module
(Used to split the filename and the extension)
CV120_SPLIT_FILE
Please reward points if you find this as a right solution
Regards,
Harini
‎2006 Jul 10 1:56 PM
Please use the following logic.
This should upload the file from presentation server
TYPE-POOLS: TRUXS.
wa_rawdata type TRUXS_T_TEXT_DATA.
filename type RLGRAP-FILENAME
itab type (file structure )
CALL FUNCTION 'TEXT_CONVERT_CSV_TO_SAP'
EXPORTING
I_FIELD_SEPERATOR = ';'
i_tab_raw_data = wa_rawdata
I_FILENAME = filename
tables
i_tab_converted_data = itab
EXCEPTIONS
CONVERSION_FAILED = 1
OTHERS = 2
‎2006 Jul 10 3:33 PM
Thank you.
Can we read Excel file (xls format) into internal table?
I tried using FM "ALSM_EXCEL_TO_INTERNAL_TABLE". But I need to pass start collumn , end collumn, start row and End row, in this case. I won't be having information about end row. How can I use it? Is there any other FM which I could use?
Regrads,
Madhu
‎2006 Jul 10 3:44 PM
Hi For Excel Sheet you can use
CALL FUNCTION 'TEXT_CONVERT_XLS_TO_SAP'
EXPORTING
i_field_seperator = c_x
i_tab_raw_data = wa_rawdata
i_filename = p_f1
TABLES
i_tab_converted_data = i_excel
EXCEPTIONS
conversion_failed = 1
OTHERS = 2.
You dont have to give start and end column but you do have to define the internal table as in the same format as the sheet.
<b>Note : Please award points for all helpful answers</b>
Close the thread if solved
‎2006 Jul 10 3:49 PM