Application Development and Automation 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: 
Read only

return code - CALL 'SYSTEM' ID 'COMMAND' FIELD

Former Member
0 Likes
7,604

Hi Experts,

As part of an interface implementation, i need to create and delete directories.

I am using the following method to create directory on our Unix sap server.



*to create directory
  CONCATENATE
  'mkdir'
  LV_DIR
  INTO UNIXCOM
  SEPARATED BY SPACE.

  CALL 'SYSTEM' ID 'COMMAND' FIELD UNIXCOM
                ID 'TAB'     FIELD TABL[].

I am getting sy-subrc = -1 but directory is created. Same is the case with Delete directory.

How to ensure whether directory is created or not from sy-subrc?

I think ideally i should get sy-subrc = 0, but why am i getting -1?

pls help to resolve this problem.

Many thanks,

Simha

8 REPLIES 8
Read only

Former Member
0 Likes
3,735

CONCATENATE

'mkdir'

LV_DIR

INTO UNIXCOM

SEPARATED BY SPACE.

CALL 'SYSTEM' ID 'COMMAND' FIELD UNIXCOM

ID 'TAB' FIELD TABL[].

*Loop and write the contents og the internal table that should help you.

loop at itabl.

write/:itabl-line.

endloop.

Regards

Neha

Read only

0 Likes
3,735

Hi Neha,

The contents of the table is empty.

This will be run in the background, so i would not know and will not be able to decide on the contents of the retuned Internal table TABL[]

Am i supposed to get sy-subrc = 0 ?

Pls help.

Thanks,

Simha

Read only

0 Likes
3,735

Hello,

I think that we ran into this situation during an upgrade. The sy-subrc used to be 0 if

successful and then after the upgrade it changed to -1.

The command was always successful even though the return code was -1 and the

return table was always empty.

Another way to do this is to create OS commands in SM69 and thne execute them with the

FM: SXPG_COMMAND_EXECUTE. If you do this you avoid using a 'feature' that is not

offically supported by SAP ( is CALL SYSTEM).

Regards

Greg Kern

Read only

0 Likes
3,735

Hi Greg Kern,

Thanks for your inputs. Points noted, but what could be the reason for this change?

But can i take sy-subrc = -1 as success always?

regards,

Simha

Read only

0 Likes
3,735

Hello Simha,

We did assume that -1 was a successful return from the call system. However, since

we could not assume that this would not change in the future we worked at converting

the call systems to call fm sxpg*.

As for a reason, the call system method is not officaily supported by SAP so then can

change whatever they want to with no notice or explanation.

Regards

Greg Kern

Read only

0 Likes
3,735

Hi Greg Kern,

Thanks for your inputs.

I will try this by entering in system commands thru sm69.

I am closing this thread.

Regards,

Simha

Read only

Former Member
0 Likes
3,735

Hey,

I am getting return code 2 for my command. I am trying to decrypt a file using linux command. What does the return code 2 mean? I didn't find anything on SAP help yet.

Regards,

Avinash Vaishya

Read only

Sandra_Rossi
Active Contributor
3,735

Avinash Vaishya it's normal that you don't find anything on SAP help because all C programs are undocumented and you shouldn't call them. Instead of CALL 'SYSTEM', you should use the official and documented way: define your OS command (mkdir or whatever you want) via transaction code SM49, and call it via the function module SXPG_COMMAND_EXECUTE (documentation supplied within the function module itself).