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: 

Renaming a file stored at the application server.

Former Member
0 Kudos
294

Is there a function module to rename a file stored at the application server? Or a system command that can be executed within ABAP?

1 ACCEPTED SOLUTION

Former Member
0 Kudos
72

The earlier reply is an excellent way to do it. Another way to do this is by using the SYSTEM command/function as follows :

DATA: unix_command(500)

DATA: BEGIN OF itab OCCURS 0,

LINE(255),

END OF itab.

concatenate 'mv' source_file dest_file into unix_command separated by space.

CALL 'SYSTEM' ID 'COMMAND' FIELD COMMAND ID 'ITAB' FIELD TABM-SYS.

3 REPLIES 3

RichHeilman
Developer Advocate
Developer Advocate
0 Kudos
72

You can copy the file into a new file name and delete the old one.




report zrich_0001.

Parameters: d1 type localfile default '/usr/sap/TST/SYS/Data1.txt',
            d2 type localfile default '/usr/sap/TST/SYS/Data2.txt'.

data: begin of itab occurs 0,
      rec(20) type c,
      end of itab.
data: wa(20) type c.


start-of-selection.

  open dataset d1 for input in text mode.
  if sy-subrc = 0.
    do.
      read dataset d1 into wa.
      if sy-subrc <> 0.
        exit.
      endif.
      itab-rec = wa.
      append itab.
    enddo.
  endif.
  close dataset d1.

  open dataset d2 for output in text mode.
  loop at itab.
    transfer itab to d2.
  endloop.
  close dataset d2.

delete dataset d1.

Welcome to SDN. Please remember to award points for helpful answers and mark your post as solved when your problem is solved.

Regards,

Rich Heilman

Former Member
0 Kudos
73

The earlier reply is an excellent way to do it. Another way to do this is by using the SYSTEM command/function as follows :

DATA: unix_command(500)

DATA: BEGIN OF itab OCCURS 0,

LINE(255),

END OF itab.

concatenate 'mv' source_file dest_file into unix_command separated by space.

CALL 'SYSTEM' ID 'COMMAND' FIELD COMMAND ID 'ITAB' FIELD TABM-SYS.

gabriel_pill-kahan
Active Participant
0 Kudos
72

Amit,

You can use transaction SM69 to define an external command and then call transaction SXPG_COMMAND_EXECUTE to execute it. For example, if you're on Unix, define command ZRENAME with OS command mv and parameters ?.

For more documentation, search for "External Operating System Command" in the Computing Center Management System (CCMS).

Regards, Gabriel