Application Development and Automation 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: 
Read only

copy file

Former Member
0 Likes
890

Hi experts,

I want to move or copy a file in a directory to another directory in the Application server.

Can any body tell me how can we do this.

Regards

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
859

You can do the following.

1. Read the file to be written using Read dataset statement.

OPEN DATASET INFILE FOR Input .

2. Use one more dataset statement with different file name for writing the file to other location on application server.

OPEN DATASET OUTFILE FOR OUTPUT IN TEXT MODE

Now loop through the file open in step1 and transfer it to the file opened in step2.

Hi experts,

I want to move or copy a file in a directory to another directory in the Application server.

Can any body tell me how can we do this.

Regards

8 REPLIES 8
Read only

Former Member
0 Likes
859

hi Ravi,

Check FM '/SAPDMC/LSM_F4_FRONTEND_FILE'

Check out this thread too

Regards,

Santosh

Message was edited by: Santosh Kumar P

Read only

Former Member
0 Likes
859

hi Ravi,

Check out this too..

Regards,

Santosh

Read only

Former Member
0 Likes
859

You could create an external command in SM69 and call it with function SXPG_COMMAND_EXECUTE. For example, you could create an external command for mv. You would then pass the source and destination in the parameter.

Read only

Former Member
0 Likes
860

You can do the following.

1. Read the file to be written using Read dataset statement.

OPEN DATASET INFILE FOR Input .

2. Use one more dataset statement with different file name for writing the file to other location on application server.

OPEN DATASET OUTFILE FOR OUTPUT IN TEXT MODE

Now loop through the file open in step1 and transfer it to the file opened in step2.

Read only

0 Likes
859

Reading the file into a program and writing it out works, but it involves unneccessary processing especially for large files.

The OS provides commands for file processing and SAP provides the ability to execute these commands.

Read only

0 Likes
859

Here is a sample that I did a while back, All you need to do is change the directory folder if you want to move to another directory.



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: itab type string.
data: wa type string.


start-of-selection.

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


* Copy to new file
  open dataset d2 for output in text mode.
  loop at itab into wa.
    transfer wa to d2.
  endloop.
  close dataset d2.

* Delete the first
  delete dataset d1.

Regards,

Rich Heilman

Read only

0 Likes
859

hi,

Open a dataset and write the file into it and close it. Then you can read this file by opening reading the dataset in read mode and closing it.

Regards,

Richa

Read only

0 Likes
859

Hi All,

Thank you very much for your replies.

Points are given.