05-05-2006 2:34 PM
Hello ABAP Experts,
I have a requirement to read a text file containing three fields and read them into the internal table. Could you show me a sample code.
Any help is highly appreciated.
Any docs or code mail to mgmswsol@gmail.com
Thanks,
BWer
05-05-2006 2:49 PM
Hello,
Just create an internal table with your 3 fields
data: begin of ti_data occurs 0,
fld1 type c,
fld2 type c,
fld3 type c,
end of ti_data.
To read the file just call this FM:
ALL FUNCTION 'TB_LIMIT_WS_UPLOAD'
EXPORTING
filename = Root to your file
filetype = 'ASC'
IMPORTING
filelength = length
TABLES
data_tab = ti_data.
IF sy-subrc <> 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.
Hope this helps
Gabriel
05-05-2006 2:36 PM
Hi,
use the function gui_upload to do the same.
data:begin of i_data occurs 0,
uomcode(2),
uomvalue(30),
end of i_data.
call function 'GUI_UPLOAD'
exporting
filename = 'C:\test.txt'
FILETYPE = 'ASC'
HAS_FIELD_SEPARATOR = '#'
HEADER_LENGTH = 0
READ_BY_LINE = 'X'
DAT_MODE = ' '
CODEPAGE = ' '
IGNORE_CERR = ABAP_TRUE
REPLACEMENT = '#'
CHECK_BOM = ' '
IMPORTING
FILELENGTH =
HEADER =
tables
data_tab = i_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
.
05-05-2006 2:37 PM
to upload the file
CALL FUNCTION 'GUI_UPLOAD'
EXPORTING
filename = l_file
filetype = 'ASC'
has_field_separator = 'X'
TABLES
data_tab = i_flatfile
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.
where i_flatfile has the starusture comprising of the 3 fields you are talking of.
Then directly assign the fields i_flatfile-field1 , field2 etc...
05-05-2006 2:43 PM
Is the file on the PC or the app server?
Rob
05-05-2006 3:23 PM
Rob,
what would be difference in the code to read the file from the pc against the application server.. ?
Thanks,
BWer
05-05-2006 3:26 PM
hi BWer,
if u want to read the file from application server u use <b>open dataset for input</b> else if u want to read it from presentation then you use <b>GUI_DOWNLOAD</b>...
Regards,
Santosh
05-05-2006 3:47 PM
Entirely different situation. GUI_UPLOAD won't work from the app server. You would ahve to use open dataset and transfer in that case.
So, is it on the app server?
Rob
05-05-2006 2:49 PM
Hello,
Just create an internal table with your 3 fields
data: begin of ti_data occurs 0,
fld1 type c,
fld2 type c,
fld3 type c,
end of ti_data.
To read the file just call this FM:
ALL FUNCTION 'TB_LIMIT_WS_UPLOAD'
EXPORTING
filename = Root to your file
filetype = 'ASC'
IMPORTING
filelength = length
TABLES
data_tab = ti_data.
IF sy-subrc <> 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.
Hope this helps
Gabriel
05-05-2006 3:41 PM