2005 Sep 23 2:37 PM
Hi all,
i am stucked at one point while uploading file from desktop to application server.
I have uploaded multiple files but not able to save them with different names. when i upload files i have to save them dynamically with their names.for ex:
if i have uploaded 3 files together..abc.txt,,abc1.txt,,abc2.txt...
then they should save at server with their names...but
the logic that i have built is appending all the data in one file..
the logic of my code is::;
DATA: BEGIN OF t_itab OCCURS 0,
file(1000) type c,
END OF t_itab.
select-options l_file for rlgrap-filename no intervals.
loop at l_file.
CALL FUNCTION 'WS_UPLOAD'
EXPORTING
CODEPAGE = ' '
FILENAME = l_file-low
FILETYPE = 'ASC'
HEADLEN = ' '
LINE_EXIT = ' '
TRUNCLEN = ' '
USER_FORM = ' '
USER_PROG = ' '
DAT_D_FORMAT = ' '
TABLES
data_tab = t_itab
IF sy-subrc <> 0.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
open dataset in_file FOR OUTPUT IN TEXT MODE ENCODING DEFAULT.
LOOP AT t_itab.
TRANSFER t_itab TO in_file .
ENDLOOP.
if sy-subrc eq 0.
write:/ 'success'.
endif.
CLOSE DATASET in_file.
endloop.
this is the logic that i have built. its working good but appending the data into one file...
plz can anyone should suggest the corrections for that..means to say the logic..
thanks in advance
2005 Sep 23 2:43 PM
Hi all,
i am stucked at one point while uploading file from desktop to application server.
I have uploaded multiple files but not able to save them with different names. when i upload files i have to save them dynamically with their names.for ex:
if i have uploaded 3 files together..abc.txt,,abc1.txt,,abc2.txt...
then they should save at server with their names...but
the logic that i have built is appending all the data in one file..
the logic of my code is::;
DATA: BEGIN OF t_itab OCCURS 0,
file(1000) type c,
END OF t_itab.
select-options l_file for rlgrap-filename no intervals.
loop at l_file.
CALL FUNCTION 'WS_UPLOAD'
EXPORTING
CODEPAGE = ' '
FILENAME = l_file-low
FILETYPE = 'ASC'
HEADLEN = ' '
LINE_EXIT = ' '
TRUNCLEN = ' '
USER_FORM = ' '
USER_PROG = ' '
DAT_D_FORMAT = ' '
TABLES
data_tab = t_itab
IF sy-subrc <> 0.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
open dataset in_file FOR OUTPUT IN TEXT MODE ENCODING DEFAULT.
LOOP AT t_itab.
TRANSFER t_itab TO in_file .
ENDLOOP.
if sy-subrc eq 0.
write:/ 'success'.
endif.
CLOSE DATASET in_file.
endloop.
this is the logic that i have built. its working good but appending the data into one file...
plz can anyone should suggest the corrections for that..means to say the logic..
thanks in advance
2005 Sep 23 2:43 PM
2005 Sep 23 2:47 PM
Check this out.......
report zrich_0002
no standard page heading.
tables: rlgrap.
data: begin of t_itab occurs 0,
file(1000) type c,
end of t_itab.
data: in_file type localfile value '/usr/sap/TST/SYS/'.
data: stripped type rlgrap-filename.
data: file_path type rlgrap-filename.
select-options l_file for rlgrap-filename no intervals.
loop at l_file.
call function 'WS_UPLOAD'
exporting
codepage = ' '
filename = l_file-low
filetype = 'ASC'
headlen = ' '
line_exit = ' '
trunclen = ' '
user_form = ' '
user_prog = ' '
dat_d_format = ' '
tables
data_tab = t_itab.
if sy-subrc <> 0.
message id sy-msgid type sy-msgty number sy-msgno
with sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
endif.
* Here get the file name from the file path/name
call function 'SO_SPLIT_FILE_AND_PATH'
exporting
full_name = l_file-low
importing
stripped_name = stripped
file_path = file_path.
* Use the file name as your file name on the app server
* I am assuming that in_File already has the file path to
* the app server here, just take the file path of app
* server and the file name from presentation and
* put them together.
concatenate in_file stripped into in_file.
open dataset in_file for output in text mode.
loop at t_itab.
transfer t_itab to in_file .
endloop.
if sy-subrc eq 0.
write:/ 'success'.
endif.
close dataset in_file.
endloop.
I updated the code a bit
Regards,
Rich Heilman
Message was edited by: Rich Heilman
2005 Sep 23 3:01 PM
hello rich
i have tried the logic that u have forwared it working but i am still facing problem while upload...
Problem that facing now is::
if i am uploading single file its working good.
but if i am uploading 2 or 3 files together then all the file names are conactenating together and that data is coming in one file..
i have to write the each upload file independently...
can you please help in this...
it will be great help...
as its my urgent requierment
2005 Sep 23 3:08 PM
Oh yes, sorry.......
report zrich_0002
no standard page heading.
tables: rlgrap.
data: begin of t_itab occurs 0,
file(1000) type c,
end of t_itab.
data: in_file type localfile value '/usr/sap/TST/SYS/'.
data: stripped type rlgrap-filename.
data: file_path type rlgrap-filename.
<b>data: new_file_name type rlgrap-filename.</b>
select-options l_file for rlgrap-filename no intervals.
loop at l_file.
call function 'WS_UPLOAD'
exporting
codepage = ' '
filename = l_file-low
filetype = 'ASC'
headlen = ' '
line_exit = ' '
trunclen = ' '
user_form = ' '
user_prog = ' '
dat_d_format = ' '
tables
data_tab = t_itab.
if sy-subrc <> 0.
message id sy-msgid type sy-msgty number sy-msgno
with sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
endif.
* Here get the file name from the file path/name
call function 'SO_SPLIT_FILE_AND_PATH'
exporting
full_name = l_file-low
importing
stripped_name = stripped
file_path = file_path.
* Use the file name as your file name on the app server
* I am assuming that in_File already has the file path to
* the app server here, just take the file path of app
* server and the file name from presentation and
* put them together.
<b>clear new_file_name.
concatenate in_file stripped into new_file_name.
open dataset new_file_name for output in text mode.</b>
loop at t_itab.
transfer t_itab to in_file .
endloop.
if sy-subrc eq 0.
write:/ 'success'.
endif.
close dataset in_file.
endloop.
Regards,
Rich Heilman
2005 Sep 23 3:42 PM
hi rich
that was really great...thanks for all support...that really solved my query...
if possible just one help more...
if i have to check ..that if file exsits then i have to append date with the file name.
canu help on this also..
it will be great ..
thanks
2005 Sep 23 3:50 PM
Sure, try something like this.
report zrich_0002
no standard page heading.
tables: rlgrap.
data: begin of t_itab occurs 0,
file(1000) type c,
end of t_itab.
data: in_file type localfile value '/usr/sap/TST/SYS/'.
data: stripped type rlgrap-filename.
data: file_path type rlgrap-filename.
data: new_file_name type rlgrap-filename.
select-options l_file for rlgrap-filename no intervals.
loop at l_file.
call function 'WS_UPLOAD'
exporting
codepage = ' '
filename = l_file-low
filetype = 'ASC'
headlen = ' '
line_exit = ' '
trunclen = ' '
user_form = ' '
user_prog = ' '
dat_d_format = ' '
tables
data_tab = t_itab.
if sy-subrc <> 0.
message id sy-msgid type sy-msgty number sy-msgno
with sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
endif.
* Here get the file name from the file path/name
call function 'SO_SPLIT_FILE_AND_PATH'
exporting
full_name = l_file-low
importing
stripped_name = stripped
file_path = file_path.
* Use the file name as your file name on the app server
* I am assuming that in_File already has the file path to
* the app server here, just take the file path of app
* server and the file name from presentation and
* put them together.
clear new_file_name.
concatenate in_file stripped into new_file_name.
* Here we are checking for the file existance, if it has
* been opened sucessfully, then close it, and add the
* date to the file name and open that file.
<b> open dataset new_file_name.
if sy-subrc = 0.
close dataset new_file_name.
endif.
concatenate new_file_name sy-datum into new_file_name.</b>
open dataset new_file_name for output in text mode.
loop at t_itab.
transfer t_itab to new_file_name .
endloop.
if sy-subrc eq 0.
write:/ 'success'.
endif.
close dataset new_file_name.
endloop.
2005 Sep 23 3:55 PM
hi
thats really great of u...
thanks for all ur support..
thanks ..thanks sir
2005 Sep 23 3:59 PM
2005 Oct 04 6:17 AM
hi rich
can you please help in this open dataset...
if i have to upload same file name 2 times i am able to do that. But if i have to upload same file name 4 0r 5 times i am not able to built a code for that.
User can upload ame file name 10 or 12 times together. And i have to save the file in application server in this format.._2 _2 _2 _2 for all file name that are having same name...
so plz can u suggest the logic for that...
*check for exsistency of file
open dataset new_file_name for update IN TEXT MODE encoding default.
if sy-subrc = 0.
*if exists then append 2 again with the new filename
concatenate new_file_name '2' into new_file_name
separated by '_'.
close dataset new_file_name.
endif.
open dataset new_file_name for output in text mode encoding default.
*looping on Internal table to write all data
loop at t_itab.
transfer t_itab to new_file_name .
endloop.
the above logic is working for two but not for multiples file that have same file name..
so plz can u suggest
2005 Sep 23 2:43 PM
Hi,
You have to change "in_file" also inside the loop every time.
you have to fill "in_file" at the very end with l_file-low for each loop pass..
Sri
2005 Sep 23 2:45 PM
You are missing one line I guess
<u>in_file = i_file-low.</u>
open dataset in_file FOR OUTPUT IN TEXT MODE ENCODING DEFAULT.
Cheers
2005 Sep 23 3:09 PM
Use
CLear In_file .
concatenate in_file stripped into in_file
2005 Sep 23 3:11 PM
2005 Sep 23 3:12 PM
Here get the file name from the file path/name
call function 'SO_SPLIT_FILE_AND_PATH'
exporting
full_name = l_file-low
importing
stripped_name = stripped
file_path = file_path.
Use the file name as your file name on the app server
I am assuming that in_File already has the file path to
the app server here, just take the file path of app
server and the file name from presentation and
put them together.
<b>clear in_file.</b>
clear new_file_name.
concatenate in_file stripped into new_file_name.
open dataset new_file_name for output in text mode.
loop at t_itab.
transfer t_itab to <b>new_file_name</b> .
endloop.
if sy-subrc eq 0.
write:/ 'success'.
endif.
close dataset in_file.
endloop.
| User | Count |
|---|---|
| 6 | |
| 2 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 |