Inclusion of Custom Functions for the ALV Grid
Before the standard toolbar is integrated into the ALV grid control, the representative instance triggers the toolbar event. This happens during the execution of the set_table_for_first_display and refresh_table_display methods.
During the lifetime of the representative instance, you can trigger the toolbar event explicitly by calling the set_toolbar_interactive method.
To add elements to the standard toolbar, you must implement a handler method for the toolbar event of the cl_gui_alv_grid class.
Extension of the Standard Toolbar
The toolbar event has a pointer to an instance of the cl_alv_event_toolbar_set class as an exporting parameter. This instance of a toolbar contains the public attribute mt_toolbar. This attribute is an internal table with line type stb_button. You fill this internal table in the handler method to add further buttons or other elements.
If the user chooses an element of the menu button or menu type, the representative instance triggers the menu_button event. This has a parameter e_object with type ref to cl_ctmenu. To add a menu to the toolbar, you must also implement a handler method in which you create the menu in the same way as a context menu.
You can differentiate between multiple menus by querying the function code.
Function Handling
If the user chooses a function element that has been added to the standard toolbar, the representative instance triggers the user_command event. This event contains the function code as its e_ucomm export parameter.
To handle the additional function, implement a handler method for the user_command event. You can differentiate between the function elements by querying the function code.
Reaction to Button Clicks
In the figure, a separate field (btn_text) is defined for the gs_flight structure in which a button is displayed (or not) depending on other data. You can also use the existing fields of the data structure if they do not have F4 help.
To define the field as a button, you need an internal table with type lvc_t_styl (CT in the preceding figure). For each field to be displayed as a button, you create an entry in the internal table in which you assign the name of the field to the fieldname component and the constant cl_gui_alv_grid=>mc_style_button to the style component.
The name of the internal table that contains the information about the buttons is specified in the stylefname component of the layout structure.
BUTTON_CLICK Event Handling
When a user chooses a button in a cell, it triggers the button_click event. The event returns the number of the row and name of the column in which the button was clicked. This allows an associated handler method to implement a context-specific reaction.
Print List Events
The print list is automatically generated by the representative instance. This list can be extended by the calling program.
Use the events shown in the figure. By using these events, you can implement the same logical process steps as used in the classic ABAP list layout. In the event handler methods that you want to implement, you can use the usual statements for ABAP list output and their various additions such as write, skip, uline, and so on.
You can also use the subtotal_text event to define additional texts for subtotals across columns whose output has been suppressed.
Print List – Page Break for Group Change
For a page break at a control level change in the print list, you must set an indicator in the print structure to ensure that the user can format the control level change in the print list. This print structure is controlled by the grpchgedit field of the is_print transfer parameter, which is the lvc_s_prnt structure type.