2009 Apr 06 10:41 AM
Hey guys,
I'm using the FM GUI_UPLOAD to upload a .csv file from my pc to in internal table using the following code:
CALL FUNCTION 'GUI_UPLOAD'
EXPORTING
filename = gv_filename
has_field_separator = 'X'
TABLES
data_tab = itab
EXCEPTIONS
file_open_error = 1
file_read_error = 2
OTHERS = 17.
LOOP AT it_data
CLEAR it_csv.
SPLIT it_idata-rec AT ',' INTO it_csv-mandt
it_csv-field1
it_csv-field2
it_csv-field3.
APPEND it_csv
But after running the program my .csv file with this data:
MANDT field1 field2 field3
1000 1234 3042009 testtest
2000 4321 8723982 TESTTEST
Becomes this:
ÐÏ# ########## ##.##.#### #õÿ ##ø########À #######ÿ#######ÿ#######
### 00.00.0000
### ######## Í 00.00.0000
### 00.00.0000
### 00.00.0000
### 00.00.0000
### 00.00.0000
### 00.00.0000
### ######## Í 00.00.0000
### ######## Í ##.##.####
### #######P## . .###
### 00.00.0000
### 00.00.0000
Why is this happening and how do I solve it? Thanks in advance.
2009 Apr 06 10:47 AM
Hi Jeffrey,
Have you define the file name as the type String.
Also, when you passed the parameter field Separator give it as , (comma).
That should solve your purpose
2009 Apr 06 10:47 AM
Hi Jeffrey,
Have you define the file name as the type String.
Also, when you passed the parameter field Separator give it as , (comma).
That should solve your purpose
2009 Apr 06 10:50 AM
Hi Babu
Thanks for your fast response, but that didn't work. The filename is already a string and using a ',' as seperator doesn't fix the issue.
2009 Apr 06 11:03 AM
hi,
After using the FM GUI_upload . u need splite the data into another internal table do the spliting operation .
LOOP AT t_itab INTO w_itab.
SPLIT w_itab AT con_tab INTO w_file-f1
w_file-f2
w_file-f3
endloop.
like that ..
hope it help u ..
~linganna
2009 Apr 06 11:07 AM
Hi Jeffrey,
If you are reading file to table of string line type, you have to split it using hex value of the separator mark, like below:
DATA: it_data TYPE TABLE OF string WITH HEADER LINE.
DATA: BEGIN OF it_csv OCCURS 0,
mandt TYPE string,
field1 TYPE string,
field2 TYPE string,
field3 TYPE string,
END OF it_csv.
CALL FUNCTION 'GUI_UPLOAD'
EXPORTING
filename = 'C:\test.txt'
has_field_separator = 'X'
TABLES
data_tab = it_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.
CHECK sy-subrc = 0.
DATA: xsep TYPE xstring,
sep TYPE string.
xsep = '20'. "hex for space mark as separator, for tab mark it is '09'
CALL FUNCTION 'HR_KR_XSTRING_TO_STRING'
EXPORTING
in_xstring = xsep
IMPORTING
out_string = sep.
LOOP AT it_data.
SPLIT it_data AT sep INTO it_csv-mandt it_csv-field1 it_csv-field2 it_csv-field3.
ENDLOOP.
Regards
Marcin
2009 Apr 06 11:40 AM
@ katigiri
Thanks, but I already did that in my original code. I just didn't include it because the splitting has no effect on the encoded output.
@ Marcin Pciak
Thank for your answer but I'm afraid the FM 'HR_KR_XSTRING_TO_STRING' doesn't exist here. So I'm unable to call it.
@ Raymond Giuseppi
Thanks, I did this but it doesn't affect the output.
Thank you all for trying.
2009 Apr 06 1:10 PM
I found an OSS note [Note 1066919 - Showcase GUI_UPLOAD: Comma separated value (CSV) file|https://service.sap.com/sap/support/notes/1066919] but doesn't seem to rely on your problem.
So the problem may come from page codes, look at OSS [Note 1088209 - Help for troubleshooting: Code page display problems|https://service.sap.com/sap/support/notes/1088209]
Regards
2009 Apr 06 1:22 PM
Hey Raymond,
Thanks but it seems that site requires an id and password or something. Thanks for the effort.
For all other people: The problem is still there.
2009 Apr 06 2:01 PM
The Note : [Note 1088209 - Help for troubleshooting: Code page display problems|https://service.sap.com/sap/support/notes/1088209]
Symptom
You experience display problems after you download or upload data that
refers to an incorrect code page.
More Terms
GUI_DOWNLOAD, GUI_UPLOAD, garbled characters, character encoding
Cause and Prerequisites
This problem is caused by an incorrect code page when using GUI_DOWNLOAD
and GUI_UPLOAD.
Solution
Help for troubleshooting
This note provides support for customers with customer developments who,
for example, want to download ABAP lists to the PC for processing them with
Microsoft Office programs. This note also offers support to internal
application developers so that they can provide users with an interface for
the data transfer to or from the front end.
For this purpose, the methods of the class CL_GUI_FRONTEND_SERVICES=>
GUI_DOWNLOAD and GUI_UPLOAD are to be used. Both methods provide the
option of explicitly setting the code page as a parameter. The code page
contains the country-specific or language-specific assignment of characters
to their representation (screen, printer) using one or more bytes.
The code page that is to be used can generally be determined using the
following procedures:
o If a file from an SAP Unicode system is to be processed for a
single code page, the system uses the logon language to determine
the single-byte code page. You can change the current logon
language using the parameter SY-LANGU with the statement SET LOCALE
LANGUAGE <lang>. (Also see the table TCP01: Assignment of the
language to the single code page)
o As of SAP GUI 6.40, you have the option of using the interactive
file dialog with the methods FILE_OPEN or SAVE_DIALOG from the
class CL_GUI_FRONTEND_SERVICES. If these two methods are called
with the parameter WITH_ENCODING = 'X', the user can interactively
select the code page that is to be used in the dialog.
o As of SAP GUI 6.40, the code page for the PC file can also be set
by default. To do this, use SAPLogon or SAPShortcut. For this
purpose, you must select the system entry in the SAPLogon and then
choose "Change Entry" to switch to the "Code Page" tab page. On
this tab page, the code page setting for the upload or the download
can be set by default. (Caution: The language settings that are
further up on the same tab page do not affect the code page
for the download or the upload.)
In both methods GUI_DOWNLOAD and GUI_UPLOAD, internal processing of the
code page is still significantly affected by the additional parameter
SAP Note 1088209 -Help for troubleshooting: Code page display problems
Filetype:
o Filetype = 'IBM'
If you set this parameter, the system uses the code page 1103
(IBM-PC Multilingual 850) by default.
o FileType = 'DBF'
If the transferred parameter 'CODEPAGE' is initial, the system uses
the code page 1103 (IBM-PC Multilingual).
o Filetype = 'BIN'
No code page is used -- parameter is ignored.
o Filetype = 'ASC'
If no explicit code page is transferred, the system uses the code
page that is set in SAPLogon.
If the user does not select an explicit code page in the SAPLogon and
selects one of the two default entries instead, the following applies:
o If the user selects Default ANSI for UNICODE systems in the
SAPLogon, the system uses the code page for the current logon
language. (ANSI code page, no UNICODE code page)
o If the user selects Default UTF8 for UNICODE in the SAPLogon,
the system also uses the code page for the current logon language
in non-Unicode systems. For Unicode systems, UTF8 is automatically
set.
When you use GUI_UPLOAD, note the following:
o If no code page is transferred, the system first performs a BOM
check (byte order mark) to be able to identify a Unicode file.
o If the BOM check has a negative outcome, the system automatically
uses the code page you selected in the SAPLogon.
To identify the code page that is currently set, you can use the method
get_saplogon_encoding of the class CL_GUI_FRONTEND_SERVICES. This
method returns the code page that is currently set in the changing
parameter file_encoding (type abap_encoding).
Several typical error sources are:
o When you download a text with Filetype 'BIN' from a Unicode system,
blanks (blank characters) are created after each character:
This is not an error -- Unicode uses two bytes for each character:
Whether the "blank character" is in front of or behind the
character depends on whether the encoding is UTF-16 little endian
or UTF-16 big endian. The "blank character" (actually 0x00) mainly
occurs for the (American) standard ASCII characters.
There is no reason for a binary download of text.
o When you perform a Unicode download in UTF8 format, you must note
that most of the Microsoft Office applications cannot handle UTF8
encoding. (In UTF8, for example, umlauts are encoded with three
bytes.)
Conclusion
For customer developments that indicate a code page problem, the customer
should first check whether the correct code page was transferred to the two
methods GUI_DOWNLOAD and GUI_UPLOAD. You may require consulting concerning
the code page that is to be used because you have questions, such as:
o Which code page should be used for Cyrillic languages?
o Are the required code pages installed?
o The correct code page is used. However, the result is not
satisfactory. What should be done?
If this is the case, open a message for the component BC-I18. Explicit
questions about Unicode are handled under the component BC-I18-UNI.
Application developments should generally go through the same process:
Check whether the correct code page has been transferred and check whether
internal processing of the methods (described above) has been taken into
account.
If problems still occur (for example, conversion errors) or if a standard
function (for example, menu: System==>List==>Save) indicates problems, open
a message for the component BC-FES-GUI.
Regards
2009 Apr 06 3:36 PM
I'm sorry but that text contains no information on solving my problem, I've read it and tried some things but the error remains.
2009 Apr 08 7:04 PM
hi,
just check in the debug mode whether the internal table u r using in gui upload is having a correct string of values if not do the follwing:
create a structure with only one field which is of string type ...
declare a table of that structure type
types: begin of bst,
cool type string,
end of bst .
i_table type standard table of bst.
give the same table in table parameter of gui_upload ie i_table
now u want to move the data of i_table into another tabel lets say i_item
would suggest create a work area w_item with its structure same as i_item, use the same refrence which u have used for i_item. declare the table without header line
now use the same command which u have alrady used with work area and later append in the inetrnal table
but use spilt at "tab which u r giving" w_item -field1
w_item2-field2
append w_item into i_tem
note:
just for info
there is command from which u can pick the tab value from the system ( not sure of the command)
the command simply uses some class. "if the seprator is tab."
Edited by: sabsvk on Apr 8, 2009 8:06 PM
Edited by: sabsvk on Apr 8, 2009 8:07 PM
2009 Apr 09 7:48 AM
Thanks sabsvk but I'm afraid that also didn't work. My code is now as following:
REPORT z_csv_program.
*Types
TYPES: BEGIN OF zinfo,
rec(65000) TYPE c,
END OF zinfo.
TYPES:
BEGIN OF zcustomer,
mandt TYPE mandt,
businesspartner TYPE zpartner,
creationdate TYPE zerdat,
description TYPE zdescription,
END OF zcustomer,
BEGIN OF zcustomer_error,
businesspartner TYPE bu_partner,
creationdate TYPE zerdat,
description TYPE zdescription,
message TYPE crmmsgtext,
END OF zcustomer_error.
DATA : BEGIN OF i_partner_check OCCURS 0,
partner LIKE but000-partner,
END OF i_partner_check.
*Tables
DATA: it_klant TYPE TABLE OF zcustomer WITH HEADER LINE,
it_info TYPE TABLE OF zinfo WITH HEADER LINE,
it_klant_error TYPE TABLE OF zcustomer_error WITH HEADER LINE.
*Variables
DATA: gv_filename TYPE string,
*Work area's
DATA: wa_info TYPE zcustomer.
*Parameters
PARAMETERS: csv_file TYPE localfile.
*Call selection screen for document selection
AT SELECTION-SCREEN ON VALUE-REQUEST FOR csv_file.
*get file name
CALL FUNCTION 'KD_GET_FILENAME_ON_F4'
EXPORTING
field_name = ' '
CHANGING
file_name = csv_file
EXCEPTIONS
mask_too_long = 1
OTHERS = 2.
IF sy-subrc NE 0.
ENDIF.
START-OF-SELECTION.
Perform read external file
gv_filename = csv_file.
Upload .csv to internal table
CALL FUNCTION 'GUI_UPLOAD'
EXPORTING
filename = gv_filename
has_field_separator = 'X'
filetype = 'ASC'
TABLES
data_tab = it_klant
EXCEPTIONS
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.
WRITE:/ 'local file', gv_filename , 'could not be openend.'.
ENDIF.
IF sy-subrc <> 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.
END-OF-SELECTION.
And some more irrelevant pieces of code. I don't know anymore and think it would be better to try something else.
2009 Apr 20 2:47 PM
Hi jeffrey,
well its a distant guess, But have you changed the format of teh date anywhere .I mean there is a date field in the internal table(it_klant), The data you are passing is according to teh DATS format (8 charcters) and the uploaded data is in teh format of dd.mm.yyyy (10 characters)
Please debug watchfully and see what data is being passed baecuas according to current i guess the values 00.00.0000 is being passed due to setting of default data for date.)i.e whenevr no data fr date is passed).Please check , maybe you can find the error in upload,
Cheers !
Laveen
2009 Apr 06 11:08 AM
2009 Apr 10 7:02 AM
2009 Apr 10 7:07 AM
@ Chenna kesava
Thanks but SAP doesn't agree with you. When defining 'DAT' as Filetype I get the following error message: "parameter 'FILETYPE" has the wrong value".
2009 Apr 14 9:23 AM
hi ,
comment the filetype and has_field seprator..
the try to run the fm.
one additional note: u can use f4_filename function module too for file search help (browse).
one more observation if sy-subrc eq 0
then file can not be opend ???
if i am not wrong it shld be sy-subrc ne 0
then file can not be opened.
2009 Apr 14 12:19 PM
comment filetype and has field seprator and then run fm .
note: u cna use f4_filename fm for search help for file (browsing)
one observation:
if sy-subrc eq 0
file not created
i think it shld be
if sy-subrc ne 0
file not created
2009 Apr 14 12:25 PM
Thanks sabsvk
But that doesn't work for me. I already started working on another way around this issue so thanks you all for the help.