Application Development Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 

Rename or Copy files in Application Server

Former Member
0 Kudos

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.

1 ACCEPTED SOLUTION

former_member156446
Active Contributor
0 Kudos

5 REPLIES 5

Former Member
0 Kudos

you can import the file with OPEN DATA SET and create a new file with other name and them delete the old file.

Former Member
0 Kudos

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

former_member156446
Active Contributor
0 Kudos

0 Kudos

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.