Application Development and Automation 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
5,004


A long time ago I presented here a possibility how to call DLL functions from a library of the presentation server inside ABAP.

Not so long ago I presented here the possibility how to use Windows PowerShell inside ABAP.

Here now a symbiosis, how to call DLL functions via PowerShell inside ABAP:
"-Begin-----------------------------------------------------------------
Program zCallDLL.

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

"-Constants---------------------------------------------------------
Constants CrLf(2) Type c Value %_CR_LF.
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 CrLf Into PSCode.
End-Of-Definition.

"-Main--------------------------------------------------------------
Create Object PS 'SAPIEN.ActiveXPoSH'.
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.

_ '$sig = @"'.
_ '[DllImport("User32.dll")]'.
_ 'public static extern int MessageBoxA(int hWnd, String Text, String Caption, int Type);'.
_ '"@;'.
_ '$DLL_User32 = Add-Type PBexpMsgBox -MemberDefinition $sig -PassThru'.
_ '$DLL_User32::MessageBoxA(0, "Hello World", "From WinAPI", 0);'.

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 example above shows the using of a WinAPI call.

9 Comments
Former Member
0 Kudos

GUI 7.30 is used as the first operation:

--

Create Object PS 'SAPIEN.ActiveXPoSH'.

--

causes an error => SY-SUBRC = 2. Provides that use the object SAPIEN.ActiveXPoSH?


Stefan-Schnell
Active Contributor
0 Kudos

Hello Oleg TV,

are you sure you install ActiveX PowerShell library correct?

Do you try the VBS test program and runs it well?

Cheers

Stefan


Former Member
0 Kudos

Thank you, there was a problem with the installation ActiveX PowerShell library.

former_member186413
Participant
0 Kudos

Thanks for sharing @stefan.schnell ,  It will be great, if you also know Unix script in ABAP.

Stefan-Schnell
Active Contributor
0 Kudos

Hello Hai Wang,

the solution above is only for SAP GUI for Windows, I am no Unix expert but as far as I know SAP offers no special SAP GUI for Unix. Also Unix offers no equivalent to ActiveX, which is natively supported by the SAP GUI for Windows.

One ot the ways I see is a server application, which runs on the presentation server, something like I describe here. So I think it is possible to build a bridge between an SAP ABAP application and Unix script.

Maybe somewhere is an expert who can present a way.

Cheers

Stefan

Former Member
0 Kudos

Hi Stefan,

There is only the Java SAPGui for UNIX systems. Mostly we use it for simple administration tasks on X-Windows.

With Java you could in theory attach to other Jar files which you could run in-line with SAPGui but I don't think there is an API for this.

Better to write a web app for all your needs, in most cases.

John

heberth_warley
Explorer
0 Kudos

​Hi Stefan, I hope you going well. I’m research to the way to use a DLL in background mode. I’ve seen your post about the use in foreground mode and I'd like know if you had experience with the use in background mode too.

Thanks ever so much

Stefan-Schnell
Active Contributor
Hello heberth.warley

that is a very interesting requirement.

One way to realize this is an SAP server application which runs locally. I programmed a solution on this base five years ago, called Background Light. You can find more information here. In my opinion should a combination of Background Light and dotNETRunner meet your demands.

Best regards
Stefan
heberth_warley
Explorer
Hi st.schnell

This is a very useful tip. Thank you so much.

Best regards
Labels in this area