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: 

Executing Unix Commands..

Former Member
0 Kudos
1,175

Hi All,

I am working on an outbound interface in which i am creating a file on the application server using OPEN DATASET and CLOSE DATASET....

Now my requirement is after the file is created i have to rename the file .

I guess this can be done by creating an external command in SM69 and then can be called using the FM SXPG_COMMAND_EXECUTE. I just wanted to know is there any other simple FM's or any Command's in SAP by which i can execute the unix commands.

Thanks and Regards,

Swaroop

4 REPLIES 4

Former Member
0 Kudos
194

Hi,

<b>Issuing an Unix Command from ABAP</b>

* 
* Issuing an Unix Command from ABAP 
* 
REPORT ZUNIX. 

DATA  UNIXCMD(50) TYPE C. 
DATA: BEGIN OF ITAB occurs 0, 
                LINE(200), 
             end of ITAB. 

PARAMETERS UNIXCOMM LIKE UNIXCMD 
                    DEFAULT 'ls -ls /usr/sap/trans/data' LOWER CASE. 

* Executing the system commands witin ABAP. 

call 'SYSTEM' id 'COMMAND' field  UNIXCOMM 
       id 'TAB'   field  ITAB-*SYS*. 

EDITOR-CALL FOR ITAB DISPLAY-MODE.

Mark all the helpful answers

Regards

Sudheer

Former Member
0 Kudos
194

Hi Sudheer, Thanks for replying for useful information..

I Also wanted to know the implications(is it recommended) of using the system os command directly as specified in u r code snippet. Any ways I guess in most cases the developer will not be provided with the authorization to execute the system commands directly.

Thanks and Regards,

Swaroop Patri...

Former Member
0 Kudos
194

Hi,

ok, Check the Below program, you will get this program in latest versions from 4.6c...

<b>RSBDCOS0</b>--> Execute UNIX commands

*******************************************************

<b>look OSS Note 9391</b> for more info

Regards

Sudheer

Message was edited by: Sudheer Junnuthula

Former Member
0 Kudos
194

HI,

I found an example program in the web, see it. it is just the FM which you mentioned, mey be useful for you

DATA: COMMAND3(60)
*    VALUE 'rm /vmedata/???/rlbesnsl' .
      VALUE 'rm /vmedata/???/file1nsl' .

COMMAND3+12(3) = SY-SYSID.


*submit the unix command remove file1
REMOVE_FILE = COMMAND3+3.
* create y_remove command in sm69
CALL FUNCTION 'SXPG_COMMAND_EXECUTE'
     EXPORTING
          COMMANDNAME                   = 'Y_REMOVE'
*         OPERATINGSYSTEM               = SY-OPSYS
*         TARGETSYSTEM                  = SY-HOST
*         STDOUT                        = 'X'
*         STDERR                        = 'X'
*         TERMINATIONWAIT               = 'X'
*         TRACE                         = ' '
         ADDITIONAL_PARAMETERS         = REMOVE_FILE
*    IMPORTING
*         STATUS                        =
     TABLES
          EXEC_PROTOCOL                 = PROTOCOL
     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 I114 WITH FILE1 'deleted'.
ENDIF.

mark all the helpful answers

Regards

Sudheer