Application Development 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: 

Move file within directories

0 Kudos

Hi

Can anyone let me know how to move a file from source directory to target directory in an unix/windows NT system and how to do error handling.

Please let me know the code.There was a thread which desscribed this but am not able to locate it

Thanks

Panda<b></b>

12 REPLIES 12

RichHeilman
Developer Advocate
Developer Advocate
0 Kudos

Check the ABAP class CL_GUI_FRONTEND_SERVICES, this will allow you to copy and delete files on the frontend.

Regards,

Rich Heilman

0 Kudos

Hi

Thanks for the reply but am looking at the option in application server

Regards

Panda

0 Kudos

check out the function group <b>EPSF</b>

Regards

Raja

andreas_mann3
Active Contributor
0 Kudos

Hi,

... have a look to this link

and TA: SM49 and FM SXPG_COMMAND_EXECUTE.

regards Andreas

0 Kudos

Hi Andreas

In the below code what is the significance of

'TAB' FIELD TABM-SYS.

and how will I handle error

DATA: COMMAND(200).

DATA: BEGIN OF TABL OCCURS 0,

LINE(255),

END OF TABL.

command = 'mv /home/prd/file.in /home/prd/processed/file.out'.

CALL 'SYSTEM' ID 'COMMAND' FIELD COMMAND ID 'TAB' FIELD TABM-SYS.

0 Kudos

Hi Panda,

Sorry, but system call isn't secure

but if you're looking for a secure solution

-> please insert a os-command with ta SM49 and use fm SXPG_COMMAND_EXECUTE

You get errors with the exceptions of that fm

*"      NO_PERMISSION
*"      COMMAND_NOT_FOUND
*"      PARAMETERS_TOO_LONG
*"      SECURITY_RISK
*"      WRONG_CHECK_CALL_INTERFACE
*"      PROGRAM_START_ERROR
*"      PROGRAM_TERMINATION_ERROR
*"      X_ERROR
*"      PARAMETER_EXPECTED
*"      TOO_MANY_PARAMETERS
*"      ILLEGAL_COMMAND
*"      WRONG_ASYNCHRONOUS_PARAMETERS
*"      CANT_ENQ_TBTCO_ENTRY
*"      JOBCOUNT_GENERATION_ERROR
*"----------------------------------------------------------------------

And Have a look here:

http://help.sap.com/saphelp_47x200/helpdata/EN/c4/3a6047505211d189550000e829fbbd/frameset.htm

Regards Andreas

0 Kudos

Hi Guys

I tried the following code for Windows NT to move a file from one directory to another but its not working.Can you please suggest what is going wrong

am using operating system command 'MOVE' while creating external command

ws_file_path = 'D:\usr\sap\UKR\DVEBMGS00\work\ENQLOG00.DAT'.

p_tg_dir = 'D:\usr\sap\UKR\DVEBMGS00\data'.

  • Forming the command

concatenate ws_file_path p_tg_dir into ws_comm_winnt

separated by space.

  • Call function to execute 'ZMV' command defined in SM69 CALL FUNCTION

call function 'SXPG_COMMAND_EXECUTE'

exporting

commandname = 'ZMV'

additional_parameters = ws_comm_winnt

operatingsystem = sy-opsys

stdout = 'X'

stderr = 'X'

terminationwait = 'X'

importing

status = ws_zstat

exitcode = ws_zexit

tables

exec_protocol = t_move

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.

message id sy-msgid type sy-msgty number sy-msgno

with sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.

endif.

0 Kudos

We are using this code

check whether its useful for you.

move:'/cidata/sysid/conversions/'

into dir_from.

move: '/cidata/sysid/archive/'

into dir_to.

when 'COPY'.

operation = 'cp'.

when 'MOVE'.

operation = 'mv'.

when 'REMV'.

operation = 'rm'.

concatenate operation dir_from dir_to

into command separated by space.

call 'SYSTEM' id 'COMMAND' field command.

Regards

Raja

0 Kudos

Hi Raja

move:'/cidata/sysid/conversions/'

into dir_from.

move: '/cidata/sysid/archive/'

into dir_to.

In the above code where is your filename and I believe you are using Unix system am having the requirement in WindowsNT system

Thanks and Regards

Panda

0 Kudos

i am sorry i should have had the file name. (copy paste error).

yes its for unix system.

for windows NT if you map it to PC drive then you could simply use cl_gui_frontend_service=>file_copy method.

Regards

Raja

krzysztof_konitz4
Contributor
0 Kudos

Hi,

You can also try to use:

OPEN DATASET 'source.txt' 
FILTER 'ren source.txt dest.txt'. 
CLOSE DATASET 'source.txt'.

Check documentation for FILTER clause.

Krzys

Former Member
0 Kudos

Hi Panda,

In the below link  step by step explanation for how to move file another file.

http://scn.sap.com/community/unix/blog/2013/01/24/deleteremove-file-in-unix-folder-using-sm69-in-sap...#

hope this will help you.

Regards,

Santhoshi.