06-19-2008 11:31 AM
Hi,
I need to move a file in the application server from one Directory to another.Is there any function module for this purpose.
Regards,
Charumathi.B
06-19-2008 11:51 AM
Hi Friend,
Instead of any FM you can use this code :
Parameters: S_File type localfile default GIVE SOURCE FILEPATH,
D_File type localfile default GIVE DESTINATION FILEPATH.
data: begin of itab occurs 0,
rec(100) type c,
end of itab.
data: wa(100) type c.
start-of-selection.
open dataset S_File for input in text mode.
if sy-subrc = 0.
do.
read dataset S_File into wa.
if sy-subrc 0.
exit.
endif.
itab-rec = wa.
append itab.
enddo.
endif.
close dataset S_File.
open dataset D_File for output in text mode.
loop at itab.
transfer itab to D_File.
endloop.
close dataset D_File.
delete dataset S_File.
Regards
Hemant Khemani
06-19-2008 11:51 AM
Hi Friend,
Instead of any FM you can use this code :
Parameters: S_File type localfile default GIVE SOURCE FILEPATH,
D_File type localfile default GIVE DESTINATION FILEPATH.
data: begin of itab occurs 0,
rec(100) type c,
end of itab.
data: wa(100) type c.
start-of-selection.
open dataset S_File for input in text mode.
if sy-subrc = 0.
do.
read dataset S_File into wa.
if sy-subrc 0.
exit.
endif.
itab-rec = wa.
append itab.
enddo.
endif.
close dataset S_File.
open dataset D_File for output in text mode.
loop at itab.
transfer itab to D_File.
endloop.
close dataset D_File.
delete dataset S_File.
Regards
Hemant Khemani
08-21-2008 9:13 AM
Hi,
here a modified version for binary files and with buffering:
PARAMETERS:
s_file TYPE localfile DEFAULT '/tmp/xtest1.txt',
d_file TYPE localfile DEFAULT '/tmp/xtest2.txt'.
CONSTANTS:
c_buflen TYPE i VALUE 100.
DATA:
buf(100) TYPE x,
actlen TYPE i.
START-OF-SELECTION.
OPEN DATASET s_file FOR INPUT IN BINARY MODE.
IF sy-subrc = 0.
OPEN DATASET d_file FOR OUTPUT IN BINARY MODE.
IF sy-subrc = 0.
DO.
READ DATASET s_file INTO buf MAXIMUM LENGTH c_buflen ACTUAL LENGTH actlen.
IF actlen > 0.
TRANSFER buf TO d_file LENGTH actlen.
ELSE.
EXIT.
ENDIF.
ENDDO.
CLOSE DATASET d_file.
CLOSE DATASET s_file.
DELETE DATASET s_file.
ENDIF.
ENDIF.
regards,
Krzysztof
08-21-2008 9:42 AM
Use the below function module to move the file from one location to other location:
CALL FUNCTION 'ARCHIVFILE_SERVER_TO_SERVER'
EXPORTING
sourcepath = w_file
targetpath = lv_tgt_file
EXCEPTIONS
error_file = 1
OTHERS = 2.
IF sy-subrc <> 0.
MESSAGE ID sy-msgid TYPE c_s NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
EXIT.
ELSE.
DELETE DATASET w_file.
ENDIF.
Regards,
Kiran Bobbala
08-21-2008 9:48 AM
Another method is that you can download the file to your system and upload to another directory using transaction 'CG3Z' .
Regards
Sathar