How to Run UNIX script from ABAP?

Look at SM69, SM49 and

Function SXPG_COMMAND_EXECUTE

 

e.g. SM69
Press F5 or click Change button
Press F6 or click Create

Fill in the following parameter :-

Command name                                        - the unix scripts file name e.g. ZABAPFTP
Operating system command                       - e.g. sh
Parameters for operating system command - e.g. /sap_production/usr/sap/trans/data/zabapftp.sh

 

REPORT  ZABAPFTP.

data : t_btcxpm      like btcxpm occurs 0,
         p_addparam like sxpgcolist-parameters,
         rep_date       like sy-datum,
         t_date           like SXPGCOLIST-PARAMETERS.

rep_date = sy-datum - 1.
t_date = rep_date.

*p_addparam = '/sap_production/usr/sap/trans/data/zabapftp.sh'.

refresh t_btcxpm. clear t_btcxpm.

call function 'SXPG_CALL_SYSTEM'
     EXPORTING
          commandname                = 'ZABAPFTP'
          additional_parameters      = t_date
     TABLES
          exec_protocol              = t_btcxpm
     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
          others                     = 12.

if sy-subrc ne 0.
   write:/ 'Error in ZABAPFTP ', sy-subrc.
endif.

or

You can execute an operating system command in the OPEN DATASET statement using the FILTER addition:

The following example works under UNIX:

DATA DSN(20) VALUE '/usr/test.Z'.

OPEN DATASET DSN FOR OUTPUT FILTER 'compress'.

OPEN DATASET DSN FOR INPUT FILTER 'uncompress'.

The first OPEN statement opens the file ‘/usr/test.Z’ so that the displayed data can be read into it in compressed form.

The second OPEN statement opens the file ‘/usr/test.Z’ so that the data is decompressed when it is read from the file.

 

zt: http://www.sap-basis-abap.com/sapbs029.htm

 

Another way for executing sample script (Not validate yet)

Data: unix_cmd(50).
unix_cmd = 'chmod 664 /sapdata/DEV/home/travelers'.
translate unix_cmd to lower case.
call 'SYSTEM' id 'COMMAND' field unix_cmd.
write: / sy-subrc. 

 

Other reference:

Perl getting start: http://www.cs.tut.fi/~jkorpela/perl/intro.html

Active Perl - Run perl stand alone in windows: http://www.activestate.com/Products/activeperl/index.mhtml

Perl tutorials: http://www.gossland.com/course/intro/running.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值