here below is sample code
REPORT ZMOVEFILE.
DATA: lv_source_file TYPE string,
lv_target_file TYPE string,
lv_data_buffer TYPE string,
lv_file_length TYPE i.
” Specify the source and target files
lv_source_file = ‘/tmp/506TEST001.dat’. ” Source path (change to your source)
lv_target_file = ‘/usr/sap/tmp/506TEST001.dat’. ” Target path (change to your target)
” Open the source file
OPEN DATASET lv_source_file FOR INPUT IN TEXT MODE ENCODING DEFAULT.
IF sy-subrc <> 0.
WRITE: / ‘Error opening source file’.
EXIT.
ENDIF.
” Open the target file
OPEN DATASET lv_target_file FOR OUTPUT IN TEXT MODE ENCODING DEFAULT.
IF sy-subrc <> 0.
WRITE: / ‘Error opening target file’.
CLOSE DATASET lv_source_file.
EXIT.
ENDIF.
” Read from the source file and write to the target file
DO.
READ DATASET lv_source_file INTO lv_data_buffer.
IF sy-subrc <> 0.
EXIT. ” Exit loop if end of file
ENDIF.
TRANSFER lv_data_buffer TO lv_target_file.
ENDDO.
” Close both datasets
CLOSE DATASET lv_source_file.
CLOSE DATASET lv_target_file.
” Optional: Delete the source file if the transfer is successful
DELETE DATASET lv_source_file.
IF sy-subrc = 0.
WRITE: / ‘Source file deleted after move’.
ELSE.
WRITE: / ‘Error deleting source file’.
ENDIF.