cancel
Showing results for 
Search instead for 
Did you mean: 

Addon leaves menus and forms after shutdown

former_member231954
Participant
0 Kudos

I am new to SAP Addon development and I am trying to build a few forms in C#, but I have a little problem with how I should load a Form and register menus.

Should an addon leave the buttons, menus it registered after shutting down the addon's executable? I develop in Visual Studio and when I start my  addon, it first registers the menu elements, then the event handlers (these event handlers look for my menus to be pressed, then start a new form). If I shutdown the exe, the menus are still there and I think the forms too, even tough they are closed in SAP (If I restart the addon the menus are working again, but changes most of the time don't show without an SAP relog/restart). If I restart the SAP a menus disappear of course.

1. I create an SAPboui.Application, passed down it as parameter for the following methods

2. Register App Events

3. Register Menu Elements

(  oCreationPackage = ((MenuCreationParams (SBOApp.CreateObject(BoCreatableObjectType.cot_MenuCreationParams))); .. )

4. Register Menu Event Handler

5. The menu event handler looks like this:

public void Listener(ref MenuEvent pVal, out bool BubbleEvent)

{

    BubbleEvent = true;

    if ((pVal.MenuUID == MenuRegister.MENU_ID_MODULE1) & (pVal.BeforeAction == false))

    {

        Module1 m = new Module1(SBOApp);

        m.Display();

    }

}

After the menu click, I create a module class, which then loads the Form from XML, registers its own event handlers and display the form.

Accepted Solutions (1)

Accepted Solutions (1)

pedro_magueija
Active Contributor
0 Kudos

Hi Szabolcs,

SAP does not remove anything when the add-on stops. There is an application object event you can capture to handle "clean up" tasks.

oApplication.AppEvent is the event and you should check the event type to be

BoAppEventTypes.aet_ServerTerminition

BoAppEventTypes.aet_ShutDown

ServerTerminition is for when the user asks the addon to be stopped.

Shutdown is for when the user closes B1 entirely.


Note that when using Visual Studio debug mode then none of those events occur when you just stop running the addon.


So, it's best practice to always check if the menu you're trying to add already exists, and only add it if it does not.


Pedro Magueija


LinkedIn Logo View Pedro Magueija's profile on LinkedIn
Follow @pedromagueija on Twitter

If this answer was helpful or correct consider marking it as such.

former_member231954
Participant
0 Kudos

And what is the best practice for Forms? I load them from XML every time a menu event starts (new Module()). Multiple modules from the same type can run at the same time, because of the different FormUID, but I also load them every time.

Edit.: Sorry for the long response, I am being moderated, because I am new 😧

edy_simon
Active Contributor
0 Kudos

Hi Szalbolcs,
Normally I would remove my menus, but leave the opened forms.

You can however close all your opened forms.

Just iterate the SBO_Application.Forms and check for each form's FormType.

FormUID may be different, but your Addon should only handles few specific FormType.

Regards

Edy

pedro_magueija
Active Contributor
0 Kudos

Hi Szabolcs,

For forms that is ok. Every time there is a click on a given menu that should point to a form, you can load your form's xml, and by having a unique id for each one, you can have multiple forms of the same type opened just as you described.


Pedro Magueija


LinkedIn Logo View Pedro Magueija's profile on LinkedIn
Follow @pedromagueija on Twitter

If this answer was helpful or correct consider marking it as such.

Answers (0)