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: 

Issue in moving files from data fodler to processed folder in background

Former Member
0 Kudos

Hi All,

I am facing one issue in moving files from data fodler to processed folder in case of background execution.

When i am executing the file in the foreground, i can move the file from Data folder to processed folder. I am using SXPG_COMMAND_EXECUTE FM to move the file from data folder to processed folder. I can see the file in processed folder once the program is executed.

But in case of executing the same program in background, it is giving me the error "Failed to move the file to processed folder" in the spool of SM37 and i can see the file still laying in data folder.

I tried to check other programs which acesses the same folder as the above program, whether they are able to move. They are able to move the file to processed fodler successfully both in foreground and background mode.

Please help me in resolving this issue.

Thanks,

Deepa

2 REPLIES 2

Clemenss
Active Contributor
0 Kudos

Hi Sanu,

commands processed by SXPG_COMMAND_EXECUTE will be handled by the server operating system and will affect the server. Thus online and background should be the same.

Does SAP server run on windows server operating system or does your system uses any other method to make local files accessible?

If your data folder is a local file (local to your client/desktop), then it can not be accessed by background processed except you give the full unmapped file path and name without any drive letter.

One more possibility is that background jobs are executed using an other users who has no sufficient authority for the files/paths in question.

Check the SXPG_COMMAND_EXECUTE exception number in SY-SUBRC, also analyze contents of TABLES

EXEC_PROTOCOL. SXPG_COMMAND_EXECUTE and it's exceptions are [well documented|http://help.sap.com/saphelp_40b/helpdata/en/fa/0971fb543b11d1898e0000e8322d00/content.htm] here..

If this does not resolve the issue, just give file name and path here (slightly changed names for confidence) and let me guess again.

Regards,

Clemens

Former Member
0 Kudos

Hi Sanu,

Please use teh following code to move the file from source to target folder.

  • This is a code showing how to create and use COPY command of UNIX in ABAP

PARAMETERS:

  • Input file path

p_input TYPE localfile,

  • Processed file path

p_proc TYPE localfile.

  • Declare the Types to file data

TYPES: BEGIN OF L_X_OUTPUT,

sys(200), " Please note, there are asterisk before and after sys (i.e.sys)

END OF L_X_OUTPUT.

  • * Internal table to store file data

DATA l_i_output TYPE STANDARD TABLE OF l_x_output WITH HEADER LINE.

  • * Variable for the UNIX command

DATA: l_v_unix_comm(255) TYPE c.

  • Copy command of UNIX

CONCATENATE 'mv' p_input p_proc

INTO l_v_unix_comm SEPARATED BY space.

  • For example the Copy command is stored as below

  • cp u2018/data/interfaces/input/input_fileu2019 u2018/data/interfaces/processed/processed_fileu2019

  • Examples of UNIX Command *u2022 mv filename1 filename2 --- moves a file (i.e. gives it a different name, or moves it into a *different directory (see below) *u2022 cp filename1 filename2 --- copies a file

  • Execute the UNIX Copy command.

  • This command will copy the file from input file path to the processed file path

CALL 'SYSTEM' ID 'COMMAND' FIELD l_v_unix_comm

ID 'TAB'

FIELD l_i_output-sys.

IF sy-subrc eq 0.

write: 'File is copied successfully using UNIX command in ABAP'.

ENDIF.