on 09-07-2007 5:17 PM
I'm new to ABAP. I got a zuploadtab program from a contributor to this forum which uploads a text file into SAP. It works just fine. I would like to know two things, tho:
1. How can I alter the program so that it can accept a file with about 8 fields (4 char, 3 int, 1 curr) and they are seperated by a comma (comma delimited, i guess) into an internal table.
2. How can I then insert these into a real? database table?
Here is an example. Uploading from application server.
report zrich_0001.
data: str type string.
data: begin of itab occurs 0,
fld1(10) type c,
fld2(10) type c,
fld3(10) type c,
end of itab.
data:
dsn(100) value '/usr/sap/TST/sys/test.txt'.
clear itab. refresh itab.
* Read the data.
open dataset dsn for input in binary mode.
do.
read dataset dsn into str.
if sy-subrc = 0.
split str at ',' into itab-fld1 itab-fld2 itab-fld3.
append itab.
else.
exit.
endif.
enddo.
close dataset dsn.
Loop at itab.
write:/ itab-fld1, itab-fld2, itab-fld3.
endloop.
UPloading from frontend.
report zrich_0001.
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.
loop at itab.
clear idat.
split itab-rec at ',' into idat-fld1
idat-fld2
idat-fld3.
append idat.
endloop.
loop at idat.
write:/ idat-fld1, idat-fld2, idat-fld3.
endloop.
Regards,
RIch Heilman
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
93 | |
10 | |
10 | |
9 | |
9 | |
7 | |
6 | |
5 | |
5 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.