cancel
Showing results for 
Search instead for 
Did you mean: 

SAP Front End Classes DLL - Status Bar

Former Member
0 Kudos

Hello,

This is my first post here so sorry if it's out of place.

Background : I'm doing an automation on our SAP, and we only have access to the front end, thus the necessity of scripting. I'm doing it on VBA in excel but due to the nature of the question I think this should be asked here and not on Stack Overflow.

Project nature: Update several fields in SAP, transaction VA02 for example

Issue: Being able to handle SAP status bar messages whenever they appear

So, sometimes SAP can yield a msg on the status bar, either a Warning, Error or Information. I know how to capture that menssage and code referencing the status bar, with that I could create a function and run it whenever I think an status bar change could happen but that would result in hundreds of calls on said function and I could simply miss where I should put the function and left a potential error spot forgotten.

What I want to do: Create a listener to handle whenever the status bar shoots and change event.

To be able to do that I need the name of the event to listen to, and to have the name and declaration I would need the class that does that, and since the class if created on SAP the only way I would be able to do that would be to reference the DLL that describes such class/event.

I can't find this DLL, not I'm sure this is the best approach/will work. I tried to explore the DLLs that I have on my SAP but I couldn't view the code on them with dotPeek or a similiar program

Questions:

1 - Is the theory of my solution sound?

2 - If I manage to find the correct DLL would it work?

3 - How can I find this DLL?

Thanks all for the time to read and maybe reply 😃

Accepted Solutions (1)

Accepted Solutions (1)

stefan_schnell
Active Contributor
0 Kudos

Hello Marcos,

welcome in the Scripting Language forum.

Your requirement is very interesting.

To your questions:

3. The DLL you are searching for is the sapfewse.ocx (SAP Front End Windows Scripting Engine). You can find it in the directory Program Files (x86)\SAP\FrontEnd\SAPgui. Here you find the GuiStatusBar object with its properties and methods but without any event.

2. Mhmm, yes and no. No, it doesn't work with the SAP GUI Scripting standard because there is no event in the GuiStatusBar class. Yes, it works if you define your own event via a callback routine.

1. Yes the theory of your solution sounds good. Here a solution in AutoIt.

;-Begin-----------------------------------------------------------------

  ;-Include files-------------------------------------------------------

    #Include "Include\WindowsConstants.au3"

    #Include "Include\GuiListbox.au3"

  ;-Constants-----------------------------------------------------------

    Const $WinTitle = "[CLASS:SAP_FRONTEND_SESSION]"

  ;-Variables-----------------------------------------------------------

    Global $hList

    Global $StatusBar1 = "[CLASS:Afx:"

    Global $StatusBar2 = ":8:00010003:00000010:00000000]"

  ;-Function MyCallback-------------------------------------------------

    Func MyCallback($uiMsg, $wParam, $lParam)

      Switch $uiMsg

        Case $WM_SETTEXT

          _GUICtrlListBox_AddString($hList, "WM_SETTEXT(" & $wParam & _

            "," & $lParam & ")")

          Local $hStruc = DllStructCreate('char[256]', $lParam)

          _GUICtrlListBox_AddString($hList, DllStructGetData($hStruc, 1))

      EndSwitch

      Return 0

    EndFunc

  ;-Sub Main------------------------------------------------------------

    Func Main()

      Local $hGUI = GUICreate("Subclass", 400, 400)

      Local $cList = GUICtrlCreateList("", 8, 8, 384, 384, _

        BitOR($WS_BORDER, $WS_VSCROLL))

      GUISetState()

      $hList = GUICtrlGetHandle($cList)

      Local $hDSSUBCLS = DllOpen("dssubcls.dll")

      If $hDSSUBCLS = -1 Then

        Return

      EndIf

      Local $hWin = WinGetHandle($WinTitle)

      Local $StatusBar = $StatusBar1 & _

        Hex(_WinAPI_GetWindowLong($hWin, $GWL_HINSTANCE)) & $StatusBar2

      Local $hStatusBar = ControlGetHandle($WinTitle, "", $StatusBar)

      Local $hCallback = DllCallbackRegister("MyCallback", "long", _

        "long;long;long")

      Local $aRet = DllCall($hDSSUBCLS, "long", "SubClass", "hwnd", _

        $hStatusBar, "ptr", DllCallbackGetPtr($hCallback), "long", 0, _

        "long", 0, "long", 0, "long", 1)

      $aRet = DllCall($hDSSUBCLS, "long", "UseSendMessage", "long", 1)

      While GUIGetMsg() <> -3

        Sleep(25)

      Wend

      DllClose($hDSSUBCLS)

      GUIDelete()

    EndFunc

  ;-Main----------------------------------------------------------------

    Main()

;-End-------------------------------------------------------------------

I register a callback routine to the statusbar and if the text change I catch WM_SETTEXT.

The DLL for subclassing you can find here.

I know you use VBA, but I think it is basically important to know that the way you described is working.

Hint: Here a link to a post how to get the handles of the UI objects of the SAP GUI for Windows.

Let us know your results.

Cheers

Stefan

Former Member
0 Kudos

Hi Stefan,

Thank you a lot for the reply, it's good to know that it can work. I'm beeing presured to deliver this now so I'm getting away with the handling functions strategically placed but as soon as I can get some free time I will convert this to VBA and post here for anyone else who is looking for it 😃

holger_khn
Contributor
0 Kudos

Hello.

To achieve such function in VBA code is not possible as this require to run code parallel.

MS VBA code is single thread and each code line need completely finished before next line will start.

But we know that statusbar messages only appear when we have an Trigger command send.

Like 'SAVE' or sendvkey.

So we can make an Matrix how different Scenario we need to cover. According to this we can decide if a few functions can be used instead of seperate code line for Trigger this Event.

If we have to many Scenario it make sense to create an customized CLS in VBA.

Former Member
0 Kudos

Hmm interesting but the problem is that to create the matrix we would need to know all the possible errors, I'm aiming for something more dynamic. Also, you are right, VBA is single thread, but multi thread in VBA is achievable, the simplest way I know is to make the VBA code generate a VBS code that runs a another excel application and code. I recall searching for yet a couple week agoes, there are 3 methods that I found. I didn't tested it as I could get away without delving into it.


http://analystcave.com/excel-multithreading-vba-with-vba-worker-threads/
http://analystcave.com/excel-multithreading-in-vba-using-vbscript/
http://analystcave.com/excel-multithreading-vba-vs-vbscript-vs-c-net/

holger_khn
Contributor
0 Kudos

I would say it is not recommended to call an vbs file to capture an Event and then handover captured data back to main code via reading an Textfile created by this vbs.

If we want to control Scenario we Need to Exchange data between exception handling and main code.

I have done some complex Automation with SAP Scripting. And statusbar message handling was not so hard in all of them.

There was some Scenario where according to statusbar message different cases Need to handle. 2-5 all over. Whenever an exception happen which can´t be handle to proceed (MSG-TY = 'E') I skip handling of this line in Loop and code proceed on next Excel row again.

Starting with vbs files, store collected data in text files and read then back into main code is a bit to much.

Then you can code each single Scenario inside main code.

Former Member
0 Kudos

I Agree, handling it in vbs is not advisable. What I'm thinking is to slave the VBS to be just a listener, it will check the status bar in a loop to see if it changed and if so it would alter a designated cell in excel and then we jump into excel native event of of cell change, from there the error handler inside the VBA will kick in.

I'm not sure about the stress that a VBS constantly reading the status bar will cause, will sure test it once I have a couple hrs

Answers (0)