Skip to Content
Author's profile photo Former Member

How to add Generic Object Services to your context menus

Quick intro: This post is part of a series in which I show you some interesting ABAP tips and tricks. I’ll present this in the context of our own developments at STA Consulting to have a real-life example and to make it easier to understand.

Requirement: we have a Business Object displayed in a field of an ALV grid and we want to add the Generic Object Services to our custom context menu.

Background information:

Business Objects

In practically all ALV grids you will find fields that contain Business Objects (BO to keep it short). For example, a Plant, a Vendor, a Material is a BO defined by SAP. You can display BOs using transaction SWO1. Our example will be BUS1001 (Material).

In order to uniquely identify a BO, there is a link to at least one field of a database table. BO BUS1001 is linked to MARA-MATNR, which is the unique identifier of a material.

Click on the image above to see the full screenshot

This makes it easy to identify if an ALV field contains a BO or not: simply check the field catalog of the ALV: if there is a reference to a table field which is also referenced by a BO, then we can add the GOS menu to it.

Generic Object Services (GOS)

GOS is a very useful standard tool that allows us to do certain things with BOs. You can add notes and attachments, start and display workflows, link BOs together, send BOs as attachments in messages etc. I’m sure you’ve seen the classic toolbar menu of GOS in many transactions like MM03:

Why is it needed?: The basic reason we made this development is that the GOS menu is only available in certain transactions. For example, if you want to attach a file to a material, you have to launch MM03. In order to do this, you have to open a new window, copy-paste the material number, hit enter etc. It would be great to attach the file in the transaction you are in.

Solution: let’s assume that we have already identified which ALV field contains the material number. After this, we will use a standard class to add the GOS menu to our context menu.

First declare and create the object:

DATA: lo_gos TYPE REF TO cl_gos_manager.
     ip_no_commit = 'R'
     others       = 1.

It is important to add parameter ip_no_commit to control database commits made by GOS, which may interfere with the current program. Space and ‘X’ are pretty trivial, ‘R’ means that updates will be performed using an RFC call. Naturally you have to add your own error handling in case there was any error.

The next step is to get the GOS menu as a context menu object. We have to supply the BO type and the BO key (BUS1001 and the material number the user right-clicked on):

DATA: lo_gos_menu TYPE REF TO cl_ctmenu,
       ls_object   TYPE borident.
ls_object-objtype = 'BUS1001'.
ls_object-objkey  = lv_matnr.
CALL METHOD lo_gos->get_context_menu
     is_object = ls_object
     eo_menu   = lo_gos_menu.

The object reference received in parameter eo_menu will be exactly the same as in the toolbar of MM03.

The last step is to add this context menu to the context menu of the ALV grid. There are hundreds of forum posts about creating your custom context menus so I won’t elaborate it here. There is a standard demo program where you can check it out: BCALV_GRID_06. The bottom line is that you will have a context menu object that you can manipulate:

CALL METHOD lo_alv_context_menu->add_submenu
     menu     = lo_gos_menu
     text     = text-027.     " Generic Object Services

The end result will look like this (we have actually added the GOS menu under our own nested submenus “STA ALV Enhancer – Material”):

Click on the image above to see the full screenshot

Conclusion: This is pretty useful because now you can access the GOS in any ALV you want. Naturally if you attach a file using this context menu, it will be visible in MM03 and vice versa.

I hope you liked this first post, there are lots more things to come. Have a nice day!

p.s.: Actually it is possible to dynamically add this menu to all BOs in ALVs of all standard and custom reports, so ‘BUS1001’ it is not hardcoded…

Assigned Tags

      You must be Logged on to comment or reply to a post.
      Author's profile photo Former Member
      Former Member

      Nice post! Certainly GOS is pretty useful and it is great to have it in ALVs too.

      Author's profile photo Former Member
      Former Member

      Well I thought that this is much more complicated. Good to see that it is so easy.

      Author's profile photo Former Member
      Former Member

      Dear Tamás,

      Many thanks for your blog. I'm surprised that there are not more complimentary comments.

      I have the 3 methods calls exactly as in your blog. My GOS context menu appears, but none of the menu options does anything.

      Also, the attachments list is greyed out (implying that there are no attachments), whereas there are attachments for the object I have right-clicked on.

      Is there a missing step in the blog? Many thanks in advance.


      Author's profile photo Julian Schirm
      Julian Schirm

      I´m facing the same issue.