2006 Sep 07 3:41 PM
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
2006 Sep 07 3:47 PM
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
2006 Sep 07 3:44 PM
2006 Sep 07 3:47 PM
2006 Sep 07 3:47 PM
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.
2006 Sep 07 3:47 PM
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.
2006 Sep 07 3:54 PM
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.
2006 Sep 07 3:55 PM
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
2006 Sep 07 4:03 PM
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
2006 Sep 07 5:08 PM
| User | Count |
|---|---|
| 3 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 |