‎2007 Apr 27 8:53 AM
when i call the function gui_upload then it cannot read filetype"'TXT" or "DAT".
it only read "ASC". if i give filetype "TXT" or "DAT" exception 5 occur. please check the code..
CALL FUNCTION 'GUI_UPLOAD'
EXPORTING
filename = 'C:\test.txt'
FILETYPE = 'TXT'
HAS_FIELD_SEPARATOR = 'X'
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 = 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
.
<b>test.txt file:</b>
bp11 lf11 d004 100
bp12 lf12 d005 2000
bp13 lf01 d003 2332
bp14 lf01 d003 2332
bp12 lf12 d005 1000
Regards
Reema jain
‎2007 Apr 27 9:02 AM
Hi Reema,
In the FM kepp value of Filetype = 'ASC', using this u can also upload the .txt files.
I think this will help u.
Reward Points if helpful.
Regards
Nilesh
‎2007 Apr 27 8:54 AM
Hi,
Please keep the filetype parameter as "ASC" even if you are uploading a TXT file.
Best regards,
Prashant
‎2007 Apr 27 9:09 AM
Hi,
If i Keep the filetype parameter as "ASC" then it pick the wrong data from the file...
Regards
Reema jain
‎2007 Apr 27 8:58 AM
hi,
There is no TXT Type .. so give either ASC OR DAT or BIN type as follows
CALL FUNCTION 'GUI_UPLOAD'
EXPORTING
filename = 'C:test.txt'
FILETYPE = 'DAT'
HAS_FIELD_SEPARATOR = 'X'
* 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 = 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
‎2007 Apr 27 9:07 AM
Hi
As i have already mentioned dat filetype also throw a same exception.. If i used asc then it will pick some wrong data..
Regards
Reema jain
‎2007 Apr 27 9:00 AM
hi Reema,
Here is something from help
File Type (ASC or BIN)
Description
Describes how the upload file is read.
Value range
o 'BIN'
A binary representation of the internal table is read from the file.
No conversion or interpretation is carried out. Usually, this produces
meaningful results only if the internal table consists of a single
column of type 'X'.
o 'DAT'
The components of the internal table are filled from the file. If the
table contains more than one column, the entries in the file must be
separated by tabs. Conversion exits are not carried out.
For the different data types, the following applies:
- I or N or P or F
The numbers must be formatted according to the decimal representation
defined in the user settings.
- D
The date must be formatted according to the date format defined in
the
user settings.
- T
The time must have format hh:mm:ss.
o 'ASC'.
The components of the internal table are filled from the file. Only data
types of fixed length are allowed. The data must be contained on the
file in its entire length.
Default
ASC
Regards,
Santosh
‎2007 Apr 27 9:01 AM
Hi,
You have the extension for the filename as TXT but not the FILETYPE
check out the available filetypes
'ASC' :
ASCII format. The table is transferred as text. The conversion exits are
carried out. The output format additionally depends on the parameters
CODEPAGE, TRUNC_TRAILING_BLANKS, and TRUNC_TRAILING_BLANKS_EOL.
'IBM' :
ASCII format with IBM codepage conversion (DOS). This format corresponds
to the 'ASC' format when using target codepage 1103. This codepage is
often used for data exchange by disc.
'DAT' :
Column-by-column transfer. With this format, the data is transferred as
with ASC text. However, no conversion exists are carried out and the
columns are separated by tab characters. This format creates files that
can be uploaded again with gui_upload or ws_upload.
'DBF' :
The data is downloaded in dBase format. Because in this format the file
types of the individual columns are included, import problems, for
example, into Microsoft Excel can be avoided, especially when
interpreting numeric values.
'WK1' :
The data is downloaded in Lotus 1-2-3 format.
'BIN' :
Binary format. The data is transferred in binary format. There is no
formatting and no codepage conversion. The data is interpreted row by
row and not formatted in columns. Specify the length of the data in
parameter BIN_FILESIZE. The table should consist of a column of type X,
because especially in Unicode systems the conversion of structured data
into binary data leads to errors.
‎2007 Apr 27 9:02 AM
Hi Reema,
In the FM kepp value of Filetype = 'ASC', using this u can also upload the .txt files.
I think this will help u.
Reward Points if helpful.
Regards
Nilesh
‎2007 Apr 27 9:02 AM
Try with this
w_nom = 'C:\test.txt'
CALL FUNCTION 'FILE_GET_NAME'
EXPORTING
logical_filename = w_nom
parameter_1 =
IMPORTING
file_name = w_fichier
EXCEPTIONS
file_not_found = 1
OTHERS = 2.
OPEN DATASET w_fichier FOR input IN TEXT MODE ENCODING DEFAULT.
IF SY-SUBRC NE 0.
<b> APPEND error msg</b>
ELSE.
do.
READ DATASET w_fichier INTO ws_file.
IF sy-SUBRC = 0.
APPEND ws_file TO wt_file.
else.
exit.
ENDIF.
enddo.
ENDIF.
CLOSE DATASET w_fichier .
Hope this helps you,
Reward if helpful,
Regards,
Sooness!
‎2007 Apr 27 9:11 AM
Hii,
I am reading the file from the presentation server only...
Regards,
Reema jain.
‎2007 Apr 27 9:15 AM
Hi,
If for filtype ASC, wrong data is uploaded, then recreate the TXT file which you are uploading. Create the file in Excel and goto File->Save as-> select file type as TAB delimited and save the file with .txt extension.
Now try to upload the file.
Best regards,
Prashant
‎2007 Apr 27 9:21 AM
Hi,
Use the method of the cl_gui_frontend_services class....check the following sample code...its working for file directly created from notepad
data lv_bukrs type bukrs.
data itab type table of bukrs with header line.
CALL METHOD cl_gui_frontend_services=>gui_upload
EXPORTING
FILENAME = 'C:\test.txt'
FILETYPE = 'ASC'
HAS_FIELD_SEPARATOR = 'X'
HEADER_LENGTH = 0
READ_BY_LINE = 'X'
DAT_MODE = SPACE
CODEPAGE = SPACE
IGNORE_CERR = ABAP_TRUE
REPLACEMENT = '#'
VIRUS_SCAN_PROFILE =
IMPORTING
FILELENGTH =
HEADER =
CHANGING
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
NOT_SUPPORTED_BY_GUI = 17
ERROR_NO_GUI = 18
others = 19
.
IF sy-subrc <> 0.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
write 😕 sy-subrc.
loop at itab.
write 😕 itab.
endloop.
my file has the following entries
BP01
BP02
BP03
BP04
BP05
‎2007 Apr 27 9:45 AM
Hi,
It works but dat filetype still throw an exception..
Regards
Reema jain.
‎2007 Apr 27 9:32 AM
Hi Reema,
Do the following to get the correct data in upload.
Open excel, Write the flat file data. Save the file as TAB DELIMITED (.TXT)
Then use GUI_UPLOAD as follows:
CALL FUNCTION 'GUI_UPLOAD'
EXPORTING
FILENAME = 'C:\test.txt'
FILETYPE = 'ASC'
HAS_FIELD_SEPARATOR = 'X'
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 = 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
.
Also your internal table should be having the appropriate field length.
Try this. & don't forget to give points.
Regards,
Hemant.