You are on page 1of 2

* systen command has executed

**** Use transaction SM69 to create the xcommand Z_MV (which is the unix mv
command)
DATA: lt_dir_list TYPE STANDARD TABLE OF btcxpm INITIAL SIZE 0.

DATA: lv_from_param TYPE sxpgcolist-parameters,


lv_to_param TYPE sxpgcolist-parameters,
lv_arch_parameter TYPE sxpgcolist-parameters,
lv_status TYPE extcmdexex-status,
lv_exit_code TYPE extcmdexex-exitcode,
lv_arch_dir TYPE localfile,
lv_lines TYPE i,
lv_separator(1) TYPE c VALUE space,
lv_name TYPE localfile,
lv_extens TYPE localfile,
c_command_ren LIKE sxpgcolist-name VALUE 'Z_MV', " External
command name

* Check the interface is not running in test mode


CHECK gv_test IS INITIAL.

* Only attempt to archive files fromthe application server.


CHECK gs_file_list-sap_file IS NOT INITIAL.

* initialise
CLEAR: lt_dir_list[].
CLEAR: lv_from_param, lv_to_param, lv_arch_parameter.
CLEAR: lv_status, lv_exit_code.

* Create additional parameters to be passed into SXPG_COMMAND_EXECUTE


MOVE gs_file_list-filename TO lv_from_param.

SPLIT gs_file_list-name AT '.' INTO lv_name lv_extens.

* Rename the file


IF im_error-type NE c_error.
* Check if archive directory exist
MOVE gs_file_list-archive TO lv_arch_dir.
OPEN DATASET lv_arch_dir FOR INPUT IN BINARY MODE.
IF sy-subrc EQ 0.
CLOSE DATASET lv_arch_dir.
CONCATENATE lv_arch_dir lv_separator INTO lv_arch_dir.

ELSE.
MOVE gs_file_list-path TO lv_arch_dir.

ENDIF.

* No error processing the file so move to archive directory


CONCATENATE lv_arch_dir
lv_name
'.prc'
INTO lv_to_param. "To directory & filename

ELSE.
* Error processing file rename and keep in current directory
CONCATENATE gs_file_list-path
lv_name
'.err'
INTO lv_to_param. "To directory & filename

ENDIF.

CONCATENATE lv_from_param
lv_to_param
INTO lv_arch_parameter
SEPARATED BY space.

* Move file to archive directory


CALL FUNCTION 'SXPG_COMMAND_EXECUTE'
EXPORTING
commandname = 'Z_MV'
additional_parameters = lv_arch_parameter
IMPORTING
status = lv_status
exitcode = lv_exit_code
TABLES
exec_protocol = lt_dir_list
EXCEPTIONS
no_permission = 1
command_not_found = 2
parameters_too_long = 3
security_risk = 4
wrong_check_call_interface = 5
program_start_error = 6
program_termination_error = 7
x_error = 8
parameter_expected = 9
too_many_parameters = 10
illegal_command = 11
wrong_asynchronous_parameters = 12
cant_enq_tbtco_entry = 13
jobcount_generation_error = 14
OTHERS = 15.
IF sy-subrc <> 0.
* Do nothing.
ENDIF.

You might also like