SXPG_CALL_SYSTEM: Run an External Command (Express Method)
Use
Using this function module, you can:
-
Check a user's authorization to execute a command
-
Execute the command
To determine the system on which the command should be executed, the function module uses by default the current host system and the current operating system type of the user.
As the function module is RFC-capable, you can use the RFC interface (Remote Function Call Interface) to run the function module in a different SAP application server. The external command is then accordingly executed in the host system of the other SAP server.
SXPG_CALL_SYSTEM checks the command that is specified in the call before carrying it out.
-
If a command with the same operating system type as the one in the sytem field SY-OPSYS exists, this definition is used for the execution of the command.
-
It checks for a command definition that has the same operating system type as in the system field SY-OPSYS. A syntax group is an SAP construct that groups operating systems that use the same syntax for commands and filenames. If a command whose operating system type matches the determined syntax group, this definition of the command is used.
-
If no matching definition is found for the syntax group, the function module searches for a definition with the operating system type ANYOS (executable in all supported operating systems). This definition is then used, if found.
-
Otherwise, the exception COMMAND_NOT_FOUND is triggered.
CALL FUNCTION 'SXPG_CALL_SYSTEM'
IMPORTING
COMMANDNAME = <SAP command name> " 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
Parameter
IMPORTING Parameter
|
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 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 Parameter
|
Parameter Name |
Use |
|
STATUS |
Returns the status after execution of the external command:
|
Table Parameter
|
Parameter Name |
Use |
|
EXEC_PROTOCOL |
Contains the STDOUT and STDERR output of the external command and any output from the target host system. |
Exceptions
|
Name |
Meaning |
|
X_ERROR |
Reserved. |
|
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:
|
|
WRONG_CHECK_CALL_ INTERFACE |
The command definition specifies that an additional check function module should 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, 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. |