
'-Begin-----------------------------------------------------------------
'-Directives------------------------------------------------------------
Option Explicit
'-Function plus---------------------------------------------------------
Function plus(val1, val2)
plus = val1 + val2
End Function
'-Function minus--------------------------------------------------------
Function minus(val1, val2)
minus = val1 - val2
End Function
'-Function plusminus----------------------------------------------------
Function plusminus(val1, val2, val3)
Dim res
res = plus(val1, val2)
plusminus = minus(res, val3)
End Function
'-End-------------------------------------------------------------------
"-Begin-----------------------------------------------------------------
Function ZREADVBCODE .
*"--------------------------------------------------------------------
*"*"Lokale Schnittstelle:
*" IMPORTING
*" VALUE(I_INCLNAME) TYPE SOBJ_NAME
*" EXPORTING
*" VALUE(E_STRINCL) TYPE STRING
*"--------------------------------------------------------------------
Data resTADIR Type TADIR.
Data tabIncl Type Table Of String.
Data lineIncl Type String Value ''.
Data strIncl Type String Value ''.
Select Single * From TADIR Into resTADIR
Where OBJ_NAME = I_InclName.
If sy-subrc = 0.
Read Report I_InclName Into tabIncl.
If sy-subrc = 0.
Loop At tabIncl Into lineIncl.
If lineIncl <> ''.
"-Trim leading and trailing spaces----------------------------
Condense lineIncl.
"-If line is no comment---------------------------------------
If lineIncl+0(1) <> ''''.
Concatenate strIncl lineIncl
cl_abap_char_utilities=>cr_lf Into strIncl.
EndIf.
lineIncl = ''.
EndIf.
EndLoop.
EndIf.
EndIf.
E_strIncl = strIncl.
EndFunction.
"-End-------------------------------------------------------------------
"-Begin-----------------------------------------------------------------
Report zVBScript.
Type-Pools OLE2.
Data ScriptCtrl Type OLE2_OBJECT.
Data Result Type Integer.
Data InclCode Type String Value ''.
Create Object ScriptCtrl 'MSScriptControl.ScriptControl'.
If sy-subrc = 0 And ScriptCtrl-Handle <> 0 And ScriptCtrl-Type = 'OLE2'.
"-Allow to display UI elements--------------------------------------
Set Property Of ScriptCtrl 'AllowUI' = 1.
"-Intialize the VBScript language-----------------------------------
Set Property Of ScriptCtrl 'Language' = 'VBScript'.
"-Read Visual Basic Script code from include file-------------------
Call Function 'ZREADVBCODE'
Exporting
I_InclName = 'ZVBSCRIPT001'
Importing
E_strIncl = InclCode.
"Include ZVBSCRIPT001.
Call Method Of ScriptCtrl 'AddCode' Exporting #1 = InclCode.
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-------------------------------------------------------------------
"-Begin-----------------------------------------------------------------
Report zVBScript.
Data:
ScriptCtrl Type OLE2_OBJECT,
Result Type String,
InclCode Type String.
Create Object ScriptCtrl 'MSScriptControl.ScriptControl'.
If sy-subrc = 0 And ScriptCtrl-Handle <> 0 And ScriptCtrl-Type = 'OLE2'.
"-Allow to display UI elements--------------------------------------
Set Property Of ScriptCtrl 'AllowUI' = 1.
"-Intialize the VBScript language-----------------------------------
Set Property Of ScriptCtrl 'Language' = 'VBScript'.
InclCode = 'Function strRet :'.
InclCode = InclCode && ' strRet = "Hello World" :'.
InclCode = InclCode && 'End Function'.
Call Method Of ScriptCtrl 'AddCode' Exporting #1 = InclCode.
If sy-subrc = 0.
Call Method Of ScriptCtrl 'Eval' = Result
Exporting #1 = 'strRet'.
Write: / Result. "Result = Hello World
EndIf.
"-Free the object---------------------------------------------------
Free Object ScriptCtrl.
EndIf.
"-End-------------------------------------------------------------------
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
3 | |
1 | |
1 | |
1 | |
1 | |
1 | |
1 | |
1 |