04-29-2009 6:25 PM
Hi all you experts!
I need to create a program that Copy or Rename a file in Application Server. For instance I have file A.ext_00 and I want to copy/rename it to A.ext (with out _00).
Does any of you have done that before? Sample code will be really appreciate it. Thank you in advance.
04-29-2009 6:39 PM
04-29-2009 6:33 PM
you can import the file with OPEN DATA SET and create a new file with other name and them delete the old file.
04-29-2009 6:34 PM
04-29-2009 6:35 PM
hi ,
there is not command to rename the file in application server.
but you can read the file..
* Open external file
OPEN DATASET NYFIL FOR INPUT IN TEXT MODE.
* Read file into internal table
DO.
READ DATASET NYFIL INTO ITAB.
APPEND ITAB.
IF SY-SUBRC <> 0.
EXIT.
ENDIF.
ENDDO.
* Close file
CLOSE DATASET NYFIL.
and keep in internal table..
and delete the application file..
* Delete file from host
delete dataset hostfile.
and again insert the application file with new name..
OPEN DATASET p_fname FOR OUTPUT in text mode.
loop at itab.
transfer itab.
endloop.
CLOSE DATASET p_fname.
regards,
Prabhudas
04-29-2009 6:39 PM
04-30-2009 12:18 AM
Thank you guys for your suggestions. Special thanks to J@Y, the links you shared me helped me to find Function Module STRALAN_COPY_FILES.
Here is the code I used to copy files in Application Server. I needed to rename files, since there is not a native way to do it I first created a copy of the file and then deleted the original file using 'DELETE DATASET'.
CALL FUNCTION 'STRALAN_COPY_FILES'
EXPORTING
iv_source_file = l_source_f
iv_source_directory = l_source_d
iv_target_file = l_target_f
iv_target_directory = l_target_d
* IV_OVERWRITE_MODE = ' '
* IMPORTING
* EV_FILE_SIZE =
EXCEPTIONS
open_input_file_failed = 1
open_output_file_failed = 2
read_block_failed = 3
write_block_failed = 4
close_output_file_failed = 5
invalid_file_size = 6
invalid_input_file_size = 7
others = 8.
DELETE DATASET l_original_file.
Thank you so much for your help.