Copying/Renaming a file in Application Server

By | October 14, 2011 | Utilities | 8,121 | 2

A number of times we want to copy or rename files in Application Server as per our requirements. However making changes to files in application server is not as easy as on Presentation Server.

I recently came across one such scenario while finding the answer saw a number of solutions. Some were to create a UNIX system command to move the files. Other was use of some function modules.

In the end Classes came to the rescue again and the below is the solution I used:

REPORT  ZAPP_FILE.

CALL METHOD cl_cts_language_file_io=>copy_files_local
  EXPORTING
    im_source_file           = 'Test.txt'
    im_source_directory      = '/olddir'
    im_target_file           = 'TestNew.txt'
    im_target_directory      = '/newdir'
*    im_overwrite_mode        = SPACE
*  IMPORTING
*    ex_file_size             =
  EXCEPTIONS
    open_input_file_failed   = 1
    open_output_file_failed  = 2
    write_block_failed       = 3
    read_block_failed        = 4
    close_output_file_failed = 5
    others                   6.

DELETE DATASET '/newdir/Test.txt'.

The above method call will create a new copy of the file Test.txt to TestNew.txt. The Source and Destination directory can be same or different.
If you want to rename the file then delete the previous file ‘Test.txt’ as in our example above.

Like It? Share!!

Don't miss an Update

Get notified of the new post, right into your inbox

Abhishek Periwal{2 articles}


Explore all of his 2 articles.

Load comments

2 Comments

  • Anil Palakala

    Hi Abhishek,
    Can you please provide complete program. This will help others?
    Regards,
    AK

  • Abhishek Periwal

    Anil,

    This is a complete program assuming the files are present in the App Server. If you want me to post more details then do let me know.

    Thanks,
    Abhishek

Comments on this Post are now closed. If you have something important to share, you can always contact me.

You seem to be new here. Subscribe to stay connected.