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.
Showing results for 
Search instead for 
Did you mean: 
Active Contributor

I presented here the possibility to use Windows Power Shell 2 scripting language inside ABAP. As examples I presented here how to use VB# with this szenario, and here how to call DLL functions. Now a tiny update to the version 3 of PowerShell.


You can download from SAPIEN Technologies Inc. a free library to use PowerShell 3 with ABAP - ActiveXPoshV3x86.exe. Install and register it. It is now very easy possible to use PowerShell inside ABAP, here an example which stores the PowerShell script inside an ABAP include - look here for a detailed description with a VBScript example. Our PowerShell script containes a VB# class with three methods.


$VBCode = @"

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


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





It is necessary to store this code in an own include.



With the function module zReadInclAsString and the following report you can use the PowerShell code and execute it inside your ABAP report.

Program zUseVBSharp.

Type-Pools OLE2 .

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

Data Result Type i Value 0.
Data strResult Type String Value ''.
Data tabResult Type Table Of String.
Data PSCode Type String Value ''.
Data InclName Type SOBJ_NAME Value 'ZPOWERSHELL'.

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.

"-Read PowerShell code from include file--------------------
Exporting I_InclName = InclName
Importing E_strIncl = PSCode.

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.



Free Object PS.






Here the result.


With the library from SAPIEN you can use also actual PowerShell 3 and dotNET 4 functionalities easily inside your ABAP program.

Enjoy it.