cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

FM to rename files in ABAP

Former Member
0 Likes
6,185

Hi..I am pretty new to the world of ABAP.

I have the following task.

I need to right a function module that will be responsible for renaming files on the R/3 system (to a certain predefined format). Basically, I am thinking that FM will import/accept an old file name (incl path) as a parameter, and then FM will take care of actually renaming the file and returning the name of the new filename.

Since I am very new to all the ABAP, can any of you give me some pointers, or maybe some sample code if anybody done something similar?

All the help is appreciated.

thank you

Accepted Solutions (0)

Answers (6)

Answers (6)

vinod_gunaware2
Active Contributor

Hi

U need to use system command.

regard

vinod

jvennervald
Explorer
0 Likes

This is the right way to do it.
Copying and deleting is overkill and will especially for larger files be slower than calling an actual OS-command to rename the file.

guillaume-hrc
Active Contributor
0 Likes

Hi Andrei,

Just for completion sake, you can also use the 2 following transactions that transfer files:

- CG3Y : Server to PC

- CG3Z : PC to Server

Best regards,

Guillaume

andreas_mann3
Active Contributor
0 Likes

Hi Andrei,

look here

Andreas

ferry_lianto
Active Contributor
0 Likes

Hi Andrei,

You may try SAP program <b>RSFTP002</b> to copy and delete file in applicatio server. You may need BASIS to give permission access to aps server.

Hope this will help.

Regards,

Ferry Lianto

Former Member
0 Likes

Hi,

Use FM <b>RS_RENAME_PROGRAM </b>

DATA: PROGOLD LIKE SY-REPID VALUE 'ZTEST', "Old prog name

PROGNEW LIKE SY-REPID VALUE 'ZTEST998'. "new prog name

call function 'RS_RENAME_PROGRAM'

exporting devclass = '$TMP'

source_program = progold

program = prognew

suppress_popup = 'X'

exceptions others = 1.

This FM is not for file names in application server.

We can rename program names using this FM.

Regards,

Sailaja.

Message was edited by: Sailaja N.L.

Former Member
0 Likes

Sorry...actually I was referring to renaming files on the application server..not programs. Maybe I can still reuse that FM though.

RichHeilman
Developer Advocate
Developer Advocate
0 Likes

Are you talking about files on the application server. If so, you will need to copy them into the new name and delete the old one. Here is a sample program.




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 and read file 1 into an internal table
  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 file 2 and copy the contents to this file
  open dataset d2 for output in text mode.
  loop at itab.
    transfer itab to d2.
  endloop.
  close dataset d2.

* Delete file 1
  delete dataset d1.

Welcome to SDN! Please remember to award points for any helpful answers that you might recieve. Also, when your question has been answered completly, be sure to mark as "Solved". Thanks.

Regards,

Rich Heilman

Former Member
0 Likes

Yep. I was referring to the files on the application server. Let me try your sample program. Thanks a lot by the way..I will let you know whether it worked for me

Former Member
0 Likes

Hi Rich,

I looked at your code....and I was wondering

how would I make the length of a rec(20) to be dynamic. Because I am creating a generec FM to rename files, so all the files can have records with different length.

What would you suggest.

Thank you

Former Member
0 Likes

<b>rec type string,</b>

would do.

Regards,

Ravi

Former Member
0 Likes

Hi Andrei,

Rich given a sample program to you. based on your requirements, you have to do some changes to that program like defalut program name,length of each record etc..

that program will works fine.

to make your FM to work for all files say the record length is 1024.

regards

srikanth