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

function module to move a file from one Directory to another

Former Member
0 Likes
12,487

Hi,

I need to move a file in the application server from one Directory to another.Is there any function module for this purpose.

Regards,

Charumathi.B

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
2,019

Hi Friend,

Instead of any FM you can use this code :

Parameters: S_File type localfile default GIVE SOURCE FILEPATH,

D_File type localfile default GIVE DESTINATION FILEPATH.

data: begin of itab occurs 0,

rec(100) type c,

end of itab.

data: wa(100) type c.

start-of-selection.

open dataset S_File for input in text mode.

if sy-subrc = 0.

do.

read dataset S_File into wa.

if sy-subrc 0.

exit.

endif.

itab-rec = wa.

append itab.

enddo.

endif.

close dataset S_File.

open dataset D_File for output in text mode.

loop at itab.

transfer itab to D_File.

endloop.

close dataset D_File.

delete dataset S_File.

Regards

Hemant Khemani

Hi,

I need to move a file in the application server from one Directory to another.Is there any function module for this purpose.

Regards,

Charumathi.B

4 REPLIES 4
Read only

Former Member
0 Likes
2,020

Hi Friend,

Instead of any FM you can use this code :

Parameters: S_File type localfile default GIVE SOURCE FILEPATH,

D_File type localfile default GIVE DESTINATION FILEPATH.

data: begin of itab occurs 0,

rec(100) type c,

end of itab.

data: wa(100) type c.

start-of-selection.

open dataset S_File for input in text mode.

if sy-subrc = 0.

do.

read dataset S_File into wa.

if sy-subrc 0.

exit.

endif.

itab-rec = wa.

append itab.

enddo.

endif.

close dataset S_File.

open dataset D_File for output in text mode.

loop at itab.

transfer itab to D_File.

endloop.

close dataset D_File.

delete dataset S_File.

Regards

Hemant Khemani

Read only

0 Likes
2,019

Hi,

here a modified version for binary files and with buffering:

PARAMETERS:
  s_file TYPE localfile DEFAULT '/tmp/xtest1.txt',
  d_file TYPE localfile DEFAULT '/tmp/xtest2.txt'.

CONSTANTS:
  c_buflen TYPE i VALUE 100.

DATA:
  buf(100) TYPE x,
  actlen TYPE i.

START-OF-SELECTION.

  OPEN DATASET s_file FOR INPUT IN BINARY MODE.
  IF sy-subrc = 0.
    OPEN DATASET d_file FOR OUTPUT IN BINARY MODE.
    IF sy-subrc = 0.
      DO.
        READ DATASET s_file INTO buf MAXIMUM LENGTH c_buflen ACTUAL LENGTH actlen.
        IF actlen > 0.
          TRANSFER buf TO d_file LENGTH actlen.
        ELSE.
          EXIT.
        ENDIF.
      ENDDO.
      CLOSE DATASET d_file.
      CLOSE DATASET s_file.
      DELETE DATASET s_file.
    ENDIF.
  ENDIF.

regards,

Krzysztof

Read only

Former Member
0 Likes
2,019

Use the below function module to move the file from one location to other location:

CALL FUNCTION 'ARCHIVFILE_SERVER_TO_SERVER'

EXPORTING

sourcepath = w_file

targetpath = lv_tgt_file

EXCEPTIONS

error_file = 1

OTHERS = 2.

IF sy-subrc <> 0.

MESSAGE ID sy-msgid TYPE c_s NUMBER sy-msgno

WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.

EXIT.

ELSE.

DELETE DATASET w_file.

ENDIF.

Regards,

Kiran Bobbala

Read only

Former Member
0 Likes
2,019

Another method is that you can download the file to your system and upload to another directory using transaction 'CG3Z' .

Regards

Sathar