Application Development Blog Posts
Learn and share on deeper, cross technology development topics such as integration and connectivity, automation, cloud extensibility, developing at scale, and security.
cancel
Showing results for 
Search instead for 
Did you mean: 
stefan_schnell
Active Contributor
I presented here the possibiltiy how to use Windows PowerShell inside ABAP.

Here now the possibility how to use VB#, Visual Basic for dotNET, inside ABAP, on the same way:
"-Begin-----------------------------------------------------------------
Program zUseVBSharp.

"-TypePools---------------------------------------------------------
Type-Pools OLE2 .

"-Constants--------------------------------------------------------
Constants OUTPUT_CONSOLE Type i Value 0.
Constants OUTPUT_WINDOW Type i Value 1.
Constants OUTPUT_BUFFER Type i Value 2.

"-Variables---------------------------------------------------------
Data PS Type OLE2_OBJECT.
Data Result Type i Value 0.
Data strResult Type String Value ''.
Data tabResult Type Table Of String.
Data PSCode Type String Value ''.

"-Macros------------------------------------------------------------
Define _.
Concatenate PSCode &1 cl_abap_char_utilities=>cr_lf Into PSCode.
End-Of-Definition.

"-Main--------------------------------------------------------------
Create Object PS ' SAPIEN.ActiveXPoSHV3'.
If sy-subrc = 0 And PS-Handle <> 0 And PS-Type = 'OLE2'.

Call Method Of PS 'Init' = Result Exporting #1 = 0.
If Result = 0.

Call Method Of PS 'IsPowerShellInstalled' = Result.
If Result <> 0.

Set Property Of PS 'OutputMode' = OUTPUT_BUFFER.

"-PowerShell Begin------------------------------------------------------

_ '$VBCode = @"'.

"-VB# Begin-------------------------------------------------------------

_ 'Option Strict On'.

_ 'Imports System'.
_ 'Imports Microsoft.VisualBasic'.

_ 'Namespace VBCode'.

_ ' Public Class VB'.

_ ' Public Shared Function Hello1() As String'.
_ ' Return "Hello World!"'.
_ ' End Function'.

_ ' Public Function Hello2(ByVal Name As String) As String'.
_ ' Return "Hello " & Name & "!"'.
_ ' End Function'.

_ ' Public Sub Hello3(ByVal Name As String)'.
_ ' MsgBox(Name, MsgBoxStyle.OkOnly, "Hello")'.
_ ' End Sub'.

_ ' End Class'.

_ 'End Namespace'.

"-VB# End---------------------------------------------------------------

_ '"@;'.

_ 'Add-Type -TypeDefinition $VBCode -Language VisualBasic'.
_ '$VB = new-Object VBCode.VB'.

_ '[VBCode.VB]::Hello1()'.
_ '$VB.Hello2("Stefan")'.
_ '$VB.Hello3("Stefan")'.

"-PowerShell End--------------------------------------------------------

Call Method Of PS 'Execute' Exporting
#1 = PSCode.

Call Method Of PS 'OutputString' = strResult.

Split strResult At cl_abap_char_utilities=>cr_lf
Into Table tabResult.

Loop At tabResult Into strResult.
Write: / strResult.
EndLoop.

EndIf.

EndIf.

Free Object PS.
EndIf.

"-End-------------------------------------------------------------------

 

The PowerShell code encloses the VB# code. The VB# code is a namespace, a class and three methods. In the PowerShell code, below VB# code, these methods are called. Hello1 and Hello2 returns the result inside the output buffer of ActiveX-PowerShell and Hello3 opens a message box.

On the same way you can embed C# code inside ABAP.

I think this possibility opens the gate very wide to embed the power of dotNET framework and its languages.
3 Comments