"-Begin-----------------------------------------------------------------
Report zVBScript2.
Type-Pools OLE2.
Constants CrLf(2) Type c Value %_CR_LF.
Data:
ScriptCtrl Type OLE2_OBJECT,
Command Type String Value '',
Line Type String Value '',
Module Type String Value '',
Result Type Integer.
Define AddLine.
Concatenate Module &1 CrLf Into Module.
End-Of-Definition.
"-Main------------------------------------------------------------------
Create Object ScriptCtrl 'MSScriptControl.ScriptControl'.
If sy-subrc = 0.
"-Allow to display UI elements----------------------------------------
Set Property Of ScriptCtrl 'AllowUI' = 1.
"-Intialize the VBScript language-------------------------------------
Set Property Of ScriptCtrl 'Language' = 'VBScript'.
"---------------------------------------------------------------------
"-
"- Execution of VBScript functions with parameters
"-
"---------------------------------------------------------------------
AddLine 'Function plus(val1, val2)'.
AddLine ' plus = val1 + val2'.
AddLine 'End Function'.
AddLine 'Function minus(val1, val2)'.
AddLine ' minus = val1 - val2'.
AddLine 'End Function'.
AddLine 'Function plusminus(val1, val2, val3)'.
AddLine ' Dim res'.
AddLine ' res = plus(val1, val2)'.
AddLine ' plusminus = minus(res, val3)'.
AddLine 'End Function'.
Call Method Of ScriptCtrl 'AddCode' Exporting #1 = Module.
If sy-subrc = 0.
Call Method Of ScriptCtrl 'Eval' = Result
Exporting #1 = 'plusminus(32, 16, 8)'.
Write: / Result. "Result = 40
EndIf.
"-Free the object-----------------------------------------------------
Free Object ScriptCtrl.
EndIf.
"-End-------------------------------------------------------------------