In this weblog we will see how to give access in a controlled manner to the user to change or create new layouts for the reports. We will also see how the user can select a layout on the selection screen, i.e., even before executing the report
How to restrict the user from creating new layout / changing existing layouts.
Before going into the details we need to understand that there 2 different types layouts available Global layout and User-Defined layouts. As the name suggests global layouts will be available for all the users, where as the user-defined layouts will be available for only those users who have created it.
Normally this is what the user sees, when an ALV report is displayed.
Here the user has got access to do everything with the layouts.
Not sure if you have observed in the last weblog when the SET_TABLE_FOR_FIRST_DISPLAY method was called, there was a parameter called I_SAVE and we passed a value A to it. This implies that the user will have all kinds of access to the layouts. Now if we do NOT pass anything to this parameter, the user will loose the privileges to delete / create new layouts. However he will still be able to select a different layout and change an existing one, however he will not be able to save the changed one.
Next variation – I_SAVE = X.
This is where the trick happens. When you pass X, although you see all the options for the layouts, the user will not be able save User-Defined Layouts.
Next variation – I_SAVE = U.
This is exactly opposite to the previous one. The user will be able save only user-define layouts.
So, here is the summary.
I_SAVE = SPACE (Default)- Layouts cannot be saved
I_SAVE = U – Only User-Define Layouts can be saved
I_SAVE = X – Only Global Layouts can be saved
I_SAVE = A – Both user-defined and global layouts can be saved.
In addition to these we will see how to remove some of the standard functionality given the standard ALV toolbar.
Now, that we have seen how to control the layouts, we will now see how to access them on the selection screen.
Define a parameters on the selection screen (Eg: P_LAYOUT LIKE DISVARIANT-VARIANT)
Invoke the following subroutine on value request for the parameter
This subroutine will throw a message if there are no layouts
Or, show the list of layouts if available
You can select one of the layouts and the name will be populated in the parameter field. Now the question is how to you make sure that this layout is used while showing the grid.
If you have observed there was one more parameter that we passed to SET_TABLE_FOR_FIRST_DISPLAY called IS_VARIANT and the variable that we passed to this was WA_VARIANT. Fill the variable as shown below and the layout tha was selected on the selection will be used to display the grid.
WA_VARIANT-REPORT = SY-REPID.
WA_VARIANT-USERNAME = SY-UNAME.
WA_VARIANT-VARIANT = P_LAYOUT.
Now we know all the options to play with Layouts. However the combination the IS_VARIANT and I_SAVE also play a crucial role. So, use them according to your requirements.
In the next weblog we will see how to restrict the user from using some standard features of the ALV toolbar by not displaying them. Also, we will see how to add custom functions to the toolbar and respond to the events.