‎2006 Oct 17 6:43 AM
Hi,all.
there,a problem in my pg.
I want to upload a txt file from local,and i used the GUI_UPLOAD FM to deal with it.But a mistake appears.
<b>'Cannot interpret data in file'</b>.
parts of the code as follows:
CALL FUNCTION 'GUI_UPLOAD'
EXPORTING
FILENAME = gv_file
FILETYPE = 'ASC'
HAS_FIELD_SEPARATOR = ' '
HEADER_LENGTH = 0
READ_BY_LINE = 'X'
DAT_MODE = ' '
CODEPAGE = ' '
IGNORE_CERR = ABAP_TRUE
REPLACEMENT = '#'
CHECK_BOM = ' '
VIRUS_SCAN_PROFILE =
NO_AUTH_CHECK = ' '
IMPORTING
FILELENGTH =
HEADER =
TABLES
DATA_TAB = in_tab
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
and the data in the file are came from table SPFLI,separated by SAPCE.
THANKS.
‎2006 Oct 17 6:45 AM
Hi,
WELCOME TO SDN
Modify the code accordingly ..
CALL FUNCTION 'GUI_UPLOAD'
EXPORTING
FILENAME = gv_file
<b> FILETYPE = 'ASC'</b> <--- 'ASC' or 'DAT'
HAS_FIELD_SEPARATOR = ' '
HEADER_LENGTH = 0
READ_BY_LINE = 'X'
DAT_MODE = ' '
CODEPAGE = ' '
IGNORE_CERR = ABAP_TRUE
REPLACEMENT = '#'
CHECK_BOM = ' '
VIRUS_SCAN_PROFILE =
NO_AUTH_CHECK = ' '
IMPORTING
FILELENGTH =
HEADER =
TABLES
DATA_TAB = in_tab
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
Regards,
Santosh
‎2006 Oct 17 6:46 AM
HI,
if the file have separator then use.
<b> HAS_FIELD_SEPARATOR = 'X'</b>
REgards,
‎2006 Oct 17 6:48 AM
hi lei,
simple chk this sample code.
types: begin of ttab,
rec(1000) type c,
end of ttab.
types: begin of tdat,
fld1(10) type c,
fld2(10) type c,
fld3(10) type c,
end of tdat.
data: itab type table of ttab with header line.
data: idat type table of tdat with header line.
data: file_str type string.
parameters: p_file type localfile.
at selection-screen on value-request for p_file.
call function 'KD_GET_FILENAME_ON_F4'
exporting
static = 'X'
changing
file_name = p_file.
start-of-selection.
file_str = p_file.
call function 'GUI_UPLOAD'
exporting
filename = file_str
tables
data_tab = itab
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.
delete itab index 1.
loop at itab.
clear idat.
split itab-rec at cl_abap_char_utilities=>horizontal_tab
into idat-fld1
idat-fld2
idat-fld3.
append idat.
endloop.
loop at idat.
write:/ idat-fld1, idat-fld2, idat-fld3.
endloop.
regards,
anver
pls mark all hlpful answers
‎2007 Jan 05 4:15 AM
Hi Anver,
I have to upload a flat file with multiple records into an internal table.for that I used the GUI_UPLOAD.I have used the same example which you have specified.The flat file contains the field separate ~.So i have activated the HAS_FIELD_SEPARATOR = 'X'.
The file in local server to be uploaded in internal table as follows :
XXXXXXXX~~Export file
2~19980501~19980531
// The first invoice:
0~00130698114000010004119980512059611000276233.350.1711076.66????321000789010005???????????????????130601000000000??????????18? 3352051????532611-3357211???~~~
0~????????176233.350.1711076.6676233.350~1510
// The second invoice:
0~00130698114000010007219980512059611000440482.000.175882.00????110108078901007?????????61? 68744479?????????????462088-07?????130601000000000??????????18? 3352051????532611-3357211???????????~~~
0~????????139780.000.175780.0039780.000~1510
0~????3.5"10702.000.17102.0070.20~1510
But the output which i am getting is with field separate and only first 10 character in the vertical column.
I am unable to understand why this is happening.And more over i have several records with each of more then 20 fields.
XXXXXXXX~~
2~~1998050
// The fir
0~00~1
0~????~?
// The sec
0~00~1
0~????~?
0~????
Please help me on this how should i upload multiple records in internal table from a local server using GUI_UPLOAD .
Thank you,
Best regards,
Priya
‎2006 Oct 17 7:35 AM
Thanks for your help.
As your advice, I modified my pg,but still wrong.
I simplified my pg,show it as follows,
tables: spfli.
data:gv_file type string.
data: in_tab like standard table of spfli with header line.
SELECTION-SCREEN BEGIN OF BLOCK b1 WITH FRAME TITLE text-001.
PARAMETERS: p_file LIKE rlgrap-filename obligatory.
SELECTION-SCREEN END OF BLOCK b1.
AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_file.
call function 'KD_GET_FILENAME_ON_F4'
EXPORTING
static = 'X'
CHANGING
file_name = p_file.
START-OF-SELECTION.
P_FILE is not compatible with the FM GUI_UPLOAD, so pass it to GV_FILE.
gv_file = p_file.
call function 'GUI_UPLOAD'
exporting
filename = gv_file
filetype = 'ASC'
HAS_FIELD_SEPARATOR = 'X'
tables
data_tab = in_tab.
loop at in_tab.
write: / in_tab-carrid, in_tab-cityto.
endloop.
the pg above can not run correctly,the mistake is still
'Cannot interpret data in file'.
but when add a statement
filetype = 'BIN'
it passed,but the data can not show correctly.
THANKS.
‎2006 Oct 17 7:43 AM
hi Xiang,
Keep the filetype is 'ASC' and remove HAS_FIELD_SEPARATOR = 'X and check now i guess it shoudl work if the fields are not separated with tab spaces ..
Reward if it helps...
Regards.
Santosh
‎2006 Oct 17 7:40 AM
THE FILE IS ASCII TYPE, SO THE data should be separated by tab space.
u just check whether there is tab space between each filed.
try creating file again wioth tab space and then try uploading
‎2006 Oct 17 7:46 AM
Hi,
Provide the flat file with data here.
I thikn the problem is with the flat file you are trying to upload
regards,
‎2006 Oct 17 8:03 AM
OK,there is the content of the file :
AA 0018 US NEW YORK JFK US SAN FRANCISCO SFO 361 13:00:00 16:01:00 "2.572,0000" MI 0
AA 0064 US SAN FRANCISCO SFO US NEW YORK JFK 321 10:00:00 18:21:00 "2.572,0000" MI 0
BB 0010 US NEW YORK JFK US SAN FRANCISCO SFO 361 11:00:00 14:11:00 "2.572,0000" MI 0
AA 0064 US SAN FRANCISCO JFK US NEW YORK SFO 321 10:00:00 18:21:00 "2.572,0000" MI 0
‎2006 Oct 17 8:28 AM
Hi lei,
1. It seems the file is not tab delimited,
rather it is fixed width file.
2. hence, do not pass the parameter
HAS_FIELD_SEPARATOR = 'X'
call function 'GUI_UPLOAD'
exporting
filename = gv_file
filetype = 'ASC'
tables
data_tab = in_tab.
regards,
amit m.
‎2006 Oct 17 8:07 AM
‎2006 Oct 17 8:33 AM
I am sorry ,I still not solve this problem,I modified it as all of the ways above.
In the flie,SPACE are exist between fileds
‎2006 Oct 17 9:03 AM
Hi,
Create flat file with tabdelimitor and give HAS_FIELD_SEPARATOR = 'X' in FM.
EX 123 wer
here the space between these two must be a tb space .
ok
regards,
‎2006 Dec 08 1:02 AM