SXPG_COMMAND_EXECUTE, or specialized functions like ARCHIVFILE_SERVER_TO_SERVER. DATA: lv_line TYPE string.
" 1. Open the original source file
OPEN DATASET p_src_file FOR INPUT IN BINARY MODE.
IF sy-subrc = 0.
" 2. Open the destination target file
OPEN DATASET p_tgt_file FOR OUTPUT IN BINARY MODE.
IF sy-subrc = 0.
" 3. Read line by line and transfer data
DO.
READ DATASET p_src_file INTO lv_line.
IF sy-subrc <> 0.
EXIT.
ENDIF.
TRANSFER lv_line TO p_tgt_file.
ENDDO.
CLOSE DATASET p_tgt_file.
ENDIF.
CLOSE DATASET p_src_file.
" 4. Delete the source file once successfully transferred
IF sy-subrc = 0.
DELETE DATASET p_src_file.
ENDIF.
ENDIF.
Option 2: Function Module
ARCHIVFILE_SERVER_TO_SERVER- Limitation: The source and target parameter variables have a maximum length of 70 characters. If your filepath or filename structure exceeds this limitation, you must utilize Option 1 instead. [1]
CALL FUNCTION 'ARCHIVFILE_SERVER_TO_SERVER'
EXPORTING
sourcepath = p_src_file
targetpath = p_tgt_file
EXCEPTIONS
error_file = 1
OTHERS = 2.
IF sy-subrc = 0.
DELETE DATASET p_src_file. " Removes original file to complete the move action
ENDIF.
Option 3: Function Module
SXPG_COMMAND_EXECUTEmv for Unix/Linux or move for Windows) is the fastest option since it changes file pointers rather than rewriting raw blocks. - Create a custom OS command (e.g.,
ZMV) mapped to your OS type in transaction SM69. - Call the function module programmatically:
DATA: lv_parameters TYPE btcxpgpar,
lv_status TYPE btcxpgstat.
" Concatenate source and target paths as arguments for the terminal command
CONCATENATE p_src_file p_tgt_file INTO lv_parameters SEPARATED BY space.
CALL FUNCTION 'SXPG_COMMAND_EXECUTE'
EXPORTING
commandname = 'ZMV'
additional_parameters = lv_parameters
IMPORTING
status = lv_status
EXCEPTIONS
no_permission = 1
command_not_found = 2
security_risk = 3
OTHERS = 4.
If you would like to proceed with setting up one of these options, let me know:
- What is the average size of the files you are moving?
- Will your typical filepaths exceed 70 characters?
- Which Operating System (Unix, Linux, Windows) is your SAP application server running on?