`
Jack Wu
  • 浏览: 891475 次
  • 来自: ...
社区版块
存档分类
最新评论

编写应用服务器执行外部命令的程序示例

阅读更多

1、相关Package
SBTC

2、相关T-CODE
SM69:
SM49

3、SXPG_CALL_SYSTEM函数说明
 

Use this function module to do the following:
·        Check a user’s authorization to run a command
·        Carry out the command.
To determine the system on which the command should be carried out, the function module takes by default the user’s current host system and the operating system type. 
Since the function module is RFC-capable, you can use RFC (the remote function call interface) to carry run the function module at another SAP application server. The external command is then carried out on the host system on which the destination server is running. See CALL FUNCTION... DESTINATION in the ABAP syntax documentation or User’s Guide for more information.
SXPG_CALL_SYSTEM checks the command that is specified in the call before carrying it out. The function module follows these rules in performing this check:
·        It checks for a command definition that has the same operating system type as in the system field SY-OPSYS. If found, then this command definition is used to run the command.
·        If the first check fails, then the function module looks to see if the command has been defined with an operating system type that belongs to the same syntax group as the SY-OPSYS operating system. A syntax group is an SAP construct that groups together OS’s that share the same command and file name syntax. Example: the various flavors of UNIX belong to a syntax group. 
If found, then this command definition is used to run the command. Example: If SY-OPSYS shows HP-UX as the OS, then a command definition for Sun UNIX would also be acceptable for carrying out the command. 
·        If the second check also fails, then the function modules looks for the command with the operating system type ANYOS. ANYOS indicates that a command definition can be carried out on all supported host operating systems.
If found, then this command definition is used to run the command.
Syntax:
CALL FUNCTION ‘SXPG_CALL_SYSTEM’
     IMPORTING                                                
        COMMANDNAME   =
<Name of command to run> “ Default '*'
        ADDITIONAL_PARAMETERS    =
<Argument string> “ Default <space>        
     EXPORTING                                                
        STATUS        =
<Exit status of command>                 
      TABLES                                                   
        EXEC_PROTOCOL =
<Log> “ In structure BTCXPM. Can
                               “ contain STDOUT, STDERR

      EXCEPTIONS                                               
        NO_PERMISSION
“ Command rejected by user exit auth.
                      “ check

        COMMAND_NOT_FOUND 
“ Command not defined in SAP database
        PARAMETERS_TOO_LONG
 “ Complete parameter string exceeds
                             “ 128 characters

        SECURITY_RISK
“ Security check failed
        WRONG_CHECK_CALL_INTERFACE
“ Problem with function
                                    “ module for additional
                                    “ security check

        PROGRAM_START_ERROR
“ Error while starting program                              
        PROGRAM_TERMINATION_ERROR
“ Error while requesting final
                                  “ status of program

        X_ERROR
“ Reserved
        PARAMETER_EXPECTED
“ Required parameter not specified
        TOO_MANY_PARAMETERS
“ User arguments not allowed by
                            “ supplied in call
              
        ILLEGAL_COMMAND
“ Command not legitimately defined
       
OTHERS
Parameters
IMPORTING Parameters

Parameter name
Use
COMMANDNAME
The name of the definition of the external command, as specified in the maintenance function (transaction SM69).
PARAMETERS
Arguments for the external command as specified by the definition in the SAP system and by the calling program or user.
These arguments are checked for impermissible characters, such as the ; under UNIX. Problems are registered with the SECURITY_RISK exception.

 
EXPORTING Parameters

Parameter name
Use
STATUS
Returns the final status of the execution of the external command:
·     Value ‘O’: The external command was started and ran to end successfully.
·     Value ‘E’: An error occurred; the external command was not run successfully. 

 
Tables Parameters

Parameter name
Use
EXEC_PROTOCOL
Contains the STDOUT and STDERR output of the external command and any output from the target host system.

 
Exceptions

Exception name
Meaning
X_ERROR
Reserved for future use.
NO_PERMISSION
The AUTHORITY-CHECK of the user’s authorization for the authorization object S_LOG_COM failed. The user is not authorized to carry out the command named with the specified arguments on the target system. 
COMMAND_NOT_FOUND
Command name, as identified by COMMANDNAME and OPERATINGSYSTEM, has not been defined in the maintenance function (transaction SM69).
PARAMETERS_TOO_LONG
The combined argument string (ADDITIONAL_PARAMETERS and the DEFINED_PARAMETERS, as returned in ALL_PARAMETERS) exceeds the limit of 128 characters in length.
SECURITY_RISK
Either:
· The command contains impermissible characters. These are characters with potentially dangerous properties, such as ; under UNIX.
· The command definition specifies that an extra-check function module be run. This function module has rejected execution of the command. 
WRONG_CHECK_CALL_
INTERFACE
The command definition specifies that an extra-check function module is to be run. Either this function module is missing, or the interface defined for this function module does not match that of the standard SAP function module SXPG_DUMMY_COMMAND_CHECK. For more information, please see SXPG_DUMMY_COMMAND_CHECK: Interface for Extra-Check Function Modules.
TOO_MANY_PARAMETERS
The command definition specifies that user-specified arguments for the external command are not allowed. However, an additional string of command arguments was specified.
PARAMETER_EXPECTED
The command definition includes the placeholder character ?, which signifies that additional user-defined arguments are required. However, no additional arguments string was supplied.
PROGRAM_START_ERROR
An error occurred while starting the external command. The SAP system field SY-MSGV1 contains additional information on the problem.
PROGRAM_TERMINATION_
ERROR
An error occurred while trying to obtain the return code of the external program. The SAP system field SY-MSGV1 contains additional information on the problem.
ILLEGAL_COMMAND
The external command definition was modified “illegally”. That is, the command was not modified by means of the maintenance function (transaction SM69).
The modified command is registered in the system log in its substituted form. The message is registered under the system log ID “LC”.   
OTHERS
Catch any new exceptions added to this function module. 

4、示例
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.

5、使用Open Dataset的FILTER执行系统命令
下面为UNIX环境下的文件压缩和解压
DATA DSN(20) VALUE '/usr/test.Z'.
OPEN DATASET DSN FOR OUTPUT FILTER 'compress'.
OPEN DATASET DSN FOR INPUT FILTER 'uncompress'.

 



分享到:
评论

相关推荐

    JAVA执行shell命令小工具

    Ganymed SSH2库允许Java应用程序通过SSH连接到其他系统,并执行包括shell命令在内的各种任务。因此,这个“JAVA执行shell命令小工具”可能依赖于Ganymed SSH2库来实现远程执行shell命令的功能。 在实际应用中,使用...

    CGI介绍及使用Python来开发CGI应用示例

    CGI(Common Gateway Interface,通用网关接口)是一种标准,允许Web服务器与外部程序交互,以动态生成网页内容。在互联网早期,CGI是实现网页动态化的常见方式,它允许服务器执行服务器端脚本,然后将结果返回到...

    编写VB CGI程序所必须的模块

    CGI (Common Gateway Interface) 是一种标准,允许Web服务器与外部应用程序交互,从而扩展了静态HTML页面的功能。当您需要使用VB编写CGI程序时,有一些关键模块是必不可少的。本文将详细讲解这些模块以及如何使用...

    freeswitch esl java client 示例代码

    ESL(Event Socket Library)是Freeswitch提供的一种接口,允许外部应用程序与Freeswitch服务器进行交互,实现诸如控制通话、发送事件等功能。Java ESL客户端则是一个能够帮助Java开发者利用ESL与Freeswitch通信的库...

    《精通MATLAB2008应用程序接口编程技术》实例程序代码

    MATLAB Engine则是一个库,允许其他应用程序启动并控制MATLAB会话,执行MATLAB命令和运行脚本。 在书中,你将学习到如何设置开发环境,包括安装必要的编译器和配置MATLAB的编译器设置。接着,会介绍如何编写MEX文件...

    轻量级web服务器实现http 实现get post请求

    CGI允许服务器执行外部程序(如我们写的C++脚本),并将HTTP请求的数据传递给这些程序。这些脚本可以根据接收到的数据动态生成HTML响应,然后返回给客户端。这使得服务器能够提供动态内容,比如用户登录、表单提交等...

    nodejs入门教程二:创建一个简单应用示例.docx

    - **Node.js 入门教程三:调用内部和外部方法示例**:学习如何在 Node.js 应用程序中调用其他模块和方法。 - **Node.js 入门教程四:URL 相关模块用法分析**:了解 Node.js 中处理 URL 的各种技巧。 - **Node.js ...

    串口与http 服务器_HTTP_串口http_串口与http服务器_http服务器_

    服务器端的代码需要解析HTTP请求,根据请求的URL和方法执行相应操作,如获取串口数据或发送控制命令到串口。 3. **集成串口和HTTP**:为了使HTTP服务器能够通过串口与硬件交互,需要编写中间层代码。当服务器接收到...

    windows web调用windows本地的exe程序(ssh工具),并自动登录到远程服务器上

    MobaXterm支持脚本化操作,可以编写批处理脚本来自动执行一系列命令,这对于Web应用调用非常有用。解压`MobaXterm_Portable_v22.1.rar`后,你可以在MobaXterm的设置中配置会话,保存登录信息,然后在Web应用中调用这...

    VB编写仿瑞星自动升级程序

    - `Shell` 函数:用于启动外部命令或程序。 - `GetPrivateProfileString` 函数:读取配置文件中的设置项。 - `WritePrivateProfileString` 函数:写入配置文件中的设置项。 ### 三、技术要点解析 #### 1. VB...

    在Oracle数据库中运行操作系统命令

    这部分程序(如上述的Pro*C代码示例)应该能够接收来自数据库的命令,解析并执行它们,然后将结果反馈回数据库。在Pro*C代码中,你需要预编译这段代码并将其链接到可执行文件,确保它能在服务器上运行。 部署守护...

    SpringBoot部署Tomcat示例

    本示例将向你展示如何将一个简单的SpringBoot应用部署到外部的Tomcat服务器上,这对于开发者来说是一项基本但至关重要的技能。让我们深入探讨这个过程。 首先,了解SpringBoot的核心特性:内置的Servlet容器。默认...

    C++制作CGI程序例子

    CGI(Common Gateway Interface,通用网关接口)是一种标准,允许Web服务器与外部应用程序交互,以动态生成网页内容。在本实例中,我们将探讨如何使用C++语言来编写CGI程序,通过`cgicc`库来实现这一目标。 C++是...

    delphi开发控制台程序演示

    Delphi提供了丰富的系统相关类,如`TProcess`和`TMemoryStream`,可以用来执行外部命令、读写进程内存等。例如,你可以使用`TProcess`来调用操作系统命令,如`dir`或`ping`,以集成到你的控制台程序中。 5. 操作...

    cgi.rar_DEMO_cgi

    CGI(Common Gateway Interface,通用网关接口)是一种标准,允许Web服务器与外部应用程序交互,以动态生成网页内容。在本“cgi.rar_DEMO_cgi”压缩包中,包含了一个CGI示例程序,这对于初学者或者需要进一步理解CGI...

    linux下调用Shell实现文件上传ftp服务器

    - **命令执行**:调用外部命令或脚本中的自定义函数。 #### 2. 使用FTP命令 FTP命令行工具提供了一系列用于与FTP服务器交互的命令,包括登录、列出目录、上传和下载文件等。在本例中,我们主要关注以下几个命令: -...

Global site tag (gtag.js) - Google Analytics