# -*- coding: iso-8859-15 -*-
#-Begin-----------------------------------------------------------------
#-Imports---------------------------------------------------------------
import platform, struct
#-Sub Main--------------------------------------------------------------
def main():
print("Hello World from Python", platform.python_version(), "on",
platform.system(), "(" + platform.architecture()[0] + ")")
#-Main------------------------------------------------------------------
if __name__ == "__main__":
main()
#-End-------------------------------------------------------------------
Function ZEXECUTEPYTHONSCRIPT.
*"----------------------------------------------------------------------
*"*"Lokale Schnittstelle:
*" IMPORTING
*" VALUE(I_INCLNAME) TYPE SOBJ_NAME
*" VALUE(I_FILENAME) TYPE STRING
*" EXPORTING
*" VALUE(E_EXECPROT) TYPE Z_TAB_BTCXPGLOG
*" EXCEPTIONS
*" NO_FILE_NAME
*" NO_INCLUDE_AVAILABLE
*" CAN_NOT_WRITE_SCRIPT
*" ERROR_IN_SCRIPT_EXECUTION
*" CAN_NOT_DELETE_SCRIPT
*"----------------------------------------------------------------------
"-Variables-----------------------------------------------------------
Data lv_FileName(255) Type c.
Data lv_TADIR Type TADIR.
Data lt_Incl Type Table Of String.
Data lv_lineIncl Type String.
Data lv_strIncl Type String.
Data lv_Status Type EXTCMDEXEX-STATUS.
Data lv_ExitCode Type EXTCMDEXEX-EXITCODE.
"-Main----------------------------------------------------------------
"-Gets directory path-----------------------------------------------
Call Function 'FILE_GET_NAME'
Exporting
CLIENT = sy-mandt
LOGICAL_FILENAME = 'ZPYTHON'
OPERATING_SYSTEM = sy-opsys
PARAMETER_1 = i_FileName
ELEMINATE_BLANKS = 'X'
Importing
FILE_NAME = lv_FileName
Exceptions
FILE_NOT_FOUND = 1
Others = 2.
If sy-subrc <> 0.
Raise NO_FILE_NAME.
EndIf.
"-Gets script content-----------------------------------------------
Select Single * From TADIR Into lv_TADIR
Where OBJ_NAME = i_InclName.
If sy-subrc = 0.
Read Report i_InclName Into lt_Incl.
If sy-subrc = 0.
Loop At lt_Incl Into lv_lineIncl.
lv_strIncl = lv_strIncl && lv_lineIncl &&
cl_abap_char_utilities=>cr_lf.
EndLoop.
EndIf.
Else.
Raise NO_INCLUDE_AVAILABLE.
EndIf.
"-Writes script-----------------------------------------------------
Open Dataset lv_FileName For Output In Text Mode
Encoding Non-Unicode With Windows Linefeed.
If sy-subrc = 0.
Transfer lv_strIncl To lv_FileName.
Close Dataset lv_FileName.
Else.
Raise CAN_NOT_WRITE_SCRIPT.
EndIf.
"-Executes script---------------------------------------------------
Call Function 'SXPG_STEP_COMMAND_START'
Exporting
COMMANDNAME = 'ZPYTHON'
ADDITIONAL_PARAMETERS = lv_FileName
OPERATINGSYSTEM = sy-opsys
STDINCNTL = 'R'
STDOUTCNTL = 'M'
STDERRCNTL = 'M'
TRACECNTL = '0'
TERMCNTL = 'C'
Tables
LOG = e_ExecProt
Exceptions
COMMAND_NOT_FOUND = 1
PARAMETER_EXPECTED = 2
PARAMETERS_TOO_LONG = 3
SECURITY_RISK = 4
WRONG_CHECK_CALL_INTERFACE = 5
NO_PERMISSION = 6
UNKNOWN_ERROR = 7
COMMUNICATION_ERROR = 8
SYSTEM_ERROR = 9
CANNOT_GET_RFC_DESTS = 10
JOB_UPDATE_FAILED = 11
JOB_DOES_NOT_EXIST = 12
PROGRAM_START_ERROR = 13
Others = 14.
If sy-subrc <> 0.
Raise ERROR_IN_SCRIPT_EXECUTION.
EndIf.
"-Deletes script----------------------------------------------------
Delete Dataset lv_FileName.
If sy-subrc <> 0.
Raise CAN_NOT_DELETE_SCRIPT.
EndIf.
EndFunction.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
5 | |
5 | |
3 | |
2 | |
2 | |
2 | |
1 | |
1 | |
1 | |
1 |