`
guanhuaing
  • 浏览: 1224127 次
文章分类
社区版块
存档分类
最新评论

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

 
阅读更多

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'.

分享到:
评论

相关推荐

    ABAP751 ABAP - Keyword Documentation

    ABAP - Keyword Documentation This documentation describes the syntax and meaning of the keywords of the ABAP language and its object-oriented part ABAP Objects. Alongside this, language frameworks ...

    ABAP-培训教材目录

    ABAP-培训教材附录 ABAP-培训教材ABAP-培训教材ABAP-培训教材ABAP-培训教材

    CD260-ABAP-in-Eclipse-开发-CN

    CD260-ABAP-in-Eclipse-开发-CN CD260-ABAP-in-Eclipse-开发-CNCD260-ABAP-in-Eclipse-开发-CNCD260-ABAP-in-Eclipse-开发-CN

    eclipse-abap-keywordcolors-master.rar

    eclipse-abap-keywordcolors eclipse-abap-关键字颜色

    SAP中文教材全系列之ABAP-BC400_ZH

    本文档是《SAP中文教材全系列之ABAP-BC400_ZH》,为SAP ABAP编程语言的学习提供参考。文档包含了详细的ABAP课程内容,旨在帮助学员理解并掌握ABAP编程的基础知识和高级技能。以下将详细阐释文档所涵盖的知识点。 ...

    ABAP-OLE开发[汇编].pdf

    这是执行服务器应用程序特定功能的关键,例如在Word文档中插入文本或在Excel中执行计算。 5. **FREE OBJECT**:释放已经创建的OLE对象。当不再需要与OLE应用程序的连接时,使用此关键字来释放资源,避免内存泄漏。 ...

    ABAP-ALV进阶

    ALV 网格控制器主要使用来显示我们通过代码写筛选出来的数据,相关的操作在下面的程序编写部分详细介绍。 三、ALV 起步 ALV GRID CONTROL 使用了控制器技术以实现精美的屏幕显示。使用了 ABAP 的对象以后,列表是...

    SAP中文教材全系列之ABAP-BC401

    SAP ABAP-BC401是SAP ABAP(高级商业应用编程语言)的一部分,它是一种编程语言,专门为SAP软件应用开发。ABAP-BC401的内容覆盖了SAP ABAP开发的各个方面,旨在帮助读者深入掌握ABAP开发技能。从提供的文件内容来看...

    ABAP-WebDynpro实例.pdf

    ABAP-WebDynpro 实例是 SAP 中的一种开发技术,允许开发者创建基于 Web 的应用程序。该技术将 SAP 中开发的程序在 Web 中运行,从而不需要在客户机上安装 SAPGUI。 在本实例中,我们将创建一个 WebDynpro 程序,该...

    web-dynpro-abap-ui-element-tree_Ch01_CV_Introduction_

    在“web-dynpro-abap-ui-element-tree”这个主题中,我们主要探讨的是Web Dynpro ABAP中的UI元素树结构,以及如何在Chapter 1, Curriculum (CV) Introduction中理解和应用这些知识。 在Web Dynpro ABAP中,UI元素是...

    ABAP-学习笔记-通用

    ABAP-学习笔记-通用

    ABAP-子程序宏函数学习笔记.py

    ABAP-子程序宏函数学习笔记.py

    SAP-ABAP-Certification-Review.pdf

    SAP-ABAP-Certification-Review.pdf

    ABAP--ALV

    在给定的示例中,作者通过一段ABAP程序展示了如何使用ALV进行一般列表显示。这段程序的主要功能是显示物料细节信息,包括物料编号(MATNR)、创建者(ERNAM)、创建日期(ERSDA)以及物料类别(LABOR)。 1. **数据...

    ABAP-数据类型学习笔记

    ABAP-数据类型学习笔记

    ABAP-OLE[借鉴].pdf

    在SAP编程中,ABAP-OLE(Object Linking and Embedding)是一种技术,它允许SAP应用程序与外部非SAP系统进行交互,例如创建、读取、更新和删除Excel电子表格。在上述代码中,我们看到了一个名为`ZWM_015`的报告,它...

    ABAP-操作Excel导出数据

    为了更好地理解这一过程,你可以参考提供的文档:《用OLE DOI 实现ABAP导出EXCEL表格.docx》和《ABAP-透過OLE操作OFFICE.docx》。同时,《OLE.pdf》可能包含更深入的OLE和DOI技术细节,这对于优化和调试代码会非常有...

    SAP资料集有ABAP-PP-MM-RFC-BAPI-JCO等.rar

    5. 业务对象接口(BAPI):BAPI是SAP提供的标准接口,允许外部应用程序访问和修改SAP业务对象。BAPIs提供了结构化的、安全的方式来与SAP集成,"JCo Quick Summary.pdf"和"JCo Tutorial.pdf"可能是关于JCO(Java ...

Global site tag (gtag.js) - Google Analytics