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: 

Unix command - returning sy-subrc = 1

Former Member
0 Kudos

Hello

I have an issue with using moving files from one folder to another. I am using the following code.

LOOP AT it_tab1 INTO wa_tab1.

     CLEAR:var_file.

     var_file = wa_tab1-lines.


CONCATENATE p_src '/' var_file INTO var_src.

CONCATENATE p_trg '/' var_file INTO var_trg.

CLEAR: var_command.

CONCATENATE 'mv' var_src var_trg INTO var_command

                      SEPARATED BY space.

CALL 'SYSTEM' ID 'COMMAND' FIELD var_command.

The wierd thing is it is working all fine for some files.

I run this command inside a loop and for each file, in my internal table I execute the command and move them.

After moving some files, the sy-subrc for CALL 'SYSTEM' command is returning '1' .

I dont understand why this is happening. The unix command is not working after running for few files.

Any pointers will be of very great help. It is a simple command and works for some few files in the loop. All the files are of same type and same name formats. If I wait for sometime(few seconds/minutes ... donno how much time), it moves the remaining files tooo....

Any pointers will be of great help.


7 REPLIES 7

former_member946717
Contributor
0 Kudos

Hi Prasanna,

I suggest you click F1 on CALL and check what message does sy-subrc 1 indicate. Or if you have an idea please elaborate on the error message. We can then be able to help!

gouravkumar64
Active Contributor
0 Kudos

Hi,

Use SM69 for manage system calls.

check SXPG_COMMAND_EXECUTE ALSO...may be some authorization problem also happening.

check this one for help.

http://scn.sap.com/thread/66097

Thanks

Gourav.

0 Kudos

Hello A N

There is not information for F1 help on CALL 'SYSTEM' and also, I am not getting any error message. After the UNIX command is executed, I check for sy-subrc which is returning '1'.

The command is working fine for some files. Also, if I add a 1 second wait time, for each file after the move statement, it is working fine ( as of now ), but I am not sure why there is an error.

just to check the file movement is completed,  after each movement of file, I am checking the the count of files in each folder using 'ls -l' command which is also failing when running in loop.

Its very confusing why the UNIX commands are behaving this way.

Is there a FM to get the list of files on the application server?

0 Kudos

Hello Gourav

I donot have authorization to build commands in SM69. Is there any other way to proceed.

Also, Is there a FM to get count/list of files present on the  application server.

Thanks

0 Kudos

Hi Indira,

Since you said it helps if you add a 1 second wait time, maybe its because there are some big files which are either taking time to open or taking time to close. So best would be to add a Wait!

0 Kudos

Hello Indira,

on an old program we have the same situation. The cause is, that most called Unix-commands return "-1", which is transformed to 1, because sy-subrc has no sign. See man-pages in unix to the command "mv(1p)", there mv returns a value ">0" if an error occured.

If you try to call the Unix-command on the Unix-shell, you should get the same result on the files that are not moved.

In our own situation it was a problem of rights on the file or the users rights ("Operation ot permitted").

The constellation of whom has written the files an who wants to move or change them is important.

Greetings

Raphael

Hai,

I got through this by adding a wait time of 2 seconds after each file movement. I still dont know the reason but adding wait time worked. I do have authorization for moving files and the program moves the files sometimes.

Thanks for your time.