Even if this functionality has been introduced some years ago (as of SAP ECC 6.0) there are very few programs using the full potential of this tool. I would like to bring your attention to this not-so-known useful technique.
So what is it about ? Some people working with PP standard transactions like COOIS are already familiar with this. It is allowing to dynamically add some buttons in the toolbar of an ALV table and to link those buttons to some actions. Actions can be triggered by existing ok-codes, or call a given transaction with some parameters. It is even possible to execute some code from a class. Very useful and very customizable !
The best part of it to me (as I am a developer) is that it is possible to make it work with my own ALV grids.
Note: it works basically with an ALV grid so if you want to use it with the SALV framework you will have to retrieve the reference to your implicitly defined ALV grid. This technique has been used in some previous blog.
So, what do we need in order to allow using the navigation profile ?
Get the default profile either general or user-related (optional)
FORM profile_default_get CHANGING cs_prfkey TYPE navp_s_profile_key.
DATA: ls_prfkey_def TYPE navp_s_profile_key.
That's it ! Now you have some new menu in the ALV toolbar : it allows to choose the navigation profile, to edit the profile and to manage. The buttons next to this menu are the ones inherited from the navigation profile (sample below: MD04 will run transaction MD04).
Clicking on Change, you get to a popup where you can see the different actions contained into the profile. You can also maintain the profile (depending on your authorizations - object C_NAV_PROF activity 23).
You are able to add and remove actions : transaction call, function call (meaning raising an ok-code), class call and menu. The menu option allows to group some actions into a menu.
So it is very convenient to build some toolbar that will give access to various actions. Of course, if it is an ok-code this one should be handled by the program in order to work. All standards functions from the ALV menu are available (like &DETAIL for example) but you can also program your own ok-codes. Typically you will retrieve the selected rows of the grid and process the data of the internal table. This should be done in some method handle_user_command of your listener for event user_command of the ALV grid.
You can transport a navigation profile by using the managing tool. You can call it with transaction NAVP_MANAGE. If the profile is not linked to your user, click on button "Standard Profiles" to switch to the general profiles.