‎2007 Jan 22 10:44 PM
Hi Experts,
How to a archive file in application server to another folder? Is there any function module used for that?.
Thanks
‎2007 Jan 22 10:45 PM
try using CG3Z transaction or use OPEN dATASET statement
- Guru
‎2007 Jan 22 10:45 PM
try using CG3Z transaction or use OPEN dATASET statement
- Guru
‎2007 Jan 22 10:50 PM
Hi Dan,
you can use following syntax:
OPEN DATASET v_file FOR APPENDING IN TEXT MODE ENCODING DEFAULT.
IF sy-subrc <> 0.
MESSAGE text-002 TYPE 'I'.
ELSE.
CLEAR x_data.
LOOP AT it_data INTO x_data.
TRANSFER x_data TO v_file.
APPEND x_data TO it_sdata.
CLEAR x_data.
ENDLOOP.
ENDIF.
CLOSE DATASET v_file.
Or you can use Transaction Code CG3Z.
Ashven
‎2007 Jan 22 11:07 PM
Hi,
You can request the Basis to do it. Else you can also write a small Unix Script to copy the file or move a file from one folder on the Application server to another.
This script will run in an ABAP program.
Hope this helps...
Ketan
‎2007 Jan 22 11:31 PM
Hi,
Chk these two FMs:
C13Z_APPL_TO_FRONT_END
C13Z_FRONT_END_TO_APPL
One is to move from Appl.server to Front end, and another from front end to appl. server.
Go to Tcode: AL11 and decide the folder where you want to place the file.
Regards
Subramanian
‎2007 Jan 23 12:13 AM
There is no straight forward way to do it. You can use OPEN DATASET, READ DATASET, TRANSFER DATASET, DELETE DATASET to open the source file, read it into an internal table, transfer the contents of the internal table to the target file and then delete the source file.
You can also ask your unix administrators to simply provide you with a unix script that takes in the source and target directories and moves the file from source to destination. Once you have the script, you can create an external system command in SAP (SM69, SM49) which can be executed through an ABAP program by calling the function module SXPG_COMMAND_EXECUTE.
‎2007 Jan 23 2:01 AM
Hi Dan
For archiving, we can use FM: <b>EPS_DELETE_FILE</b> for archiving a file.
Below code can help you understand for moving a file:
[code]FUNCTION y_copy_file_within_appli_serv.
*"----
""Local interface:
*" IMPORTING
*" VALUE(RFC_DESTINATION) LIKE RFCDES-RFCDEST
*" VALUE(LOCAL_FILE) LIKE EPSF-EPSFILNAM
*" VALUE(LOCAL_DIRECTORY) LIKE EPSF-EPSDIRNAM DEFAULT SPACE
*" VALUE(REMOTE_FILE) LIKE EPSF-EPSFILNAM DEFAULT SPACE
*" VALUE(REMOTE_DIRECTORY) LIKE EPSF-EPSDIRNAM DEFAULT SPACE
*" VALUE(OVERWRITE_MODE) LIKE EPSF-EPSOVRWRI DEFAULT SPACE
*" VALUE(TEXT_MODE) LIKE EPSF-EPSTXTMOD DEFAULT SPACE
*" VALUE(TRANSMISSION_MONITOR) LIKE EPSF-EPSTRAMON DEFAULT 'X'
*" VALUE(RECORDS_PER_TRANSFER) LIKE EPSF-EPSRECTRA DEFAULT 10
*" VALUE(REQUESTED_FILE_SIZE) LIKE EPSF-EPSFILSIZ DEFAULT 0
*" VALUE(MONITOR_TITLE) LIKE EPSF-EPSTEXT OPTIONAL
*" VALUE(MONITOR_TEXT1) LIKE EPSF-EPSTEXT OPTIONAL
*" VALUE(MONITOR_TEXT2) LIKE EPSF-EPSTEXT OPTIONAL
*" VALUE(PROGRESS_TEXT) LIKE EPSF-EPSTEXT OPTIONAL
*" VALUE(OBJECT_NAME) LIKE EPSF-EPSFILNAM OPTIONAL
*" EXPORTING
*" VALUE(LOCAL_DIRECTORY) LIKE EPSF-EPSDIRNAM
*" VALUE(LOCAL_PATH) LIKE EPSF-EPSPATH
*" VALUE(REMOTE_FILE) LIKE EPSF-EPSFILNAM
*" VALUE(REMOTE_DIRECTORY) LIKE EPSF-EPSDIRNAM
*" VALUE(REMOTE_PATH) LIKE EPSF-EPSPATH
*" VALUE(FILE_SIZE) LIKE EPSF-EPSFILSIZ
*" VALUE(LOCAL_SYSTEM_INFO) LIKE EPSFTPSI STRUCTURE EPSFTPSI
*" VALUE(REMOTE_SYSTEM_INFO) LIKE EPSFTPSI STRUCTURE EPSFTPSI
*" EXCEPTIONS
*" OPEN_INPUT_FILE_FAILED
*" OPEN_OUTPUT_FILE_FAILED
*" READ_BLOCK_FAILED
*" WRITE_BLOCK_FAILED
*" CLOSE_OUTPUT_FILE_FAILED
*" INVALID_FILE_SIZE
*" STOPPED_BY_USER
*" INVALID_INPUT_FILE_SIZE
*" RESTART_FAILED
*" CONNECTION_FAILED
*" INVALID_VERSION
*"----
DATA: BEGIN OF eps_buffer OCCURS 10.
INCLUDE STRUCTURE tbl8000.
DATA: END OF eps_buffer.
DATA: BEGIN OF eps_txtbuf OCCURS 0.
INCLUDE STRUCTURE epsteco.
DATA: END OF eps_txtbuf.
DATA: ls_save_moni LIKE g$moni.
DATA: lv_local_file_size LIKE epsf-epsfilsiz,
lv_remote_file_size LIKE epsf-epsfilsiz,
lv_block_size LIKE epsf-epsfilsiz,
lv_number_of_records LIKE epsf-epsrectra,
lv_last_record_length LIKE epsf-epsreclen,
lv_max_record_length LIKE epsf-epsreclen,
lv_end_of_file LIKE epsf-epsflag,
lv_low_rc LIKE sy-subrc,
lv_rfc_message LIKE sy-msgv1,
lv_restart_flag LIKE epsf-epsflag,
lv_pattern LIKE tbl8000-line,
lv_records_to_skip LIKE epsf-epsrectra,
lv_skiped_size LIKE epsf-epsfilsiz.
check parameters (only if not started from EPS_ftp_mput)
IF transmission_monitor <> gc_mon_flag_m.
PERFORM get_ftp_system_info " get ftp system info
USING
rfc_destination
CHANGING
local_system_info
remote_system_info.
PERFORM check_ftp_version " check ftp version
USING
text_mode
remote_system_info.
PERFORM check_overwrite_mode " check OVERWRITE_MODE
USING
text_mode
CHANGING
overwrite_mode.
PERFORM check_records_per_transfer " check RECORDS_PER_TRANSFER
USING
text_mode
CHANGING
records_per_transfer.
ENDIF.
determine block_size [byte] (binary mode only)
IF text_mode <> 'X'.
*>>> Begin of modification for change log reference UnicodeC <<<
DESCRIBE FIELD eps_buffer-line LENGTH lv_max_record_length.
DESCRIBE FIELD eps_buffer-line LENGTH lv_max_record_length IN
BYTE MODE.
*<<< End of modification for change log reference UnicodeC >>>
lv_block_size = lv_max_record_length * records_per_transfer.
ENDIF.
open local file for input
CALL FUNCTION 'EPS_OPEN_INPUT_FILE'
EXPORTING
file_name = local_file
dir_name = local_directory
text_mode = text_mode
IMPORTING
dir_name = local_directory
file_path = local_path
file_size = lv_local_file_size
EXCEPTIONS
invalid_eps_subdir = 11
sapgparam_failed = 12
build_directory_failed = 13
no_authorization = 14
build_path_failed = 15
open_failed = 16
read_directory_failed = 17
read_attributes_failed = 18.
lv_low_rc = sy-subrc.
IF sy-subrc <> 0.
CALL FUNCTION 'EPS_CLOSE_FILE'
EXPORTING
file_name = local_file
dir_name = local_directory
EXCEPTIONS
OTHERS = 99.
MESSAGE e001 WITH lv_low_rc local_file local_directory
space " rfc message
RAISING open_input_file_failed.
ENDIF.
check file size
IF requested_file_size <> 0 AND
requested_file_size <> lv_local_file_size.
CALL FUNCTION 'EPS_CLOSE_FILE'
EXPORTING
file_name = local_file
dir_name = local_directory
EXCEPTIONS
OTHERS = 99.
lv_low_rc = 0.
MESSAGE e008 WITH lv_low_rc local_file
requested_file_size lv_local_file_size
RAISING invalid_input_file_size.
ENDIF.
open remote file for output
IF remote_file = space. " no remote file specified
remote_file = local_file. " -> remote file = local file
ENDIF.
IF text_mode = 'X' AND " no restart in textmode
overwrite_mode = 'R'.
overwrite_mode = 'S'.
ENDIF.
CALL FUNCTION 'EPS_OPEN_OUTPUT_FILE'
DESTINATION rfc_destination
EXPORTING
file_name = remote_file
dir_name = remote_directory
file_size_request = lv_local_file_size
overwrite_mode = overwrite_mode
text_mode = text_mode
IMPORTING
dir_name = remote_directory
file_path = remote_path
restart_flag = lv_restart_flag
EXCEPTIONS
system_failure = 03 MESSAGE lv_rfc_message
communication_failure = 04 MESSAGE lv_rfc_message
invalid_eps_subdir = 11
sapgparam_failed = 12
build_directory_failed = 13
no_authorization = 14
build_path_failed = 15
open_failed = 16
file_already_exists = 19.
lv_low_rc = sy-subrc.
IF sy-subrc <> 0.
CALL FUNCTION 'EPS_CLOSE_FILE'
DESTINATION rfc_destination
EXPORTING
file_name = remote_file
dir_name = remote_directory
EXCEPTIONS
OTHERS = 99.
CALL FUNCTION 'EPS_CLOSE_FILE'
EXPORTING
file_name = local_file
dir_name = local_directory
EXCEPTIONS
OTHERS = 99.
MESSAGE e002 WITH lv_low_rc remote_file remote_directory
lv_rfc_message
RAISING open_output_file_failed.
ENDIF.
restart file transfer
IF lv_restart_flag = 'X'.
ls_save_moni = g$moni. " save monitor data
CALL FUNCTION 'EPS_SEEK_OUTPUT_FILE'
DESTINATION rfc_destination
EXPORTING
file_name = remote_file
dir_name = remote_directory
records_per_transfer = records_per_transfer
object_name = object_name
IMPORTING
pattern = lv_pattern
records_to_skip = lv_records_to_skip
EXCEPTIONS
system_failure = 03 MESSAGE lv_rfc_message
communication_failure = 04 MESSAGE lv_rfc_message
invalid_eps_subdir = 11
sapgparam_failed = 12
build_directory_failed = 13
no_authorization = 14
build_path_failed = 15
open_failed = 16
read_directory_failed = 17
read_attributes_failed = 18
read_failure = 20
write_failure = 21
OTHERS = 99.
lv_low_rc = sy-subrc.
IF sy-subrc <> 0.
CALL FUNCTION 'EPS_CLOSE_FILE'
EXPORTING
file_name = local_file
dir_name = local_directory
EXCEPTIONS
OTHERS = 99.
g$moni = ls_save_moni. " restore monitor data
MESSAGE e009 WITH lv_low_rc remote_file remote_directory
lv_rfc_message
RAISING restart_failed.
ENDIF.
CALL FUNCTION 'EPS_SEEK_INPUT_FILE'
EXPORTING
pattern = lv_pattern
records_to_skip = lv_records_to_skip
file_path = local_path
records_per_transfer = records_per_transfer
EXCEPTIONS
read_failure = 20
write_failure = 21
end_of_file = 22
pattern_not_found = 23
OTHERS = 99.
lv_low_rc = sy-subrc.
IF sy-subrc <> 0.
CALL FUNCTION 'EPS_CLOSE_FILE'
DESTINATION rfc_destination
EXPORTING
file_name = remote_file
dir_name = remote_directory
EXCEPTIONS
OTHERS = 99.
CALL FUNCTION 'EPS_CLOSE_FILE'
EXPORTING
file_name = local_file
dir_name = local_directory
EXCEPTIONS
OTHERS = 99.
CALL FUNCTION 'EPS_DELETE_FILE'
DESTINATION rfc_destination
EXPORTING
file_name = remote_file
dir_name = remote_directory
EXCEPTIONS
OTHERS = 99.
g$moni = ls_save_moni. " restore monitor data
MESSAGE e009 WITH lv_low_rc remote_file remote_directory
space " rfc message
RAISING restart_failed.
ENDIF.
lv_skiped_size = lv_records_to_skip * lv_max_record_length.
g$moni = ls_save_moni. " restore monitor data
ENDIF.
start transmission monitor
IF transmission_monitor <> 'M'.
PERFORM monitor_open
USING transmission_monitor
monitor_title.
PERFORM monitor_set_values
USING gc_ftp_put
progress_text
monitor_text1
monitor_text2
rfc_destination
local_file
0 " total files
0 " current file
0 " maxval gauge 1
lv_local_file_size " maxval gauge 2
0 " skiped size gauge 1
lv_skiped_size. " skiped size gauge 2
ELSE.
PERFORM monitor_update_values
USING 0 " increment
0 " skiped size gauge 1
lv_skiped_size. " skiped size gauge 2
ENDIF.
*
file transfer ------------------------------------------ begin -------
*
CLEAR lv_end_of_file.
WHILE lv_end_of_file <> 'X'.
read block from input file
IF text_mode = 'X'.
REFRESH eps_txtbuf.
CALL FUNCTION 'EPS_READ_TEXT_BLOCK'
EXPORTING
file_path = local_path
records_per_transfer = records_per_transfer
IMPORTING
end_of_file = lv_end_of_file
TABLES
eps_buffer = eps_txtbuf
EXCEPTIONS
read_failure = 20.
ELSE.
REFRESH eps_buffer.
CALL FUNCTION 'EPS_READ_BLOCK'
EXPORTING
file_path = local_path
records_per_transfer = records_per_transfer
IMPORTING
number_of_records = lv_number_of_records
last_record_length = lv_last_record_length
end_of_file = lv_end_of_file
TABLES
eps_buffer = eps_buffer
EXCEPTIONS
read_failure = 20.
ENDIF.
lv_low_rc = sy-subrc.
IF sy-subrc <> 0.
IF transmission_monitor = 'X'. " stop monitor
PERFORM monitor_stop.
ENDIF.
MESSAGE e003 WITH lv_low_rc local_path space
RAISING read_block_failed.
ENDIF.
write block into output file
IF text_mode = 'X'.
CALL FUNCTION 'EPS_WRITE_TEXT_BLOCK'
DESTINATION rfc_destination
EXPORTING
file_path = remote_path
IMPORTING
transfered_bytes = lv_block_size
TABLES
eps_buffer = eps_txtbuf
EXCEPTIONS
system_failure = 03 MESSAGE lv_rfc_message
communication_failure = 04 MESSAGE lv_rfc_message
write_failure = 21.
ELSE.
CALL FUNCTION 'EPS_WRITE_BLOCK'
DESTINATION rfc_destination
EXPORTING
file_path = remote_path
number_of_records = lv_number_of_records
last_record_length = lv_last_record_length
TABLES
eps_buffer = eps_buffer
EXCEPTIONS
system_failure = 03 MESSAGE lv_rfc_message
communication_failure = 04 MESSAGE lv_rfc_message
write_failure = 21.
ENDIF.
lv_low_rc = sy-subrc.
IF sy-subrc <> 0.
IF transmission_monitor = 'X'. " stop monitor
PERFORM monitor_stop.
ENDIF.
MESSAGE e004 WITH lv_low_rc remote_path lv_rfc_message
RAISING write_block_failed.
ENDIF.
update transmission monitor
PERFORM monitor_update_values
USING lv_block_size " increment
0 " skiped size gauge 1
0. " skiped size gauge 2
IF g$moni-cancel = 'X'. " stop transmission
MESSAGE e007 RAISING stopped_by_user.
ENDIF.
ENDWHILE.
*
file transfer ------------------------------------------ end ---------
*
stop transmission monitor
IF transmission_monitor = 'X'.
PERFORM monitor_stop.
ENDIF.
close output file and get size
CALL FUNCTION 'EPS_CLOSE_FILE'
DESTINATION rfc_destination
EXPORTING
file_name = remote_file
dir_name = remote_directory
IMPORTING
file_size = lv_remote_file_size
EXCEPTIONS
system_failure = 03 MESSAGE lv_rfc_message
communication_failure = 04 MESSAGE lv_rfc_message
build_path_failed = 15
read_directory_failed = 17
read_attributes_failed = 18.
lv_low_rc = sy-subrc.
IF sy-subrc <> 0.
MESSAGE e005 WITH lv_low_rc remote_file remote_directory
lv_rfc_message
RAISING close_output_file_failed.
ENDIF.
compare size of local and remote file (binary mode only)
IF text_mode <> 'X'.
IF lv_local_file_size <> lv_remote_file_size.
lv_low_rc = 0.
MESSAGE e006 WITH lv_low_rc local_file lv_local_file_size
RAISING invalid_file_size.
ENDIF.
ENDIF.
file_size = lv_local_file_size.
ENDFUNCTION.[/code]
Regards
Eswar